source: trip-planner-front/node_modules/webpack/lib/dependencies/WorkerDependency.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Ivan Kopeykin @vankop
4*/
5
6"use strict";
7
8const Dependency = require("../Dependency");
9const RuntimeGlobals = require("../RuntimeGlobals");
10const makeSerializable = require("../util/makeSerializable");
11const ModuleDependency = require("./ModuleDependency");
12
13/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
14/** @typedef {import("../AsyncDependenciesBlock")} AsyncDependenciesBlock */
15/** @typedef {import("../ChunkGraph")} ChunkGraph */
16/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
17/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
18/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
19/** @typedef {import("../Entrypoint")} Entrypoint */
20/** @typedef {import("../ModuleGraph")} ModuleGraph */
21/** @typedef {import("../util/Hash")} Hash */
22/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
23
24class WorkerDependency extends ModuleDependency {
25 /**
26 * @param {string} request request
27 * @param {[number, number]} range range
28 */
29 constructor(request, range) {
30 super(request);
31 this.range = range;
32 }
33
34 /**
35 * Returns list of exports referenced by this dependency
36 * @param {ModuleGraph} moduleGraph module graph
37 * @param {RuntimeSpec} runtime the runtime for which the module is analysed
38 * @returns {(string[] | ReferencedExport)[]} referenced exports
39 */
40 getReferencedExports(moduleGraph, runtime) {
41 return Dependency.NO_EXPORTS_REFERENCED;
42 }
43
44 get type() {
45 return "new Worker()";
46 }
47
48 get category() {
49 return "worker";
50 }
51}
52
53WorkerDependency.Template = class WorkerDependencyTemplate extends (
54 ModuleDependency.Template
55) {
56 /**
57 * @param {Dependency} dependency the dependency for which the template should be applied
58 * @param {ReplaceSource} source the current replace source which can be modified
59 * @param {DependencyTemplateContext} templateContext the context object
60 * @returns {void}
61 */
62 apply(dependency, source, templateContext) {
63 const { chunkGraph, moduleGraph, runtimeRequirements } = templateContext;
64 const dep = /** @type {WorkerDependency} */ (dependency);
65 const block = /** @type {AsyncDependenciesBlock} */ (
66 moduleGraph.getParentBlock(dependency)
67 );
68 const entrypoint = /** @type {Entrypoint} */ (
69 chunkGraph.getBlockChunkGroup(block)
70 );
71 const chunk = entrypoint.getEntrypointChunk();
72
73 runtimeRequirements.add(RuntimeGlobals.publicPath);
74 runtimeRequirements.add(RuntimeGlobals.baseURI);
75 runtimeRequirements.add(RuntimeGlobals.getChunkScriptFilename);
76
77 source.replace(
78 dep.range[0],
79 dep.range[1] - 1,
80 `/* worker import */ ${RuntimeGlobals.publicPath} + ${
81 RuntimeGlobals.getChunkScriptFilename
82 }(${JSON.stringify(chunk.id)}), ${RuntimeGlobals.baseURI}`
83 );
84 }
85};
86
87makeSerializable(WorkerDependency, "webpack/lib/dependencies/WorkerDependency");
88
89module.exports = WorkerDependency;
Note: See TracBrowser for help on using the repository browser.