webpack 5.87.0 → 5.88.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.

Files changed (144) hide show
  1. package/lib/APIPlugin.js +1 -1
  2. package/lib/AsyncDependenciesBlock.js +3 -3
  3. package/lib/ChunkGraph.js +4 -4
  4. package/lib/ChunkGroup.js +9 -3
  5. package/lib/CompatibilityPlugin.js +50 -30
  6. package/lib/Compilation.js +2 -1
  7. package/lib/ContextModule.js +4 -1
  8. package/lib/ContextReplacementPlugin.js +13 -0
  9. package/lib/DelegatedModule.js +15 -3
  10. package/lib/DelegatedModuleFactoryPlugin.js +6 -0
  11. package/lib/Dependency.js +11 -5
  12. package/lib/DllEntryPlugin.js +11 -1
  13. package/lib/DllReferencePlugin.js +13 -1
  14. package/lib/Entrypoint.js +1 -1
  15. package/lib/ErrorHelpers.js +1 -0
  16. package/lib/EvalSourceMapDevToolPlugin.js +4 -0
  17. package/lib/ExportsInfo.js +17 -3
  18. package/lib/ExportsInfoApiPlugin.js +14 -5
  19. package/lib/ExternalModule.js +5 -0
  20. package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
  21. package/lib/FlagDependencyUsagePlugin.js +3 -1
  22. package/lib/HotModuleReplacementPlugin.js +8 -0
  23. package/lib/InitFragment.js +28 -5
  24. package/lib/JavascriptMetaInfoPlugin.js +11 -6
  25. package/lib/LibManifestPlugin.js +20 -4
  26. package/lib/Module.js +7 -2
  27. package/lib/ModuleProfile.js +1 -0
  28. package/lib/ModuleRestoreError.js +2 -0
  29. package/lib/NodeStuffPlugin.js +32 -6
  30. package/lib/ProvidePlugin.js +13 -4
  31. package/lib/RawModule.js +3 -1
  32. package/lib/RequireJsStuffPlugin.js +7 -0
  33. package/lib/RuntimeModule.js +3 -3
  34. package/lib/RuntimePlugin.js +4 -2
  35. package/lib/RuntimeTemplate.js +2 -2
  36. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  37. package/lib/SourceMapDevToolPlugin.js +7 -2
  38. package/lib/UseStrictPlugin.js +10 -3
  39. package/lib/WebpackIsIncludedPlugin.js +6 -4
  40. package/lib/asset/AssetGenerator.js +2 -1
  41. package/lib/asset/AssetParser.js +11 -6
  42. package/lib/asset/AssetSourceParser.js +8 -3
  43. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  44. package/lib/cache/IdleFileCachePlugin.js +2 -1
  45. package/lib/cache/PackFileCacheStrategy.js +35 -14
  46. package/lib/config/browserslistTargetHandler.js +7 -7
  47. package/lib/config/defaults.js +12 -24
  48. package/lib/container/RemoteRuntimeModule.js +1 -1
  49. package/lib/css/CssLoadingRuntimeModule.js +30 -13
  50. package/lib/css/CssParser.js +11 -1
  51. package/lib/dependencies/AMDDefineDependency.js +34 -4
  52. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
  53. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  54. package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
  55. package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
  56. package/lib/dependencies/CommonJsPlugin.js +13 -8
  57. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  58. package/lib/dependencies/ContextDependency.js +7 -2
  59. package/lib/dependencies/CssImportDependency.js +1 -1
  60. package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
  61. package/lib/dependencies/CssUrlDependency.js +3 -3
  62. package/lib/dependencies/DllEntryDependency.js +5 -0
  63. package/lib/dependencies/DynamicExports.js +10 -6
  64. package/lib/dependencies/ExportsInfoDependency.js +14 -4
  65. package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
  66. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
  67. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
  68. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
  69. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
  70. package/lib/dependencies/HarmonyExports.js +9 -5
  71. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +32 -17
  72. package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
  73. package/lib/dependencies/HarmonyImportSpecifierDependency.js +19 -9
  74. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  75. package/lib/dependencies/ImportDependency.js +5 -3
  76. package/lib/dependencies/ImportEagerDependency.js +5 -3
  77. package/lib/dependencies/ImportMetaPlugin.js +31 -15
  78. package/lib/dependencies/ImportParserPlugin.js +38 -25
  79. package/lib/dependencies/ImportWeakDependency.js +5 -3
  80. package/lib/dependencies/ModuleDependency.js +1 -1
  81. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  82. package/lib/dependencies/ProvidedDependency.js +4 -1
  83. package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
  84. package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
  85. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
  86. package/lib/dependencies/RequireHeaderDependency.js +4 -0
  87. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
  88. package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
  89. package/lib/dependencies/SystemPlugin.js +17 -5
  90. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  91. package/lib/dependencies/URLDependency.js +2 -2
  92. package/lib/dependencies/URLPlugin.js +9 -4
  93. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  94. package/lib/dependencies/WorkerPlugin.js +59 -22
  95. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
  96. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  97. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  98. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  99. package/lib/javascript/JavascriptParser.js +17 -5
  100. package/lib/logging/runtime.js +1 -1
  101. package/lib/logging/truncateArgs.js +4 -0
  102. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
  103. package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
  104. package/lib/optimize/InnerGraph.js +1 -1
  105. package/lib/optimize/InnerGraphPlugin.js +2 -1
  106. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +1 -1
  107. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +1 -1
  108. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -1
  109. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -1
  110. package/lib/runtime/AsyncModuleRuntimeModule.js +4 -4
  111. package/lib/runtime/AutoPublicPathRuntimeModule.js +1 -1
  112. package/lib/runtime/BaseUriRuntimeModule.js +1 -1
  113. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  114. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
  115. package/lib/runtime/CompatRuntimeModule.js +1 -1
  116. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
  117. package/lib/runtime/CreateScriptRuntimeModule.js +1 -1
  118. package/lib/runtime/CreateScriptUrlRuntimeModule.js +1 -1
  119. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +1 -1
  120. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -1
  121. package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -1
  122. package/lib/runtime/GetFullHashRuntimeModule.js +1 -1
  123. package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -1
  124. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  125. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  126. package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
  127. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  128. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
  129. package/lib/runtime/NonceRuntimeModule.js +1 -1
  130. package/lib/runtime/OnChunksLoadedRuntimeModule.js +1 -1
  131. package/lib/runtime/PublicPathRuntimeModule.js +1 -1
  132. package/lib/runtime/RelativeUrlRuntimeModule.js +1 -1
  133. package/lib/runtime/RuntimeIdRuntimeModule.js +1 -1
  134. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
  135. package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -1
  136. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  137. package/lib/sharing/ConsumeSharedRuntimeModule.js +1 -1
  138. package/lib/sharing/ShareRuntimeModule.js +1 -1
  139. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +1 -1
  140. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +1 -1
  141. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
  142. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  143. package/package.json +2 -1
  144. package/types.d.ts +86 -38
@@ -42,7 +42,7 @@ class URLDependency extends ModuleDependency {
42
42
  this.range = range;
43
43
  this.outerRange = outerRange;
44
44
  this.relative = relative || false;
45
- /** @type {Set<string> | boolean} */
45
+ /** @type {Set<string> | boolean | undefined} */
46
46
  this.usedByExports = undefined;
47
47
  }
48
48
 
@@ -68,7 +68,7 @@ class URLDependency extends ModuleDependency {
68
68
 
69
69
  /**
70
70
  * @param {string} context context directory
71
- * @returns {Module} a module
71
+ * @returns {Module | null} a module
72
72
  */
73
73
  createIgnoredModule(context) {
74
74
  const RawDataUrlModule = getRawDataUrlModule();
@@ -18,9 +18,11 @@ const URLDependency = require("./URLDependency");
18
18
  /** @typedef {import("estree").NewExpression} NewExpressionNode */
19
19
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
20
20
  /** @typedef {import("../Compiler")} Compiler */
21
+ /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
21
22
  /** @typedef {import("../NormalModule")} NormalModule */
22
23
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
23
24
  /** @typedef {import("../javascript/JavascriptParser")} Parser */
25
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
24
26
 
25
27
  const PLUGIN_NAME = "URLPlugin";
26
28
 
@@ -94,7 +96,7 @@ class URLPlugin {
94
96
 
95
97
  return new BasicEvaluatedExpression()
96
98
  .setString(url.toString())
97
- .setRange(expr.range);
99
+ .setRange(/** @type {Range} */ (expr.range));
98
100
  });
99
101
  parser.hooks.new.for("URL").tap(PLUGIN_NAME, _expr => {
100
102
  const expr = /** @type {NewExpressionNode} */ (_expr);
@@ -106,11 +108,14 @@ class URLPlugin {
106
108
  const [arg1, arg2] = expr.arguments;
107
109
  const dep = new URLDependency(
108
110
  request,
109
- [arg1.range[0], arg2.range[1]],
110
- expr.range,
111
+ [
112
+ /** @type {Range} */ (arg1.range)[0],
113
+ /** @type {Range} */ (arg2.range)[1]
114
+ ],
115
+ /** @type {Range} */ (expr.range),
111
116
  relative
112
117
  );
113
- dep.loc = expr.loc;
118
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
114
119
  parser.state.current.addDependency(dep);
115
120
  InnerGraph.onUsage(parser.state, e => (dep.usedByExports = e));
116
121
  return true;
@@ -55,7 +55,7 @@ class WebAssemblyImportDependency extends ModuleDependency {
55
55
  /**
56
56
  * Returns errors
57
57
  * @param {ModuleGraph} moduleGraph module graph
58
- * @returns {WebpackError[]} errors
58
+ * @returns {WebpackError[] | null | undefined} errors
59
59
  */
60
60
  getErrors(moduleGraph) {
61
61
  const module = moduleGraph.getModule(this);
@@ -25,20 +25,32 @@ const {
25
25
  } = require("./HarmonyImportDependencyParserPlugin");
26
26
  const WorkerDependency = require("./WorkerDependency");
27
27
 
28
+ /** @typedef {import("estree").CallExpression} CallExpression */
28
29
  /** @typedef {import("estree").Expression} Expression */
29
30
  /** @typedef {import("estree").ObjectExpression} ObjectExpression */
30
31
  /** @typedef {import("estree").Pattern} Pattern */
31
32
  /** @typedef {import("estree").Property} Property */
32
33
  /** @typedef {import("estree").SpreadElement} SpreadElement */
34
+ /** @typedef {import("../../declarations/WebpackOptions").ChunkLoading} ChunkLoading */
33
35
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
36
+ /** @typedef {import("../../declarations/WebpackOptions").OutputModule} OutputModule */
37
+ /** @typedef {import("../../declarations/WebpackOptions").WasmLoading} WasmLoading */
38
+ /** @typedef {import("../../declarations/WebpackOptions").WorkerPublicPath} WorkerPublicPath */
34
39
  /** @typedef {import("../Compiler")} Compiler */
40
+ /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
35
41
  /** @typedef {import("../Entrypoint").EntryOptions} EntryOptions */
42
+ /** @typedef {import("../NormalModule")} NormalModule */
36
43
  /** @typedef {import("../Parser").ParserState} ParserState */
37
44
  /** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
38
45
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
39
46
  /** @typedef {import("../javascript/JavascriptParser")} Parser */
47
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
40
48
  /** @typedef {import("./HarmonyImportDependencyParserPlugin").HarmonySettings} HarmonySettings */
41
49
 
50
+ /**
51
+ * @param {NormalModule} module module
52
+ * @returns {string} url
53
+ */
42
54
  const getUrl = module => {
43
55
  return pathToFileURL(module.resource).toString();
44
56
  };
@@ -58,6 +70,12 @@ const workerIndexMap = new WeakMap();
58
70
  const PLUGIN_NAME = "WorkerPlugin";
59
71
 
60
72
  class WorkerPlugin {
73
+ /**
74
+ * @param {ChunkLoading} chunkLoading chunk loading
75
+ * @param {WasmLoading} wasmLoading wasm loading
76
+ * @param {OutputModule} module output module
77
+ * @param {WorkerPublicPath} workerPublicPath worker public path
78
+ */
61
79
  constructor(chunkLoading, wasmLoading, module, workerPublicPath) {
62
80
  this._chunkLoading = chunkLoading;
63
81
  this._wasmLoading = wasmLoading;
@@ -99,7 +117,7 @@ class WorkerPlugin {
99
117
  /**
100
118
  * @param {JavascriptParser} parser the parser
101
119
  * @param {Expression} expr expression
102
- * @returns {[BasicEvaluatedExpression, [number, number]]} parsed
120
+ * @returns {[BasicEvaluatedExpression, [number, number]] | void} parsed
103
121
  */
104
122
  const parseModuleUrl = (parser, expr) => {
105
123
  if (
@@ -116,13 +134,19 @@ class WorkerPlugin {
116
134
  const arg2Value = parser.evaluateExpression(arg2);
117
135
  if (
118
136
  !arg2Value.isString() ||
119
- !arg2Value.string.startsWith("file://") ||
137
+ !(/** @type {string} */ (arg2Value.string).startsWith("file://")) ||
120
138
  arg2Value.string !== getUrl(parser.state.module)
121
139
  ) {
122
140
  return;
123
141
  }
124
142
  const arg1Value = parser.evaluateExpression(arg1);
125
- return [arg1Value, [arg1.range[0], arg2.range[1]]];
143
+ return [
144
+ arg1Value,
145
+ [
146
+ /** @type {Range} */ (arg1.range)[0],
147
+ /** @type {Range} */ (arg2.range)[1]
148
+ ]
149
+ ];
126
150
  };
127
151
 
128
152
  /**
@@ -182,6 +206,10 @@ class WorkerPlugin {
182
206
  const options = !Array.isArray(parserOptions.worker)
183
207
  ? ["..."]
184
208
  : parserOptions.worker;
209
+ /**
210
+ * @param {CallExpression} expr expression
211
+ * @returns {boolean | void} true when handled
212
+ */
185
213
  const handleNewWorker = expr => {
186
214
  if (expr.arguments.length === 0 || expr.arguments.length > 2)
187
215
  return;
@@ -209,10 +237,12 @@ class WorkerPlugin {
209
237
  values: {},
210
238
  spread: false,
211
239
  insertType: arg2 ? "spread" : "argument",
212
- insertLocation: arg2 ? arg2.range : arg1.range[1]
240
+ insertLocation: arg2
241
+ ? /** @type {Range} */ (arg2.range)
242
+ : /** @type {Range} */ (arg1.range)[1]
213
243
  };
214
244
  const { options: importOptions, errors: commentErrors } =
215
- parser.parseCommentOptions(expr.range);
245
+ parser.parseCommentOptions(/** @type {Range} */ (expr.range));
216
246
 
217
247
  if (commentErrors) {
218
248
  for (const e of commentErrors) {
@@ -235,7 +265,7 @@ class WorkerPlugin {
235
265
  parser.state.module.addWarning(
236
266
  new UnsupportedFeatureWarning(
237
267
  `\`webpackIgnore\` expected a boolean, but received: ${importOptions.webpackIgnore}.`,
238
- expr.loc
268
+ /** @type {DependencyLocation} */ (expr.loc)
239
269
  )
240
270
  );
241
271
  } else {
@@ -252,7 +282,7 @@ class WorkerPlugin {
252
282
  parser.state.module.addWarning(
253
283
  new UnsupportedFeatureWarning(
254
284
  `\`webpackEntryOptions\` expected a object, but received: ${importOptions.webpackEntryOptions}.`,
255
- expr.loc
285
+ /** @type {DependencyLocation} */ (expr.loc)
256
286
  )
257
287
  );
258
288
  } else {
@@ -267,7 +297,7 @@ class WorkerPlugin {
267
297
  parser.state.module.addWarning(
268
298
  new UnsupportedFeatureWarning(
269
299
  `\`webpackChunkName\` expected a string, but received: ${importOptions.webpackChunkName}.`,
270
- expr.loc
300
+ /** @type {DependencyLocation} */ (expr.loc)
271
301
  )
272
302
  );
273
303
  } else {
@@ -310,18 +340,22 @@ class WorkerPlugin {
310
340
  }
311
341
  });
312
342
  block.loc = expr.loc;
313
- const dep = new WorkerDependency(url.string, range, {
314
- publicPath: this._workerPublicPath
315
- });
316
- dep.loc = expr.loc;
343
+ const dep = new WorkerDependency(
344
+ /** @type {string} */ (url.string),
345
+ range,
346
+ {
347
+ publicPath: this._workerPublicPath
348
+ }
349
+ );
350
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
317
351
  block.addDependency(dep);
318
352
  parser.state.module.addBlock(block);
319
353
 
320
354
  if (compilation.outputOptions.trustedTypes) {
321
355
  const dep = new CreateScriptUrlDependency(
322
- expr.arguments[0].range
356
+ /** @type {Range} */ (expr.arguments[0].range)
323
357
  );
324
- dep.loc = expr.loc;
358
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
325
359
  parser.state.module.addDependency(dep);
326
360
  }
327
361
 
@@ -330,9 +364,9 @@ class WorkerPlugin {
330
364
  if (options.type !== false) {
331
365
  const dep = new ConstDependency(
332
366
  this._module ? '"module"' : "undefined",
333
- expr.range
367
+ /** @type {Range} */ (expr.range)
334
368
  );
335
- dep.loc = expr.loc;
369
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
336
370
  parser.state.module.addPresentationalDependency(dep);
337
371
  expressions.type = undefined;
338
372
  }
@@ -342,20 +376,20 @@ class WorkerPlugin {
342
376
  `, type: ${this._module ? '"module"' : "undefined"}`,
343
377
  insertLocation
344
378
  );
345
- dep.loc = expr.loc;
379
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
346
380
  parser.state.module.addPresentationalDependency(dep);
347
381
  }
348
382
  } else if (insertType === "spread") {
349
383
  const dep1 = new ConstDependency(
350
384
  "Object.assign({}, ",
351
- insertLocation[0]
385
+ /** @type {Range} */ (insertLocation)[0]
352
386
  );
353
387
  const dep2 = new ConstDependency(
354
388
  `, { type: ${this._module ? '"module"' : "undefined"} })`,
355
- insertLocation[1]
389
+ /** @type {Range} */ (insertLocation)[1]
356
390
  );
357
- dep1.loc = expr.loc;
358
- dep2.loc = expr.loc;
391
+ dep1.loc = /** @type {DependencyLocation} */ (expr.loc);
392
+ dep2.loc = /** @type {DependencyLocation} */ (expr.loc);
359
393
  parser.state.module.addPresentationalDependency(dep1);
360
394
  parser.state.module.addPresentationalDependency(dep2);
361
395
  } else if (insertType === "argument") {
@@ -364,7 +398,7 @@ class WorkerPlugin {
364
398
  ', { type: "module" }',
365
399
  insertLocation
366
400
  );
367
- dep.loc = expr.loc;
401
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
368
402
  parser.state.module.addPresentationalDependency(dep);
369
403
  }
370
404
  }
@@ -382,6 +416,9 @@ class WorkerPlugin {
382
416
 
383
417
  return true;
384
418
  };
419
+ /**
420
+ * @param {string} item item
421
+ */
385
422
  const processItem = item => {
386
423
  if (
387
424
  item.startsWith("*") &&
@@ -20,7 +20,7 @@ class ExportWebpackRequireRuntimeModule extends RuntimeModule {
20
20
  }
21
21
 
22
22
  /**
23
- * @returns {string} runtime code
23
+ * @returns {string | null} runtime code
24
24
  */
25
25
  generate() {
26
26
  return `export default ${RuntimeGlobals.require};`;
@@ -80,7 +80,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
80
80
  }
81
81
 
82
82
  /**
83
- * @returns {string} runtime code
83
+ * @returns {string | null} runtime code
84
84
  */
85
85
  generate() {
86
86
  const compilation = /** @type {Compilation} */ (this.compilation);
@@ -14,7 +14,7 @@ class HotModuleReplacementRuntimeModule extends RuntimeModule {
14
14
  super("hot module replacement", RuntimeModule.STAGE_BASIC);
15
15
  }
16
16
  /**
17
- * @returns {string} runtime code
17
+ * @returns {string | null} runtime code
18
18
  */
19
19
  generate() {
20
20
  return Template.getFunctionContent(
@@ -36,7 +36,7 @@ class HashedModuleIdsPlugin {
36
36
 
37
37
  /** @type {HashedModuleIdsPluginOptions} */
38
38
  this.options = {
39
- context: null,
39
+ context: undefined,
40
40
  hashFunction: "md4",
41
41
  hashDigest: "base64",
42
42
  hashDigestLength: 4,
@@ -132,9 +132,10 @@ class VariableInfo {
132
132
  * @property {StackedMap<string, VariableInfo | ScopeInfo>} definitions
133
133
  * @property {boolean | "arrow"} topLevelScope
134
134
  * @property {boolean | string} inShorthand
135
+ * @property {boolean} inTaggedTemplateTag
136
+ * @property {boolean} inTry
135
137
  * @property {boolean} isStrict
136
138
  * @property {boolean} isAsmJs
137
- * @property {boolean} inTry
138
139
  */
139
140
 
140
141
  /** @typedef {[number, number]} Range */
@@ -348,7 +349,7 @@ class JavascriptParser extends Parser {
348
349
  importCall: new SyncBailHook(["expression"]),
349
350
  /** @type {SyncBailHook<[Expression], boolean | void>} */
350
351
  topLevelAwait: new SyncBailHook(["expression"]),
351
- /** @type {HookMap<SyncBailHook<[BaseCallExpression], boolean | void>>} */
352
+ /** @type {HookMap<SyncBailHook<[CallExpression], boolean | void>>} */
352
353
  call: new HookMap(() => new SyncBailHook(["expression"])),
353
354
  /** Something like "a.b()" */
354
355
  /** @type {HookMap<SyncBailHook<[CallExpression, string[], boolean[], Range[]], boolean | void>>} */
@@ -373,7 +374,7 @@ class JavascriptParser extends Parser {
373
374
  ])
374
375
  ),
375
376
  /** Something like "a.b().c.d()"" */
376
- /** @type {HookMap<SyncBailHook<[Expression, string[], CallExpression, string[]], boolean | void>>} */
377
+ /** @type {HookMap<SyncBailHook<[CallExpression, string[], CallExpression, string[]], boolean | void>>} */
377
378
  callMemberChainOfCallMemberChain: new HookMap(
378
379
  () =>
379
380
  new SyncBailHook([
@@ -391,7 +392,7 @@ class JavascriptParser extends Parser {
391
392
  binaryExpression: new SyncBailHook(["binaryExpression"]),
392
393
  /** @type {HookMap<SyncBailHook<[Expression], boolean | void>>} */
393
394
  expression: new HookMap(() => new SyncBailHook(["expression"])),
394
- /** @type {HookMap<SyncBailHook<[Expression, string[], boolean[], Range[]], boolean | void>>} */
395
+ /** @type {HookMap<SyncBailHook<[MemberExpression, string[], boolean[], Range[]], boolean | void>>} */
395
396
  expressionMemberChain: new HookMap(
396
397
  () =>
397
398
  new SyncBailHook([
@@ -401,7 +402,7 @@ class JavascriptParser extends Parser {
401
402
  "memberRanges"
402
403
  ])
403
404
  ),
404
- /** @type {HookMap<SyncBailHook<[Expression, string[]], boolean | void>>} */
405
+ /** @type {HookMap<SyncBailHook<[MemberExpression, string[]], boolean | void>>} */
405
406
  unhandledExpressionMemberChain: new HookMap(
406
407
  () => new SyncBailHook(["expression", "members"])
407
408
  ),
@@ -2473,6 +2474,10 @@ class JavascriptParser extends Parser {
2473
2474
  }
2474
2475
  }
2475
2476
 
2477
+ /**
2478
+ * @param {ObjectPattern} objectPattern object pattern
2479
+ * @returns {Set<string> | undefined} set of names or undefined if not all keys are identifiers
2480
+ */
2476
2481
  _preWalkObjectPattern(objectPattern) {
2477
2482
  const ids = new Set();
2478
2483
  const properties = objectPattern.properties;
@@ -3126,7 +3131,9 @@ class JavascriptParser extends Parser {
3126
3131
  */
3127
3132
  walkTaggedTemplateExpression(expression) {
3128
3133
  if (expression.tag) {
3134
+ this.scope.inTaggedTemplateTag = true;
3129
3135
  this.walkExpression(expression.tag);
3136
+ this.scope.inTaggedTemplateTag = false;
3130
3137
  }
3131
3138
  if (expression.quasi && expression.quasi.expressions) {
3132
3139
  this.walkExpressions(expression.quasi.expressions);
@@ -3588,6 +3595,7 @@ class JavascriptParser extends Parser {
3588
3595
  topLevelScope: oldScope.topLevelScope,
3589
3596
  inTry: false,
3590
3597
  inShorthand: false,
3598
+ inTaggedTemplateTag: false,
3591
3599
  isStrict: oldScope.isStrict,
3592
3600
  isAsmJs: oldScope.isAsmJs,
3593
3601
  definitions: oldScope.definitions.createChild()
@@ -3616,6 +3624,7 @@ class JavascriptParser extends Parser {
3616
3624
  topLevelScope: oldScope.topLevelScope,
3617
3625
  inTry: false,
3618
3626
  inShorthand: false,
3627
+ inTaggedTemplateTag: false,
3619
3628
  isStrict: oldScope.isStrict,
3620
3629
  isAsmJs: oldScope.isAsmJs,
3621
3630
  definitions: oldScope.definitions.createChild()
@@ -3646,6 +3655,7 @@ class JavascriptParser extends Parser {
3646
3655
  topLevelScope: oldScope.topLevelScope,
3647
3656
  inTry: false,
3648
3657
  inShorthand: false,
3658
+ inTaggedTemplateTag: false,
3649
3659
  isStrict: oldScope.isStrict,
3650
3660
  isAsmJs: oldScope.isAsmJs,
3651
3661
  definitions: oldScope.definitions.createChild()
@@ -3674,6 +3684,7 @@ class JavascriptParser extends Parser {
3674
3684
  topLevelScope: oldScope.topLevelScope,
3675
3685
  inTry: oldScope.inTry,
3676
3686
  inShorthand: false,
3687
+ inTaggedTemplateTag: false,
3677
3688
  isStrict: oldScope.isStrict,
3678
3689
  isAsmJs: oldScope.isAsmJs,
3679
3690
  definitions: oldScope.definitions.createChild()
@@ -3963,6 +3974,7 @@ class JavascriptParser extends Parser {
3963
3974
  topLevelScope: true,
3964
3975
  inTry: false,
3965
3976
  inShorthand: false,
3977
+ inTaggedTemplateTag: false,
3966
3978
  isStrict: false,
3967
3979
  isAsmJs: false,
3968
3980
  definitions: new StackedMap()
@@ -5,7 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const SyncBailHook = require("tapable/lib/SyncBailHook");
8
+ const { SyncBailHook } = require("tapable");
9
9
  const { Logger } = require("./Logger");
10
10
  const createConsoleLogger = require("./createConsoleLogger");
11
11
 
@@ -5,6 +5,10 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ /**
9
+ * @param {Array<number>} array array of numbers
10
+ * @returns {number} sum of all numbers in array
11
+ */
8
12
  const arraySum = array => {
9
13
  let sum = 0;
10
14
  for (const item of array) sum += item;
@@ -16,6 +16,8 @@ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
16
16
  const { getUndoPath } = require("../util/identifier");
17
17
 
18
18
  /** @typedef {import("../Chunk")} Chunk */
19
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
20
+ /** @typedef {import("../Compilation")} Compilation */
19
21
 
20
22
  class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
21
23
  /**
@@ -46,11 +48,13 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
46
48
  }
47
49
 
48
50
  /**
49
- * @returns {string} runtime code
51
+ * @returns {string | null} runtime code
50
52
  */
51
53
  generate() {
52
- const { chunkGraph, chunk } = this;
53
- const { runtimeTemplate } = this.compilation;
54
+ const compilation = /** @type {Compilation} */ (this.compilation);
55
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
56
+ const chunk = /** @type {Chunk} */ (this.chunk);
57
+ const { runtimeTemplate } = compilation;
54
58
  const fn = RuntimeGlobals.ensureChunkHandlers;
55
59
  const withBaseURI = this.runtimeRequirements.has(RuntimeGlobals.baseURI);
56
60
  const withExternalInstallChunk = this.runtimeRequirements.has(
@@ -72,8 +76,8 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
72
76
  const hasJsMatcher = compileBooleanMatcher(conditionMap);
73
77
  const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
74
78
 
75
- const outputName = this.compilation.getPath(
76
- getChunkFilenameTemplate(chunk, this.compilation.outputOptions),
79
+ const outputName = compilation.getPath(
80
+ getChunkFilenameTemplate(chunk, compilation.outputOptions),
77
81
  {
78
82
  chunk,
79
83
  contentHashType: "javascript"
@@ -81,7 +85,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
81
85
  );
82
86
  const rootOutputDir = getUndoPath(
83
87
  outputName,
84
- /** @type {string} */ (this.compilation.outputOptions.path),
88
+ /** @type {string} */ (compilation.outputOptions.path),
85
89
  false
86
90
  );
87
91
 
@@ -16,6 +16,8 @@ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
16
16
  const { getUndoPath } = require("../util/identifier");
17
17
 
18
18
  /** @typedef {import("../Chunk")} Chunk */
19
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
20
+ /** @typedef {import("../Compilation")} Compilation */
19
21
 
20
22
  class RequireChunkLoadingRuntimeModule extends RuntimeModule {
21
23
  /**
@@ -46,11 +48,13 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
46
48
  }
47
49
 
48
50
  /**
49
- * @returns {string} runtime code
51
+ * @returns {string | null} runtime code
50
52
  */
51
53
  generate() {
52
- const { chunkGraph, chunk } = this;
53
- const { runtimeTemplate } = this.compilation;
54
+ const compilation = /** @type {Compilation} */ (this.compilation);
55
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
56
+ const chunk = /** @type {Chunk} */ (this.chunk);
57
+ const { runtimeTemplate } = compilation;
54
58
  const fn = RuntimeGlobals.ensureChunkHandlers;
55
59
  const withBaseURI = this.runtimeRequirements.has(RuntimeGlobals.baseURI);
56
60
  const withExternalInstallChunk = this.runtimeRequirements.has(
@@ -72,8 +76,8 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
72
76
  const hasJsMatcher = compileBooleanMatcher(conditionMap);
73
77
  const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
74
78
 
75
- const outputName = this.compilation.getPath(
76
- getChunkFilenameTemplate(chunk, this.compilation.outputOptions),
79
+ const outputName = compilation.getPath(
80
+ getChunkFilenameTemplate(chunk, compilation.outputOptions),
77
81
  {
78
82
  chunk,
79
83
  contentHashType: "javascript"
@@ -81,7 +85,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
81
85
  );
82
86
  const rootOutputDir = getUndoPath(
83
87
  outputName,
84
- /** @type {string} */ (this.compilation.outputOptions.path),
88
+ /** @type {string} */ (compilation.outputOptions.path),
85
89
  true
86
90
  );
87
91
 
@@ -309,7 +309,7 @@ exports.isDependencyUsedByExports = (
309
309
 
310
310
  /**
311
311
  * @param {Dependency} dependency the dependency
312
- * @param {Set<string> | boolean} usedByExports usedByExports info
312
+ * @param {Set<string> | boolean | undefined} usedByExports usedByExports info
313
313
  * @param {ModuleGraph} moduleGraph moduleGraph
314
314
  * @returns {null | false | function(ModuleGraphConnection, RuntimeSpec): ConnectionState} function to determine if the connection is active
315
315
  */
@@ -16,6 +16,7 @@ const InnerGraph = require("./InnerGraph");
16
16
  /** @typedef {import("estree").ClassExpression} ClassExpressionNode */
17
17
  /** @typedef {import("estree").Node} Node */
18
18
  /** @typedef {import("estree").VariableDeclarator} VariableDeclaratorNode */
19
+ /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
19
20
  /** @typedef {import("../Compiler")} Compiler */
20
21
  /** @typedef {import("../Dependency")} Dependency */
21
22
  /** @typedef {import("../dependencies/HarmonyImportSpecifierDependency")} HarmonyImportSpecifierDependency */
@@ -46,7 +47,7 @@ class InnerGraphPlugin {
46
47
 
47
48
  /**
48
49
  * @param {JavascriptParser} parser the parser
49
- * @param {Object} parserOptions options
50
+ * @param {JavascriptParserOptions} parserOptions options
50
51
  * @returns {void}
51
52
  */
52
53
  const handler = (parser, parserOptions) => {
@@ -24,7 +24,7 @@ class ChunkPrefetchFunctionRuntimeModule extends RuntimeModule {
24
24
  }
25
25
 
26
26
  /**
27
- * @returns {string} runtime code
27
+ * @returns {string | null} runtime code
28
28
  */
29
29
  generate() {
30
30
  const { runtimeFunction, runtimeHandlers } = this;
@@ -22,7 +22,7 @@ class ChunkPrefetchStartupRuntimeModule extends RuntimeModule {
22
22
  }
23
23
 
24
24
  /**
25
- * @returns {string} runtime code
25
+ * @returns {string | null} runtime code
26
26
  */
27
27
  generate() {
28
28
  const { startupChunks } = this;
@@ -21,7 +21,7 @@ class ChunkPrefetchTriggerRuntimeModule extends RuntimeModule {
21
21
  }
22
22
 
23
23
  /**
24
- * @returns {string} runtime code
24
+ * @returns {string | null} runtime code
25
25
  */
26
26
  generate() {
27
27
  const { chunkMap } = this;
@@ -21,7 +21,7 @@ class ChunkPreloadTriggerRuntimeModule extends RuntimeModule {
21
21
  }
22
22
 
23
23
  /**
24
- * @returns {string} runtime code
24
+ * @returns {string | null} runtime code
25
25
  */
26
26
  generate() {
27
27
  const { chunkMap } = this;
@@ -16,7 +16,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
16
16
  }
17
17
 
18
18
  /**
19
- * @returns {string} runtime code
19
+ * @returns {string | null} runtime code
20
20
  */
21
21
  generate() {
22
22
  const compilation = /** @type {Compilation} */ (this.compilation);
@@ -27,7 +27,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
27
27
  `var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "${RuntimeGlobals.exports}";`,
28
28
  'var webpackError = typeof Symbol === "function" ? Symbol("webpack error") : "__webpack_error__";',
29
29
  `var resolveQueue = ${runtimeTemplate.basicFunction("queue", [
30
- "if(queue && !queue.d) {",
30
+ "if(queue && queue.d < 1) {",
31
31
  Template.indent([
32
32
  "queue.d = 1;",
33
33
  `queue.forEach(${runtimeTemplate.expressionFunction(
@@ -76,7 +76,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
76
76
  )};`,
77
77
  `${fn} = ${runtimeTemplate.basicFunction("module, body, hasAwait", [
78
78
  "var queue;",
79
- "hasAwait && ((queue = []).d = 1);",
79
+ "hasAwait && ((queue = []).d = -1);",
80
80
  "var depQueues = new Set();",
81
81
  "var exports = module.exports;",
82
82
  "var currentDeps;",
@@ -124,7 +124,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
124
124
  "(err ? reject(promise[webpackError] = err) : outerResolve(exports)), resolveQueue(queue)",
125
125
  "err"
126
126
  )});`,
127
- "queue && (queue.d = 0);"
127
+ "queue && queue.d < 0 && (queue.d = 0);"
128
128
  ])};`
129
129
  ]);
130
130
  }
@@ -18,7 +18,7 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
18
18
  }
19
19
 
20
20
  /**
21
- * @returns {string} runtime code
21
+ * @returns {string | null} runtime code
22
22
  */
23
23
  generate() {
24
24
  const compilation = /** @type {Compilation} */ (this.compilation);
@@ -17,7 +17,7 @@ class BaseUriRuntimeModule extends RuntimeModule {
17
17
  }
18
18
 
19
19
  /**
20
- * @returns {string} runtime code
20
+ * @returns {string | null} runtime code
21
21
  */
22
22
  generate() {
23
23
  const chunk = /** @type {Chunk} */ (this.chunk);