webpack 5.2.1 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

@@ -75,29 +75,6 @@ const load = (input, context) => {
75
75
  * @returns {EcmaTargetProperties & PlatformTargetProperties & ApiTargetProperties} target properties
76
76
  */
77
77
  const resolve = browsers => {
78
- /**
79
- * Checks only browser against the browserslist feature query
80
- * @param {string} feature an ES feature to test
81
- * @returns {boolean} true if supports
82
- */
83
- const browserslistChecker = feature => {
84
- const supportsFeature = browserslist(`supports ${feature}`);
85
- return browsers.every(v => /^node /.test(v) || supportsFeature.includes(v));
86
- };
87
- /**
88
- * Checks only node.js version against a version
89
- * @param {number} major major version
90
- * @param {number} minor minor version
91
- * @returns {boolean} true if supports
92
- */
93
- const nodeChecker = (major, minor = 0) => {
94
- return browsers.every(v => {
95
- const match = /^node (\d+)(?:\.\d+)?/.exec(v);
96
- if (!match) return true;
97
- const [, v1, v2] = match;
98
- return major === +v1 ? +v2 >= minor : +v1 > major;
99
- });
100
- };
101
78
  /**
102
79
  * Checks all against a version number
103
80
  * @param {Record<string, number | [number, number]>} versions first supported version
@@ -105,50 +82,197 @@ const resolve = browsers => {
105
82
  */
106
83
  const rawChecker = versions => {
107
84
  return browsers.every(v => {
108
- const match = /^([^ ]+) (\d+)(?:\.\d+)?/.exec(v);
109
- if (!match) return false;
110
- const [, name, major, minor] = match;
111
- const version = versions[name];
112
- if (!version) return false;
113
- if (typeof version === "number") return +major >= version;
114
- return version[0] === +major ? +minor >= version[1] : +major > version[0];
85
+ const [name, parsedVersion] = v.split(" ");
86
+ if (!name) return false;
87
+ const requiredVersion = versions[name];
88
+ if (!requiredVersion) return false;
89
+ const [parsedMajor, parserMinor] =
90
+ // safari TP supports all features for normal safari
91
+ parsedVersion === "TP"
92
+ ? [Infinity, Infinity]
93
+ : parsedVersion.split(".");
94
+ if (typeof requiredVersion === "number") {
95
+ return +parsedMajor >= requiredVersion;
96
+ }
97
+ return requiredVersion[0] === +parsedMajor
98
+ ? +parserMinor >= requiredVersion[1]
99
+ : +parsedMajor > requiredVersion[0];
115
100
  });
116
101
  };
117
102
  const anyNode = browsers.some(b => /^node /.test(b));
118
103
  const anyBrowser = browsers.some(b => /^(?!node)/.test(b));
119
104
  const browserProperty = !anyBrowser ? false : anyNode ? null : true;
120
105
  const nodeProperty = !anyNode ? false : anyBrowser ? null : true;
121
- const es6 = browserslistChecker("es6");
122
- const letConst = browserslistChecker("let");
123
- const arrowFunctions = browserslistChecker("arrow-functions");
124
- const es6DynamicImport = browserslistChecker("es6-module-dynamic-import");
125
- const node6 = nodeChecker(6);
106
+ // Internet Explorer Mobile, Blackberry browser and Opera Mini are very old browsers, they do not support new features
107
+ const es6DynamicImport = rawChecker({
108
+ chrome: 63,
109
+ and_chr: 63,
110
+ edge: 79,
111
+ firefox: 67,
112
+ and_ff: 67,
113
+ // ie: Not supported
114
+ opera: 50,
115
+ op_mob: 46,
116
+ safari: [11, 1],
117
+ ios_saf: [11, 3],
118
+ samsung: [8, 2],
119
+ android: 63,
120
+ and_qq: [10, 4],
121
+ // baidu: Not supported
122
+ // and_uc: Not supported
123
+ // kaios: Not supported
124
+ // Since Node.js 13.14.0 no warning about usage, but it was added 8.5.0 with some limitations and it was improved in 12.0.0 and 13.2.0
125
+ node: [13, 14]
126
+ });
127
+
126
128
  return {
127
- const: letConst && node6,
128
- arrowFunction: arrowFunctions && node6,
129
- forOf: es6 && nodeChecker(5),
130
- destructuring: es6 && node6,
131
- bigIntLiteral: browserslistChecker("bigint") && nodeChecker(10, 4),
132
- module: browserslistChecker("es6-module") && nodeChecker(12, 17),
133
- dynamicImport: es6DynamicImport && nodeChecker(10, 17),
134
- dynamicImportInWorker: es6DynamicImport && nodeChecker(Infinity),
129
+ const: rawChecker({
130
+ chrome: 49,
131
+ and_chr: 49,
132
+ edge: 12,
133
+ // Prior to Firefox 13, <code>const</code> is implemented, but re-assignment is not failing.
134
+ // Prior to Firefox 46, a <code>TypeError</code> was thrown on redeclaration instead of a <code>SyntaxError</code>.
135
+ firefox: 36,
136
+ and_ff: 36,
137
+ // Not supported in for-in and for-of loops
138
+ // ie: Not supported
139
+ opera: 36,
140
+ op_mob: 36,
141
+ safari: [10, 0],
142
+ ios_saf: [10, 0],
143
+ // Before 5.0 supported correctly in strict mode, otherwise supported without block scope
144
+ samsung: [5, 0],
145
+ android: 37,
146
+ and_qq: [10, 4],
147
+ // Supported correctly in strict mode, otherwise supported without block scope
148
+ // baidu: Not supported
149
+ and_uc: [12, 12],
150
+ kaios: [2, 5],
151
+ node: [6, 0]
152
+ }),
153
+ arrowFunction: rawChecker({
154
+ chrome: 45,
155
+ and_chr: 45,
156
+ edge: 12,
157
+ // The initial implementation of arrow functions in Firefox made them automatically strict. This has been changed as of Firefox 24. The use of <code>'use strict';</code> is now required.
158
+ // Prior to Firefox 39, a line terminator (<code>\\n</code>) was incorrectly allowed after arrow function arguments. This has been fixed to conform to the ES2015 specification and code like <code>() \\n => {}</code> will now throw a <code>SyntaxError</code> in this and later versions.
159
+ firefox: 39,
160
+ and_ff: 39,
161
+ // ie: Not supported,
162
+ opera: 32,
163
+ op_mob: 32,
164
+ safari: 10,
165
+ ios_saf: 10,
166
+ samsung: [5, 0],
167
+ android: 45,
168
+ and_qq: [10, 4],
169
+ baidu: [7, 12],
170
+ and_uc: [12, 12],
171
+ kaios: [2, 5],
172
+ node: [6, 0]
173
+ }),
174
+ forOf: rawChecker({
175
+ chrome: 38,
176
+ and_chr: 38,
177
+ edge: 12,
178
+ // Prior to Firefox 51, using the for...of loop construct with the const keyword threw a SyntaxError ("missing = in const declaration").
179
+ firefox: 51,
180
+ and_ff: 51,
181
+ // ie: Not supported,
182
+ opera: 25,
183
+ op_mob: 25,
184
+ safari: 7,
185
+ ios_saf: 7,
186
+ samsung: [3, 0],
187
+ android: 38,
188
+ // and_qq: Unknown support
189
+ // baidu: Unknown support
190
+ // and_uc: Unknown support
191
+ // kaios: Unknown support
192
+ node: [0, 12]
193
+ }),
194
+ destructuring: rawChecker({
195
+ chrome: 49,
196
+ and_chr: 49,
197
+ edge: 14,
198
+ firefox: 41,
199
+ and_ff: 41,
200
+ // ie: Not supported,
201
+ opera: 36,
202
+ op_mob: 36,
203
+ safari: 8,
204
+ ios_saf: 8,
205
+ samsung: [5, 0],
206
+ android: 49,
207
+ // and_qq: Unknown support
208
+ // baidu: Unknown support
209
+ // and_uc: Unknown support
210
+ // kaios: Unknown support
211
+ node: [6, 0]
212
+ }),
213
+ bigIntLiteral: rawChecker({
214
+ chrome: 67,
215
+ and_chr: 67,
216
+ edge: 79,
217
+ firefox: 68,
218
+ and_ff: 68,
219
+ // ie: Not supported,
220
+ opera: 54,
221
+ op_mob: 48,
222
+ safari: 14,
223
+ ios_saf: 14,
224
+ samsung: [9, 2],
225
+ android: 67,
226
+ // and_qq: Not supported
227
+ // baidu: Not supported
228
+ // and_uc: Not supported
229
+ // kaios: Not supported
230
+ node: [10, 4]
231
+ }),
232
+ // Support syntax `import` and `export` and no limitations and bugs on Node.js
233
+ // Not include `export * as namespace`
234
+ module: rawChecker({
235
+ chrome: 61,
236
+ and_chr: 61,
237
+ edge: 16,
238
+ firefox: 60,
239
+ and_ff: 60,
240
+ // ie: Not supported,
241
+ opera: 48,
242
+ op_mob: 45,
243
+ safari: [10, 1],
244
+ ios_saf: [10, 3],
245
+ samsung: [8, 0],
246
+ android: 61,
247
+ and_qq: [10, 4],
248
+ // baidu: Not supported
249
+ // and_uc: Not supported
250
+ // kaios: Not supported
251
+ // Since Node.js 13.14.0 no warning about usage, but it was added 8.5.0 with some limitations and it was improved in 12.0.0 and 13.2.0
252
+ node: [13, 14]
253
+ }),
254
+ dynamicImport: es6DynamicImport,
255
+ dynamicImportInWorker: es6DynamicImport && !anyNode,
135
256
  // browserslist does not have info about globalThis
136
257
  // so this is based on mdn-browser-compat-data
137
258
  globalThis: rawChecker({
138
259
  chrome: 71,
139
- chrome_android: 71,
260
+ and_chr: 71,
140
261
  edge: 79,
141
262
  firefox: 65,
142
- firefox_android: 65,
263
+ and_ff: 65,
143
264
  // ie: Not supported,
144
- nodejs: 12,
145
265
  opera: 58,
146
- opera_android: 50,
266
+ op_mob: 50,
147
267
  safari: [12, 1],
148
- safari_ios: [12, 2],
149
- // cspell:word samsunginternet
150
- samsunginternet_android: [10, 0],
151
- webview_android: 71
268
+ ios_saf: [12, 2],
269
+ samsung: [10, 1],
270
+ android: 71,
271
+ // and_qq: Unknown support
272
+ // baidu: Unknown support
273
+ // and_uc: Unknown support
274
+ // kaios: Unknown support
275
+ node: [12, 0]
152
276
  }),
153
277
 
154
278
  browser: browserProperty,
@@ -848,7 +848,7 @@ const applyOptimizationDefaults = (
848
848
  if (development) return "named";
849
849
  return "natural";
850
850
  });
851
- D(optimization, "sideEffects", true);
851
+ F(optimization, "sideEffects", () => (production ? true : "flag"));
852
852
  D(optimization, "providedExports", true);
853
853
  D(optimization, "usedExports", production);
854
854
  D(optimization, "innerGraph", production);
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const Template = require("../Template");
8
9
  const makeSerializable = require("../util/makeSerializable");
9
10
  const HarmonyImportDependency = require("./HarmonyImportDependency");
10
11
  const NullDependency = require("./NullDependency");
@@ -62,14 +63,41 @@ HarmonyAcceptDependency.Template = class HarmonyAcceptDependencyTemplate extends
62
63
  */
63
64
  apply(dependency, source, templateContext) {
64
65
  const dep = /** @type {HarmonyAcceptDependency} */ (dependency);
65
- const { module, runtimeTemplate } = templateContext;
66
+ const {
67
+ module,
68
+ runtime,
69
+ runtimeRequirements,
70
+ runtimeTemplate,
71
+ moduleGraph,
72
+ chunkGraph
73
+ } = templateContext;
66
74
  const content = dep.dependencies
67
- .filter(dependency =>
68
- HarmonyImportDependency.Template.isImportEmitted(dependency, module)
69
- )
70
75
  .map(dependency => {
76
+ const referencedModule = moduleGraph.getModule(dependency);
77
+ return {
78
+ dependency,
79
+ runtimeCondition: referencedModule
80
+ ? HarmonyImportDependency.Template.getImportEmittedRuntime(
81
+ module,
82
+ referencedModule
83
+ )
84
+ : false
85
+ };
86
+ })
87
+ .filter(({ runtimeCondition }) => runtimeCondition !== false)
88
+ .map(({ dependency, runtimeCondition }) => {
89
+ const condition = runtimeTemplate.runtimeConditionExpression({
90
+ chunkGraph,
91
+ runtime,
92
+ runtimeCondition,
93
+ runtimeRequirements
94
+ });
71
95
  const s = dependency.getImportStatement(true, templateContext);
72
- return s[0] + s[1];
96
+ const code = s[0] + s[1];
97
+ if (condition !== "true") {
98
+ return `if (${condition}) {\n${Template.indent(code)}\n}\n`;
99
+ }
100
+ return code;
73
101
  })
74
102
  .join("");
75
103
 
@@ -244,11 +244,6 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
244
244
  mode.fakeType = 2;
245
245
  break;
246
246
  case "dynamic":
247
- mode = new ExportMode("reexport-fake-namespace-object");
248
- mode.name = name;
249
- mode.partialNamespaceExportInfo = exportInfo;
250
- mode.fakeType = 6;
251
- break;
252
247
  default:
253
248
  mode = new ExportMode("reexport-namespace-object");
254
249
  mode.name = name;
@@ -5,11 +5,13 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const ConditionalInitFragment = require("../ConditionalInitFragment");
8
9
  const Dependency = require("../Dependency");
9
10
  const HarmonyLinkingError = require("../HarmonyLinkingError");
10
11
  const InitFragment = require("../InitFragment");
11
12
  const Template = require("../Template");
12
13
  const AwaitDependenciesInitFragment = require("../async-modules/AwaitDependenciesInitFragment");
14
+ const { filterRuntime, mergeRuntime } = require("../util/runtime");
13
15
  const ModuleDependency = require("./ModuleDependency");
14
16
 
15
17
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
@@ -199,21 +201,38 @@ class HarmonyImportDependency extends ModuleDependency {
199
201
  * @returns {void}
200
202
  */
201
203
  updateHash(hash, context) {
202
- const { chunkGraph } = context;
204
+ const { chunkGraph, runtime, runtimeTemplate } = context;
203
205
  const { moduleGraph } = chunkGraph;
204
206
  super.updateHash(hash, context);
205
- const importedModule = moduleGraph.getModule(this);
206
- if (importedModule) {
207
- const parentModule = moduleGraph.getParentModule(this);
208
- hash.update(
209
- importedModule.getExportsType(
210
- moduleGraph,
211
- parentModule.buildMeta && parentModule.buildMeta.strictHarmonyModule
212
- )
213
- );
214
- if (moduleGraph.isAsync(importedModule)) hash.update("async");
215
- }
216
207
  hash.update(`${this.sourceOrder}`);
208
+ const connection = moduleGraph.getConnection(this);
209
+ if (connection) {
210
+ const importedModule = connection.module;
211
+ if (importedModule) {
212
+ const parentModule = moduleGraph.getParentModule(this);
213
+ hash.update(
214
+ importedModule.getExportsType(
215
+ moduleGraph,
216
+ parentModule.buildMeta && parentModule.buildMeta.strictHarmonyModule
217
+ )
218
+ );
219
+ if (moduleGraph.isAsync(importedModule)) hash.update("async");
220
+ }
221
+ if (runtimeTemplate) {
222
+ const runtimeRequirements = new Set();
223
+ hash.update(
224
+ runtimeTemplate.runtimeConditionExpression({
225
+ chunkGraph,
226
+ runtimeCondition: filterRuntime(runtime, runtime => {
227
+ return connection.isTargetActive(runtime);
228
+ }),
229
+ runtime,
230
+ runtimeRequirements
231
+ })
232
+ );
233
+ for (const rr of runtimeRequirements) hash.update(rr);
234
+ }
235
+ }
217
236
  }
218
237
 
219
238
  serialize(context) {
@@ -231,6 +250,7 @@ class HarmonyImportDependency extends ModuleDependency {
231
250
 
232
251
  module.exports = HarmonyImportDependency;
233
252
 
253
+ /** @type {WeakMap<Module, WeakMap<Module, RuntimeSpec | boolean>>} */
234
254
  const importEmittedMap = new WeakMap();
235
255
 
236
256
  HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends ModuleDependency.Template {
@@ -265,23 +285,42 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends
265
285
  : dep.request;
266
286
  const key = `harmony import ${moduleKey}`;
267
287
 
268
- if (module) {
269
- let emittedModules = importEmittedMap.get(dep);
288
+ const runtimeCondition = dep.weak
289
+ ? false
290
+ : connection
291
+ ? filterRuntime(runtime, r => connection.isTargetActive(r))
292
+ : true;
293
+
294
+ if (module && referencedModule) {
295
+ let emittedModules = importEmittedMap.get(module);
270
296
  if (emittedModules === undefined) {
271
- emittedModules = new WeakSet();
272
- importEmittedMap.set(dep, emittedModules);
297
+ emittedModules = new WeakMap();
298
+ importEmittedMap.set(module, emittedModules);
299
+ }
300
+ let mergedRuntimeCondition = runtimeCondition;
301
+ const oldRuntimeCondition = emittedModules.get(referencedModule) || false;
302
+ if (oldRuntimeCondition !== false && mergedRuntimeCondition !== true) {
303
+ if (mergedRuntimeCondition === false || oldRuntimeCondition === true) {
304
+ mergedRuntimeCondition = oldRuntimeCondition;
305
+ } else {
306
+ mergedRuntimeCondition = mergeRuntime(
307
+ oldRuntimeCondition,
308
+ mergedRuntimeCondition
309
+ );
310
+ }
273
311
  }
274
- emittedModules.add(module);
312
+ emittedModules.set(referencedModule, mergedRuntimeCondition);
275
313
  }
276
314
 
277
315
  const importStatement = dep.getImportStatement(false, templateContext);
278
316
  if (templateContext.moduleGraph.isAsync(referencedModule)) {
279
317
  templateContext.initFragments.push(
280
- new InitFragment(
318
+ new ConditionalInitFragment(
281
319
  importStatement[0],
282
320
  InitFragment.STAGE_HARMONY_IMPORTS,
283
321
  dep.sourceOrder,
284
- key
322
+ key,
323
+ runtimeCondition
285
324
  )
286
325
  );
287
326
  templateContext.initFragments.push(
@@ -290,20 +329,22 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends
290
329
  )
291
330
  );
292
331
  templateContext.initFragments.push(
293
- new InitFragment(
332
+ new ConditionalInitFragment(
294
333
  importStatement[1],
295
334
  InitFragment.STAGE_ASYNC_HARMONY_IMPORTS,
296
335
  dep.sourceOrder,
297
- key + " compat"
336
+ key + " compat",
337
+ runtimeCondition
298
338
  )
299
339
  );
300
340
  } else {
301
341
  templateContext.initFragments.push(
302
- new InitFragment(
342
+ new ConditionalInitFragment(
303
343
  importStatement[0] + importStatement[1],
304
344
  InitFragment.STAGE_HARMONY_IMPORTS,
305
345
  dep.sourceOrder,
306
- key
346
+ key,
347
+ runtimeCondition
307
348
  )
308
349
  );
309
350
  }
@@ -311,12 +352,13 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends
311
352
 
312
353
  /**
313
354
  *
314
- * @param {Dependency} dep the dependency
315
355
  * @param {Module} module the module
316
- * @returns {boolean} true, when for this dependency and module a import init fragment was created
356
+ * @param {Module} referencedModule the referenced module
357
+ * @returns {RuntimeSpec | boolean} runtimeCondition in which this import has been emitted
317
358
  */
318
- static isImportEmitted(dep, module) {
319
- const emittedModules = importEmittedMap.get(dep);
320
- return emittedModules !== undefined && emittedModules.has(module);
359
+ static getImportEmittedRuntime(module, referencedModule) {
360
+ const emittedModules = importEmittedMap.get(module);
361
+ if (emittedModules === undefined) return false;
362
+ return emittedModules.get(referencedModule) || false;
321
363
  }
322
364
  };
@@ -59,9 +59,13 @@ module.exports = class HarmonyImportDependencyParserPlugin {
59
59
  (statement, source) => {
60
60
  parser.state.lastHarmonyImportOrder =
61
61
  (parser.state.lastHarmonyImportOrder || 0) + 1;
62
- const clearDep = new ConstDependency("", statement.range);
62
+ const clearDep = new ConstDependency(
63
+ parser.isAsiPosition(statement.range[0]) ? ";" : "",
64
+ statement.range
65
+ );
63
66
  clearDep.loc = statement.loc;
64
67
  parser.state.module.addPresentationalDependency(clearDep);
68
+ parser.unsetAsiPosition(statement.range[1]);
65
69
  const sideEffectDep = new HarmonyImportSideEffectDependency(
66
70
  source,
67
71
  parser.state.lastHarmonyImportOrder
@@ -196,7 +196,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
196
196
  * @returns {void}
197
197
  */
198
198
  updateHash(hash, context) {
199
- const { chunkGraph } = context;
199
+ const { chunkGraph, runtime } = context;
200
200
  super.updateHash(hash, context);
201
201
  const moduleGraph = chunkGraph.moduleGraph;
202
202
  const importedModule = moduleGraph.getModule(this);
@@ -204,7 +204,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
204
204
  hash.update(ids.join());
205
205
  if (importedModule) {
206
206
  const exportsInfo = moduleGraph.getExportsInfo(importedModule);
207
- hash.update(`${exportsInfo.getUsedName(ids, context.runtime)}`);
207
+ hash.update(`${exportsInfo.getUsedName(ids, runtime)}`);
208
208
  }
209
209
  }
210
210
 
@@ -7,6 +7,7 @@
7
7
 
8
8
  const { UsageState } = require("../ExportsInfo");
9
9
  const makeSerializable = require("../util/makeSerializable");
10
+ const { filterRuntime } = require("../util/runtime");
10
11
  const NullDependency = require("./NullDependency");
11
12
 
12
13
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
@@ -74,22 +75,45 @@ PureExpressionDependency.Template = class PureExpressionDependencyTemplate exten
74
75
  * @param {DependencyTemplateContext} templateContext the context object
75
76
  * @returns {void}
76
77
  */
77
- apply(dependency, source, { moduleGraph, runtime }) {
78
+ apply(
79
+ dependency,
80
+ source,
81
+ { chunkGraph, moduleGraph, runtime, runtimeTemplate, runtimeRequirements }
82
+ ) {
78
83
  const dep = /** @type {PureExpressionDependency} */ (dependency);
79
84
 
80
- if (dep.usedByExports !== false) {
85
+ const usedByExports = dep.usedByExports;
86
+ if (usedByExports !== false) {
81
87
  const selfModule = moduleGraph.getParentModule(dep);
82
88
  const exportsInfo = moduleGraph.getExportsInfo(selfModule);
83
- for (const exportName of dep.usedByExports) {
84
- if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused) {
85
- return;
89
+ const runtimeCondition = filterRuntime(runtime, runtime => {
90
+ for (const exportName of usedByExports) {
91
+ if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused) {
92
+ return true;
93
+ }
86
94
  }
95
+ return false;
96
+ });
97
+ if (runtimeCondition === true) return;
98
+ if (runtimeCondition !== false) {
99
+ const condition = runtimeTemplate.runtimeConditionExpression({
100
+ chunkGraph,
101
+ runtime,
102
+ runtimeCondition,
103
+ runtimeRequirements
104
+ });
105
+ source.insert(
106
+ dep.range[0],
107
+ `(/* runtime-dependent pure expression or super */ ${condition} ? (`
108
+ );
109
+ source.insert(dep.range[1], ") : null)");
110
+ return;
87
111
  }
88
112
  }
89
113
 
90
114
  source.insert(
91
115
  dep.range[0],
92
- "(/* unused pure expression or super */ null && ("
116
+ `(/* unused pure expression or super */ null && (`
93
117
  );
94
118
  source.insert(dep.range[1], "))");
95
119
  }
@@ -12,6 +12,7 @@ const UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning");
12
12
  const formatLocation = require("../formatLocation");
13
13
  const EnableChunkLoadingPlugin = require("../javascript/EnableChunkLoadingPlugin");
14
14
  const { equals } = require("../util/ArrayHelpers");
15
+ const { contextify } = require("../util/identifier");
15
16
  const {
16
17
  harmonySpecifierTag
17
18
  } = require("./HarmonyImportDependencyParserPlugin");
@@ -48,6 +49,10 @@ class WorkerPlugin {
48
49
  if (this._chunkLoading) {
49
50
  new EnableChunkLoadingPlugin(this._chunkLoading).apply(compiler);
50
51
  }
52
+ const cachedContextify = contextify.bindContextCache(
53
+ compiler.context,
54
+ compiler.root
55
+ );
51
56
  compiler.hooks.thisCompilation.tap(
52
57
  "WorkerPlugin",
53
58
  (compilation, { normalModuleFactory }) => {
@@ -213,9 +218,9 @@ class WorkerPlugin {
213
218
  }
214
219
 
215
220
  if (!entryOptions.runtime) {
216
- entryOptions.runtime = `${parser.state.module.identifier()}|${formatLocation(
217
- expr.loc
218
- )}`;
221
+ entryOptions.runtime = `${cachedContextify(
222
+ parser.state.module.identifier()
223
+ )}|${formatLocation(expr.loc)}`;
219
224
  }
220
225
 
221
226
  const block = new AsyncDependenciesBlock({