webpack 5.90.3 → 5.91.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 (174) hide show
  1. package/README.md +5 -5
  2. package/bin/webpack.js +5 -1
  3. package/lib/APIPlugin.js +8 -4
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/BannerPlugin.js +3 -1
  6. package/lib/Cache.js +7 -1
  7. package/lib/CacheFacade.js +3 -3
  8. package/lib/ChunkGraph.js +32 -18
  9. package/lib/ChunkGroup.js +14 -14
  10. package/lib/CleanPlugin.js +7 -5
  11. package/lib/Compilation.js +262 -93
  12. package/lib/Compiler.js +199 -83
  13. package/lib/ConditionalInitFragment.js +4 -5
  14. package/lib/ContextModule.js +2 -0
  15. package/lib/ContextModuleFactory.js +4 -2
  16. package/lib/ContextReplacementPlugin.js +3 -2
  17. package/lib/DefinePlugin.js +4 -2
  18. package/lib/Dependency.js +4 -2
  19. package/lib/DependencyTemplate.js +7 -2
  20. package/lib/DllModule.js +1 -0
  21. package/lib/DllReferencePlugin.js +6 -2
  22. package/lib/EntryOptionPlugin.js +4 -1
  23. package/lib/EntryPlugin.js +6 -1
  24. package/lib/Entrypoint.js +1 -1
  25. package/lib/ExportsInfo.js +1 -4
  26. package/lib/ExternalModule.js +118 -24
  27. package/lib/ExternalModuleFactoryPlugin.js +37 -2
  28. package/lib/FileSystemInfo.js +1 -1
  29. package/lib/Generator.js +2 -1
  30. package/lib/HookWebpackError.js +2 -2
  31. package/lib/InitFragment.js +5 -3
  32. package/lib/LibManifestPlugin.js +15 -7
  33. package/lib/Module.js +30 -2
  34. package/lib/ModuleFilenameHelpers.js +1 -1
  35. package/lib/ModuleGraph.js +56 -27
  36. package/lib/ModuleGraphConnection.js +2 -1
  37. package/lib/MultiCompiler.js +26 -8
  38. package/lib/NodeStuffPlugin.js +14 -3
  39. package/lib/NormalModule.js +3 -1
  40. package/lib/NormalModuleFactory.js +1 -1
  41. package/lib/NormalModuleReplacementPlugin.js +5 -1
  42. package/lib/ProvidePlugin.js +3 -1
  43. package/lib/RawModule.js +2 -1
  44. package/lib/ResolverFactory.js +3 -1
  45. package/lib/RuntimeModule.js +4 -4
  46. package/lib/RuntimePlugin.js +1 -0
  47. package/lib/RuntimeTemplate.js +102 -34
  48. package/lib/SourceMapDevToolPlugin.js +4 -1
  49. package/lib/Stats.js +10 -3
  50. package/lib/TemplatedPathPlugin.js +32 -6
  51. package/lib/Watching.js +67 -60
  52. package/lib/WebpackError.js +6 -6
  53. package/lib/WebpackOptionsApply.js +18 -5
  54. package/lib/asset/RawDataUrlModule.js +3 -1
  55. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  56. package/lib/buildChunkGraph.js +117 -64
  57. package/lib/cache/IdleFileCachePlugin.js +8 -3
  58. package/lib/cache/MemoryCachePlugin.js +1 -1
  59. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  60. package/lib/cache/PackFileCacheStrategy.js +49 -16
  61. package/lib/cache/ResolverCachePlugin.js +14 -6
  62. package/lib/cache/getLazyHashedEtag.js +1 -1
  63. package/lib/config/defaults.js +24 -1
  64. package/lib/config/normalization.js +3 -1
  65. package/lib/container/ContainerEntryDependency.js +2 -1
  66. package/lib/container/ContainerEntryModule.js +3 -1
  67. package/lib/container/ContainerPlugin.js +14 -10
  68. package/lib/container/FallbackModule.js +1 -1
  69. package/lib/container/RemoteRuntimeModule.js +12 -3
  70. package/lib/css/CssExportsGenerator.js +34 -17
  71. package/lib/css/CssGenerator.js +20 -2
  72. package/lib/css/CssLoadingRuntimeModule.js +212 -96
  73. package/lib/css/CssModulesPlugin.js +47 -13
  74. package/lib/debug/ProfilingPlugin.js +27 -2
  75. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
  76. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  77. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
  78. package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
  79. package/lib/dependencies/CommonJsExportsDependency.js +13 -5
  80. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
  81. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
  82. package/lib/dependencies/ContextDependencyHelpers.js +49 -29
  83. package/lib/dependencies/ContextElementDependency.js +8 -1
  84. package/lib/dependencies/CssLocalIdentifierDependency.js +63 -8
  85. package/lib/dependencies/CssUrlDependency.js +5 -3
  86. package/lib/dependencies/ExportsInfoDependency.js +4 -3
  87. package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
  88. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
  89. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
  90. package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
  91. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
  92. package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
  93. package/lib/dependencies/HarmonyImportDependency.js +28 -12
  94. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +44 -16
  95. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
  96. package/lib/dependencies/HarmonyImportSpecifierDependency.js +6 -5
  97. package/lib/dependencies/ImportDependency.js +9 -2
  98. package/lib/dependencies/ImportEagerDependency.js +4 -2
  99. package/lib/dependencies/ImportMetaContextDependency.js +7 -0
  100. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
  101. package/lib/dependencies/ImportParserPlugin.js +12 -4
  102. package/lib/dependencies/ImportWeakDependency.js +4 -2
  103. package/lib/dependencies/LoaderDependency.js +2 -1
  104. package/lib/dependencies/LoaderImportDependency.js +2 -1
  105. package/lib/dependencies/ModuleDependency.js +4 -5
  106. package/lib/dependencies/PureExpressionDependency.js +4 -1
  107. package/lib/dependencies/RequireContextPlugin.js +1 -1
  108. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
  109. package/lib/dependencies/RequireEnsureDependency.js +1 -1
  110. package/lib/dependencies/URLDependency.js +7 -4
  111. package/lib/dependencies/WorkerPlugin.js +2 -1
  112. package/lib/dependencies/getFunctionExpression.js +3 -1
  113. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
  114. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  115. package/lib/javascript/ChunkHelpers.js +2 -2
  116. package/lib/javascript/JavascriptParser.js +169 -57
  117. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  118. package/lib/javascript/StartupHelpers.js +22 -5
  119. package/lib/logging/Logger.js +27 -2
  120. package/lib/logging/createConsoleLogger.js +11 -7
  121. package/lib/node/NodeEnvironmentPlugin.js +13 -7
  122. package/lib/node/NodeWatchFileSystem.js +37 -26
  123. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
  124. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
  125. package/lib/node/nodeConsole.js +24 -1
  126. package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
  127. package/lib/optimize/ConcatenatedModule.js +138 -54
  128. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  129. package/lib/optimize/InnerGraph.js +7 -2
  130. package/lib/optimize/InnerGraphPlugin.js +36 -13
  131. package/lib/optimize/ModuleConcatenationPlugin.js +12 -2
  132. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  133. package/lib/optimize/RuntimeChunkPlugin.js +6 -1
  134. package/lib/optimize/SideEffectsFlagPlugin.js +46 -15
  135. package/lib/optimize/SplitChunksPlugin.js +2 -2
  136. package/lib/performance/SizeLimitsPlugin.js +11 -0
  137. package/lib/rules/ObjectMatcherRulePlugin.js +4 -0
  138. package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
  139. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  140. package/lib/serialization/FileMiddleware.js +1 -0
  141. package/lib/serialization/ObjectMiddleware.js +2 -0
  142. package/lib/serialization/Serializer.js +19 -0
  143. package/lib/sharing/ConsumeSharedModule.js +1 -1
  144. package/lib/sharing/ConsumeSharedPlugin.js +17 -3
  145. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
  146. package/lib/sharing/ProvideSharedPlugin.js +12 -5
  147. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  148. package/lib/sharing/utils.js +13 -6
  149. package/lib/util/StackedCacheMap.js +26 -0
  150. package/lib/util/WeakTupleMap.js +57 -13
  151. package/lib/util/cleverMerge.js +24 -11
  152. package/lib/util/comparators.js +34 -14
  153. package/lib/util/conventions.js +129 -0
  154. package/lib/util/fs.js +379 -65
  155. package/lib/util/hash/BatchedHash.js +3 -0
  156. package/lib/util/hash/xxhash64.js +2 -2
  157. package/lib/util/runtime.js +1 -1
  158. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
  159. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +15 -6
  160. package/lib/wasm-sync/WebAssemblyGenerator.js +27 -6
  161. package/lib/wasm-sync/WebAssemblyParser.js +7 -4
  162. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
  163. package/lib/webpack.js +7 -3
  164. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
  165. package/package.json +25 -26
  166. package/schemas/WebpackOptions.check.js +1 -1
  167. package/schemas/WebpackOptions.json +69 -8
  168. package/schemas/plugins/BannerPlugin.check.js +1 -1
  169. package/schemas/plugins/BannerPlugin.json +5 -1
  170. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  171. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  172. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  173. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  174. package/types.d.ts +1668 -613
@@ -87,13 +87,18 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
87
87
  /** @typedef {import("estree").Super} Super */
88
88
  /** @typedef {import("estree").TaggedTemplateExpression} TaggedTemplateExpression */
89
89
  /** @typedef {import("estree").TemplateLiteral} TemplateLiteral */
90
- /** @typedef {Record<string, any>} Assertions */
91
- /** @template T @typedef {import("tapable").AsArray<T>} AsArray<T> */
90
+ /** @typedef {import("estree").AssignmentProperty} AssignmentProperty */
91
+ /** @typedef {Record<string, any>} Attributes */
92
+ /**
93
+ * @template T
94
+ * @typedef {import("tapable").AsArray<T>} AsArray<T>
95
+ */
92
96
  /** @typedef {import("../Parser").ParserState} ParserState */
93
97
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
94
98
  /** @typedef {{declaredScope: ScopeInfo, freeName: string | true, tagInfo: TagInfo | undefined}} VariableInfoInterface */
95
99
  /** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRanges: () => Range[] }} GetInfoResult */
96
100
  /** @typedef {Statement | ModuleDeclaration | Expression} StatementPathItem */
101
+ /** @typedef {TODO} OnIdent */
97
102
 
98
103
  /** @type {string[]} */
99
104
  const EMPTY_ARRAY = [];
@@ -257,7 +262,7 @@ class JavascriptParser extends Parser {
257
262
  evaluateCallExpression: new HookMap(
258
263
  () => new SyncBailHook(["expression"])
259
264
  ),
260
- /** @type {HookMap<SyncBailHook<[CallExpression, BasicEvaluatedExpression | undefined], BasicEvaluatedExpression | undefined | null>>} */
265
+ /** @type {HookMap<SyncBailHook<[CallExpression, BasicEvaluatedExpression], BasicEvaluatedExpression | undefined | null>>} */
261
266
  evaluateCallExpressionMember: new HookMap(
262
267
  () => new SyncBailHook(["expression", "param"])
263
268
  ),
@@ -298,15 +303,15 @@ class JavascriptParser extends Parser {
298
303
  "exportName",
299
304
  "identifierName"
300
305
  ]),
301
- /** @type {SyncBailHook<[ExportNamedDeclaration | ExportAllDeclaration], boolean | void>} */
306
+ /** @type {SyncBailHook<[ExportDefaultDeclaration | ExportNamedDeclaration], boolean | void>} */
302
307
  export: new SyncBailHook(["statement"]),
303
308
  /** @type {SyncBailHook<[ExportNamedDeclaration | ExportAllDeclaration, ImportSource], boolean | void>} */
304
309
  exportImport: new SyncBailHook(["statement", "source"]),
305
- /** @type {SyncBailHook<[ExportNamedDeclaration | ExportAllDeclaration, Declaration], boolean | void>} */
310
+ /** @type {SyncBailHook<[ExportDefaultDeclaration | ExportNamedDeclaration | ExportAllDeclaration, Declaration], boolean | void>} */
306
311
  exportDeclaration: new SyncBailHook(["statement", "declaration"]),
307
- /** @type {SyncBailHook<[ExportDefaultDeclaration, Declaration], boolean | void>} */
312
+ /** @type {SyncBailHook<[ExportDefaultDeclaration, FunctionDeclaration | ClassDeclaration], boolean | void>} */
308
313
  exportExpression: new SyncBailHook(["statement", "declaration"]),
309
- /** @type {SyncBailHook<[ExportNamedDeclaration | ExportAllDeclaration, string, string, number | undefined], boolean | void>} */
314
+ /** @type {SyncBailHook<[ExportDefaultDeclaration | ExportNamedDeclaration | ExportAllDeclaration, string, string, number | undefined], boolean | void>} */
310
315
  exportSpecifier: new SyncBailHook([
311
316
  "statement",
312
317
  "identifierName",
@@ -349,7 +354,7 @@ class JavascriptParser extends Parser {
349
354
  typeof: new HookMap(() => new SyncBailHook(["expression"])),
350
355
  /** @type {SyncBailHook<[ImportExpression], boolean | void>} */
351
356
  importCall: new SyncBailHook(["expression"]),
352
- /** @type {SyncBailHook<[Expression], boolean | void>} */
357
+ /** @type {SyncBailHook<[Expression | ForOfStatement], boolean | void>} */
353
358
  topLevelAwait: new SyncBailHook(["expression"]),
354
359
  /** @type {HookMap<SyncBailHook<[CallExpression], boolean | void>>} */
355
360
  call: new HookMap(() => new SyncBailHook(["expression"])),
@@ -880,7 +885,12 @@ class JavascriptParser extends Parser {
880
885
  /** @type {string} */ (left.string) +
881
886
  /** @type {string} */ (right.prefix.string)
882
887
  )
883
- .setRange(joinRanges(left.range, right.prefix.range)),
888
+ .setRange(
889
+ joinRanges(
890
+ /** @type {Range} */ (left.range),
891
+ /** @type {Range} */ (right.prefix.range)
892
+ )
893
+ ),
884
894
  right.postfix,
885
895
  right.wrappedInnerExpressions
886
896
  );
@@ -901,7 +911,10 @@ class JavascriptParser extends Parser {
901
911
  if (right.isString()) {
902
912
  res.setString(left.number + /** @type {string} */ (right.string));
903
913
  } else if (right.isNumber()) {
904
- res.setNumber(left.number + right.number);
914
+ res.setNumber(
915
+ /** @type {number} */ (left.number) +
916
+ /** @type {number} */ (right.number)
917
+ );
905
918
  } else {
906
919
  return;
907
920
  }
@@ -1328,7 +1341,7 @@ class JavascriptParser extends Parser {
1328
1341
  if (arg1.type === "SpreadElement") return;
1329
1342
  const arg1Eval = this.evaluateExpression(arg1);
1330
1343
  if (!arg1Eval.isString()) return;
1331
- const arg1Value = arg1Eval.string;
1344
+ const arg1Value = /** @type {string} */ (arg1Eval.string);
1332
1345
 
1333
1346
  let result;
1334
1347
  if (arg2) {
@@ -1357,9 +1370,11 @@ class JavascriptParser extends Parser {
1357
1370
  let arg1 = this.evaluateExpression(expr.arguments[0]);
1358
1371
  let arg2 = this.evaluateExpression(expr.arguments[1]);
1359
1372
  if (!arg1.isString() && !arg1.isRegExp()) return;
1360
- const arg1Value = arg1.regExp || arg1.string;
1373
+ const arg1Value = /** @type {string | RegExp} */ (
1374
+ arg1.regExp || arg1.string
1375
+ );
1361
1376
  if (!arg2.isString()) return;
1362
- const arg2Value = arg2.string;
1377
+ const arg2Value = /** @type {string} */ (arg2.string);
1363
1378
  return new BasicEvaluatedExpression()
1364
1379
  .setString(
1365
1380
  /** @type {string} */ (param.string).replace(arg1Value, arg2Value)
@@ -1380,7 +1395,9 @@ class JavascriptParser extends Parser {
1380
1395
  if (expr.arguments[0].type === "SpreadElement") return;
1381
1396
  arg1 = this.evaluateExpression(expr.arguments[0]);
1382
1397
  if (!arg1.isNumber()) return;
1383
- result = str[fn](arg1.number);
1398
+ result = str[
1399
+ /** @type {"substr" | "substring" | "slice"} */ (fn)
1400
+ ](/** @type {number} */ (arg1.number));
1384
1401
  break;
1385
1402
  case 2: {
1386
1403
  if (expr.arguments[0].type === "SpreadElement") return;
@@ -1389,7 +1406,12 @@ class JavascriptParser extends Parser {
1389
1406
  const arg2 = this.evaluateExpression(expr.arguments[1]);
1390
1407
  if (!arg1.isNumber()) return;
1391
1408
  if (!arg2.isNumber()) return;
1392
- result = str[fn](arg1.number, arg2.number);
1409
+ result = str[
1410
+ /** @type {"substr" | "substring" | "slice"} */ (fn)
1411
+ ](
1412
+ /** @type {number} */ (arg1.number),
1413
+ /** @type {number} */ (arg2.number)
1414
+ );
1393
1415
  break;
1394
1416
  }
1395
1417
  default:
@@ -1443,7 +1465,7 @@ class JavascriptParser extends Parser {
1443
1465
  }
1444
1466
 
1445
1467
  const part = new BasicEvaluatedExpression()
1446
- .setString(quasi)
1468
+ .setString(/** @type {string} */ (quasi))
1447
1469
  .setRange(/** @type {Range} */ (quasiExpr.range))
1448
1470
  .setExpression(quasiExpr);
1449
1471
  quasis.push(part);
@@ -1489,7 +1511,6 @@ class JavascriptParser extends Parser {
1489
1511
  .for("concat")
1490
1512
  .tap("JavascriptParser", (expr, param) => {
1491
1513
  if (!param.isString() && !param.isWrapped()) return;
1492
-
1493
1514
  let stringSuffix = null;
1494
1515
  let hasUnknownParams = false;
1495
1516
  const innerExpressions = [];
@@ -1569,7 +1590,9 @@ class JavascriptParser extends Parser {
1569
1590
  /** @type {string} */
1570
1591
  (param.string).split(/** @type {string} */ (arg.string));
1571
1592
  } else if (arg.isRegExp()) {
1572
- result = /** @type {string} */ (param.string).split(arg.regExp);
1593
+ result = /** @type {string} */ (param.string).split(
1594
+ /** @type {RegExp} */ (arg.regExp)
1595
+ );
1573
1596
  } else {
1574
1597
  return;
1575
1598
  }
@@ -1627,7 +1650,7 @@ class JavascriptParser extends Parser {
1627
1650
  });
1628
1651
  if (!items.every(Boolean)) return;
1629
1652
  return new BasicEvaluatedExpression()
1630
- .setItems(items)
1653
+ .setItems(/** @type {BasicEvaluatedExpression[]} */ (items))
1631
1654
  .setRange(/** @type {Range} */ (expr.range));
1632
1655
  });
1633
1656
  this.hooks.evaluate
@@ -2213,6 +2236,9 @@ class JavascriptParser extends Parser {
2213
2236
  });
2214
2237
  }
2215
2238
 
2239
+ /**
2240
+ * @param {ForOfStatement} statement statement
2241
+ */
2216
2242
  preWalkForOfStatement(statement) {
2217
2243
  if (statement.await && this.scope.topLevelScope === true) {
2218
2244
  this.hooks.topLevelAwait.call(statement);
@@ -2305,7 +2331,9 @@ class JavascriptParser extends Parser {
2305
2331
 
2306
2332
  // check multiple assignments
2307
2333
  if (this.destructuringAssignmentProperties.has(expression)) {
2308
- const set = this.destructuringAssignmentProperties.get(expression);
2334
+ const set =
2335
+ /** @type {Set<string>} */
2336
+ (this.destructuringAssignmentProperties.get(expression));
2309
2337
  this.destructuringAssignmentProperties.delete(expression);
2310
2338
  for (const id of set) keys.add(id);
2311
2339
  }
@@ -2322,8 +2350,11 @@ class JavascriptParser extends Parser {
2322
2350
  }
2323
2351
  }
2324
2352
 
2353
+ /**
2354
+ * @param {ImportDeclaration} statement statement
2355
+ */
2325
2356
  blockPreWalkImportDeclaration(statement) {
2326
- const source = statement.source.value;
2357
+ const source = /** @type {ImportSource} */ (statement.source.value);
2327
2358
  this.hooks.import.call(statement, source);
2328
2359
  for (const specifier of statement.specifiers) {
2329
2360
  const name = specifier.local.name;
@@ -2340,7 +2371,12 @@ class JavascriptParser extends Parser {
2340
2371
  !this.hooks.importSpecifier.call(
2341
2372
  statement,
2342
2373
  source,
2343
- specifier.imported.name || specifier.imported.value,
2374
+ specifier.imported.name ||
2375
+ // eslint-disable-next-line no-warning-comments
2376
+ // @ts-ignore
2377
+ // Old version of acorn used it
2378
+ // TODO drop it in webpack@6
2379
+ specifier.imported.value,
2344
2380
  name
2345
2381
  )
2346
2382
  ) {
@@ -2360,7 +2396,7 @@ class JavascriptParser extends Parser {
2360
2396
 
2361
2397
  /**
2362
2398
  * @param {Declaration} declaration declaration
2363
- * @param {TODO} onIdent on ident callback
2399
+ * @param {OnIdent} onIdent on ident callback
2364
2400
  */
2365
2401
  enterDeclaration(declaration, onIdent) {
2366
2402
  switch (declaration.type) {
@@ -2383,10 +2419,13 @@ class JavascriptParser extends Parser {
2383
2419
  }
2384
2420
  }
2385
2421
 
2422
+ /**
2423
+ * @param {ExportNamedDeclaration} statement statement
2424
+ */
2386
2425
  blockPreWalkExportNamedDeclaration(statement) {
2387
2426
  let source;
2388
2427
  if (statement.source) {
2389
- source = statement.source.value;
2428
+ source = /** @type {ImportSource} */ (statement.source.value);
2390
2429
  this.hooks.exportImport.call(statement, source);
2391
2430
  } else {
2392
2431
  this.hooks.export.call(statement);
@@ -2414,7 +2453,13 @@ class JavascriptParser extends Parser {
2414
2453
  const specifier = statement.specifiers[specifierIndex];
2415
2454
  switch (specifier.type) {
2416
2455
  case "ExportSpecifier": {
2417
- const name = specifier.exported.name || specifier.exported.value;
2456
+ const name =
2457
+ specifier.exported.name ||
2458
+ // eslint-disable-next-line no-warning-comments
2459
+ // @ts-ignore
2460
+ // Old version of acorn used it
2461
+ // TODO drop it in webpack@6
2462
+ specifier.exported.value;
2418
2463
  if (source) {
2419
2464
  this.hooks.exportImportSpecifier.call(
2420
2465
  statement,
@@ -2447,36 +2492,50 @@ class JavascriptParser extends Parser {
2447
2492
  }
2448
2493
  }
2449
2494
 
2495
+ /**
2496
+ * @param {TODO} statement statement
2497
+ */
2450
2498
  blockPreWalkExportDefaultDeclaration(statement) {
2451
2499
  const prev = this.prevStatement;
2452
2500
  this.preWalkStatement(statement.declaration);
2453
2501
  this.prevStatement = prev;
2454
2502
  this.blockPreWalkStatement(statement.declaration);
2455
2503
  if (
2456
- statement.declaration.id &&
2504
+ /** @type {FunctionDeclaration | ClassDeclaration} */ (
2505
+ statement.declaration
2506
+ ).id &&
2457
2507
  statement.declaration.type !== "FunctionExpression" &&
2458
2508
  statement.declaration.type !== "ClassExpression"
2459
2509
  ) {
2510
+ const declaration =
2511
+ /** @type {FunctionDeclaration | ClassDeclaration} */
2512
+ (statement.declaration);
2460
2513
  this.hooks.exportSpecifier.call(
2461
2514
  statement,
2462
- statement.declaration.id.name,
2515
+ declaration.id.name,
2463
2516
  "default",
2464
2517
  undefined
2465
2518
  );
2466
2519
  }
2467
2520
  }
2468
2521
 
2522
+ /**
2523
+ * @param {ExportDefaultDeclaration} statement statement
2524
+ */
2469
2525
  walkExportDefaultDeclaration(statement) {
2470
2526
  this.hooks.export.call(statement);
2471
2527
  if (
2472
- statement.declaration.id &&
2528
+ /** @type {FunctionDeclaration | ClassDeclaration} */ (
2529
+ statement.declaration
2530
+ ).id &&
2473
2531
  statement.declaration.type !== "FunctionExpression" &&
2474
2532
  statement.declaration.type !== "ClassExpression"
2475
2533
  ) {
2476
- if (
2477
- !this.hooks.exportDeclaration.call(statement, statement.declaration)
2478
- ) {
2479
- this.walkStatement(statement.declaration);
2534
+ const declaration =
2535
+ /** @type {FunctionDeclaration | ClassDeclaration} */
2536
+ (statement.declaration);
2537
+ if (!this.hooks.exportDeclaration.call(statement, declaration)) {
2538
+ this.walkStatement(declaration);
2480
2539
  }
2481
2540
  } else {
2482
2541
  // Acorn parses `export default function() {}` as `FunctionDeclaration` and
@@ -2486,14 +2545,23 @@ class JavascriptParser extends Parser {
2486
2545
  statement.declaration.type === "FunctionDeclaration" ||
2487
2546
  statement.declaration.type === "ClassDeclaration"
2488
2547
  ) {
2489
- this.walkStatement(statement.declaration);
2548
+ this.walkStatement(
2549
+ /** @type {FunctionDeclaration | ClassDeclaration} */
2550
+ (statement.declaration)
2551
+ );
2490
2552
  } else {
2491
2553
  this.walkExpression(statement.declaration);
2492
2554
  }
2493
- if (!this.hooks.exportExpression.call(statement, statement.declaration)) {
2555
+
2556
+ if (
2557
+ !this.hooks.exportExpression.call(
2558
+ statement,
2559
+ /** @type {TODO} */ (statement).declaration
2560
+ )
2561
+ ) {
2494
2562
  this.hooks.exportSpecifier.call(
2495
2563
  statement,
2496
- statement.declaration,
2564
+ /** @type {TODO} */ (statement.declaration),
2497
2565
  "default",
2498
2566
  undefined
2499
2567
  );
@@ -2501,8 +2569,11 @@ class JavascriptParser extends Parser {
2501
2569
  }
2502
2570
  }
2503
2571
 
2572
+ /**
2573
+ * @param {ExportAllDeclaration} statement statement
2574
+ */
2504
2575
  blockPreWalkExportAllDeclaration(statement) {
2505
- const source = statement.source.value;
2576
+ const source = /** @type {ImportSource} */ (statement.source.value);
2506
2577
  const name = statement.exported ? statement.exported.name : null;
2507
2578
  this.hooks.exportImport.call(statement, source);
2508
2579
  this.hooks.exportImportSpecifier.call(statement, source, null, name, 0);
@@ -2568,7 +2639,7 @@ class JavascriptParser extends Parser {
2568
2639
  if (key.type === "Identifier") {
2569
2640
  ids.add(key.name);
2570
2641
  } else {
2571
- const id = this.evaluateExpression(key);
2642
+ const id = this.evaluateExpression(/** @type {TODO} */ (key));
2572
2643
  const str = id.asString();
2573
2644
  if (str) {
2574
2645
  ids.add(str);
@@ -2764,10 +2835,16 @@ class JavascriptParser extends Parser {
2764
2835
  this.walkPattern(pattern.left);
2765
2836
  }
2766
2837
 
2838
+ /**
2839
+ * @param {ObjectPattern} pattern pattern
2840
+ */
2767
2841
  walkObjectPattern(pattern) {
2768
2842
  for (let i = 0, len = pattern.properties.length; i < len; i++) {
2769
2843
  const prop = pattern.properties[i];
2770
2844
  if (prop) {
2845
+ if (prop.type === "RestElement") {
2846
+ continue;
2847
+ }
2771
2848
  if (prop.computed) this.walkExpression(prop.key);
2772
2849
  if (prop.value) this.walkPattern(prop.value);
2773
2850
  }
@@ -3248,9 +3325,21 @@ class JavascriptParser extends Parser {
3248
3325
  }
3249
3326
  }
3250
3327
 
3328
+ /**
3329
+ * @private
3330
+ * @param {FunctionExpression | ArrowFunctionExpression} functionExpression function expression
3331
+ * @param {(Expression | SpreadElement)[]} options options
3332
+ * @param {Expression | SpreadElement | null} currentThis current this
3333
+ */
3251
3334
  _walkIIFE(functionExpression, options, currentThis) {
3335
+ /**
3336
+ * @param {Expression | SpreadElement} argOrThis arg or this
3337
+ * @returns {string | VariableInfoInterface | undefined} var info
3338
+ */
3252
3339
  const getVarInfo = argOrThis => {
3253
- const renameIdentifier = this.getRenameIdentifier(argOrThis);
3340
+ const renameIdentifier = this.getRenameIdentifier(
3341
+ /** @type {Expression} */ (argOrThis)
3342
+ );
3254
3343
  if (renameIdentifier) {
3255
3344
  if (
3256
3345
  this.callHooksForInfo(
@@ -3267,7 +3356,7 @@ class JavascriptParser extends Parser {
3267
3356
  )
3268
3357
  ) {
3269
3358
  return typeof renameIdentifier === "string"
3270
- ? this.getVariableInfo(renameIdentifier)
3359
+ ? /** @type {string} */ (this.getVariableInfo(renameIdentifier))
3271
3360
  : renameIdentifier;
3272
3361
  }
3273
3362
  }
@@ -3280,12 +3369,15 @@ class JavascriptParser extends Parser {
3280
3369
  const varInfoForArgs = options.map(getVarInfo);
3281
3370
  const wasTopLevel = this.scope.topLevelScope;
3282
3371
  this.scope.topLevelScope = wasTopLevel && arrow ? "arrow" : false;
3283
- const scopeParams = params.filter(
3284
- (identifier, idx) => !varInfoForArgs[idx]
3285
- );
3372
+ const scopeParams =
3373
+ /** @type {(Identifier | string)[]} */
3374
+ (params.filter((identifier, idx) => !varInfoForArgs[idx]));
3286
3375
 
3287
3376
  // Add function name in scope for recursive calls
3288
- if (functionExpression.id) {
3377
+ if (
3378
+ functionExpression.type === "FunctionExpression" &&
3379
+ functionExpression.id
3380
+ ) {
3289
3381
  scopeParams.push(functionExpression.id.name);
3290
3382
  }
3291
3383
 
@@ -3297,7 +3389,7 @@ class JavascriptParser extends Parser {
3297
3389
  const varInfo = varInfoForArgs[i];
3298
3390
  if (!varInfo) continue;
3299
3391
  if (!params[i] || params[i].type !== "Identifier") continue;
3300
- this.setVariable(params[i].name, varInfo);
3392
+ this.setVariable(/** @type {Identifier} */ (params[i]).name, varInfo);
3301
3393
  }
3302
3394
  if (functionExpression.body.type === "BlockStatement") {
3303
3395
  this.detectMode(functionExpression.body.body);
@@ -3322,6 +3414,9 @@ class JavascriptParser extends Parser {
3322
3414
  this.walkExpression(expression.source);
3323
3415
  }
3324
3416
 
3417
+ /**
3418
+ * @param {CallExpression} expression expression
3419
+ */
3325
3420
  walkCallExpression(expression) {
3326
3421
  const isSimpleFunction = fn => {
3327
3422
  return fn.params.every(p => p.type === "Identifier");
@@ -3330,14 +3425,20 @@ class JavascriptParser extends Parser {
3330
3425
  expression.callee.type === "MemberExpression" &&
3331
3426
  expression.callee.object.type.endsWith("FunctionExpression") &&
3332
3427
  !expression.callee.computed &&
3428
+ // eslint-disable-next-line no-warning-comments
3429
+ // @ts-ignore
3430
+ // TODO check me and handle more cases
3333
3431
  (expression.callee.property.name === "call" ||
3432
+ // eslint-disable-next-line no-warning-comments
3433
+ // @ts-ignore
3334
3434
  expression.callee.property.name === "bind") &&
3335
3435
  expression.arguments.length > 0 &&
3336
3436
  isSimpleFunction(expression.callee.object)
3337
3437
  ) {
3338
3438
  // (function(…) { }.call/bind(?, …))
3339
3439
  this._walkIIFE(
3340
- expression.callee.object,
3440
+ /** @type {FunctionExpression | ArrowFunctionExpression} */
3441
+ (expression.callee.object),
3341
3442
  expression.arguments.slice(1),
3342
3443
  expression.arguments[0]
3343
3444
  );
@@ -3346,7 +3447,12 @@ class JavascriptParser extends Parser {
3346
3447
  isSimpleFunction(expression.callee)
3347
3448
  ) {
3348
3449
  // (function(…) { }(…))
3349
- this._walkIIFE(expression.callee, expression.arguments, null);
3450
+ this._walkIIFE(
3451
+ /** @type {FunctionExpression | ArrowFunctionExpression} */
3452
+ (expression.callee),
3453
+ expression.arguments,
3454
+ null
3455
+ );
3350
3456
  } else {
3351
3457
  if (expression.callee.type === "MemberExpression") {
3352
3458
  const exprInfo = this.getMemberExpressionInfo(
@@ -3366,7 +3472,9 @@ class JavascriptParser extends Parser {
3366
3472
  if (result === true) return;
3367
3473
  }
3368
3474
  }
3369
- const callee = this.evaluateExpression(expression.callee);
3475
+ const callee = this.evaluateExpression(
3476
+ /** @type {TODO} */ (expression.callee)
3477
+ );
3370
3478
  if (callee.isIdentifier()) {
3371
3479
  const result1 = this.callHooksForInfo(
3372
3480
  this.hooks.callMemberChain,
@@ -3824,8 +3932,8 @@ class JavascriptParser extends Parser {
3824
3932
  }
3825
3933
 
3826
3934
  /**
3827
- * @param {(Pattern | Property)[]} patterns patterns
3828
- * @param {TODO} onIdent on ident callback
3935
+ * @param {(string | Pattern | Property)[]} patterns patterns
3936
+ * @param {OnIdent} onIdent on ident callback
3829
3937
  */
3830
3938
  enterPatterns(patterns, onIdent) {
3831
3939
  for (const pattern of patterns) {
@@ -3839,7 +3947,7 @@ class JavascriptParser extends Parser {
3839
3947
 
3840
3948
  /**
3841
3949
  * @param {Pattern | Property} pattern pattern
3842
- * @param {TODO} onIdent on ident callback
3950
+ * @param {OnIdent} onIdent on ident callback
3843
3951
  */
3844
3952
  enterPattern(pattern, onIdent) {
3845
3953
  if (!pattern) return;
@@ -3873,7 +3981,7 @@ class JavascriptParser extends Parser {
3873
3981
 
3874
3982
  /**
3875
3983
  * @param {Identifier} pattern identifier pattern
3876
- * @param {TODO} onIdent callback
3984
+ * @param {OnIdent} onIdent callback
3877
3985
  */
3878
3986
  enterIdentifier(pattern, onIdent) {
3879
3987
  if (!this.callHooksForName(this.hooks.pattern, pattern.name, pattern)) {
@@ -3883,7 +3991,7 @@ class JavascriptParser extends Parser {
3883
3991
 
3884
3992
  /**
3885
3993
  * @param {ObjectPattern} pattern object pattern
3886
- * @param {TODO} onIdent callback
3994
+ * @param {OnIdent} onIdent callback
3887
3995
  */
3888
3996
  enterObjectPattern(pattern, onIdent) {
3889
3997
  for (
@@ -3898,7 +4006,7 @@ class JavascriptParser extends Parser {
3898
4006
 
3899
4007
  /**
3900
4008
  * @param {ArrayPattern} pattern object pattern
3901
- * @param {TODO} onIdent callback
4009
+ * @param {OnIdent} onIdent callback
3902
4010
  */
3903
4011
  enterArrayPattern(pattern, onIdent) {
3904
4012
  for (
@@ -3916,7 +4024,7 @@ class JavascriptParser extends Parser {
3916
4024
 
3917
4025
  /**
3918
4026
  * @param {RestElement} pattern object pattern
3919
- * @param {TODO} onIdent callback
4027
+ * @param {OnIdent} onIdent callback
3920
4028
  */
3921
4029
  enterRestElement(pattern, onIdent) {
3922
4030
  this.enterPattern(pattern.argument, onIdent);
@@ -3924,7 +4032,7 @@ class JavascriptParser extends Parser {
3924
4032
 
3925
4033
  /**
3926
4034
  * @param {AssignmentPattern} pattern object pattern
3927
- * @param {TODO} onIdent callback
4035
+ * @param {OnIdent} onIdent callback
3928
4036
  */
3929
4037
  enterAssignmentPattern(pattern, onIdent) {
3930
4038
  this.enterPattern(pattern.left, onIdent);
@@ -3975,6 +4083,10 @@ class JavascriptParser extends Parser {
3975
4083
  );
3976
4084
  }
3977
4085
 
4086
+ /**
4087
+ * @param {Expression} expression expression
4088
+ * @returns {TODO} result
4089
+ */
3978
4090
  parseCalculatedString(expression) {
3979
4091
  switch (expression.type) {
3980
4092
  case "BinaryExpression":
@@ -4412,7 +4524,7 @@ class JavascriptParser extends Parser {
4412
4524
 
4413
4525
  /**
4414
4526
  * @param {string} name variable name
4415
- * @returns {ExportedVariableInfo} info for this variable
4527
+ * @returns {string | ExportedVariableInfo} info for this variable
4416
4528
  */
4417
4529
  getVariableInfo(name) {
4418
4530
  const value = this.scope.definitions.get(name);
@@ -4425,7 +4537,7 @@ class JavascriptParser extends Parser {
4425
4537
 
4426
4538
  /**
4427
4539
  * @param {string} name variable name
4428
- * @param {ExportedVariableInfo} variableInfo new info for this variable
4540
+ * @param {string | ExportedVariableInfo} variableInfo new info for this variable
4429
4541
  * @returns {void}
4430
4542
  */
4431
4543
  setVariable(name, variableInfo) {
@@ -18,7 +18,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
18
18
  /**
19
19
  * @param {JavascriptParser} parser the parser
20
20
  * @param {string} value the const value
21
- * @param {string[]=} runtimeRequirements runtime requirements
21
+ * @param {(string[] | null)=} runtimeRequirements runtime requirements
22
22
  * @returns {function(Expression): true} plugin function
23
23
  */
24
24
  exports.toConstantDependency = (parser, value, runtimeRequirements) => {
@@ -12,8 +12,10 @@ const { getAllChunks } = require("./ChunkHelpers");
12
12
 
13
13
  /** @typedef {import("../util/Hash")} Hash */
14
14
  /** @typedef {import("../Chunk")} Chunk */
15
+ /** @typedef {import("../Chunk").ChunkId} ChunkId */
15
16
  /** @typedef {import("../Compilation")} Compilation */
16
17
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
18
+ /** @typedef {import("../Entrypoint")} Entrypoint */
17
19
  /** @typedef {import("../ChunkGraph").EntryModuleWithChunkGroup} EntryModuleWithChunkGroup */
18
20
  /** @typedef {import("../ChunkGroup")} ChunkGroup */
19
21
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
@@ -73,9 +75,15 @@ exports.generateEntryStartup = (
73
75
  let currentModuleIds = undefined;
74
76
 
75
77
  for (const [module, entrypoint] of entries) {
76
- const runtimeChunk = entrypoint.getRuntimeChunk();
78
+ const runtimeChunk =
79
+ /** @type {Entrypoint} */
80
+ (entrypoint).getRuntimeChunk();
77
81
  const moduleId = chunkGraph.getModuleId(module);
78
- const chunks = getAllChunks(entrypoint, chunk, runtimeChunk);
82
+ const chunks = getAllChunks(
83
+ /** @type {Entrypoint} */ (entrypoint),
84
+ chunk,
85
+ runtimeChunk
86
+ );
79
87
  if (
80
88
  currentChunks &&
81
89
  currentChunks.size === chunks.size &&
@@ -108,11 +116,18 @@ exports.generateEntryStartup = (
108
116
  */
109
117
  exports.updateHashForEntryStartup = (hash, chunkGraph, entries, chunk) => {
110
118
  for (const [module, entrypoint] of entries) {
111
- const runtimeChunk = entrypoint.getRuntimeChunk();
119
+ const runtimeChunk =
120
+ /** @type {Entrypoint} */
121
+ (entrypoint).getRuntimeChunk();
112
122
  const moduleId = chunkGraph.getModuleId(module);
113
123
  hash.update(`${moduleId}`);
114
- for (const c of getAllChunks(entrypoint, chunk, runtimeChunk))
124
+ for (const c of getAllChunks(
125
+ /** @type {Entrypoint} */ (entrypoint),
126
+ chunk,
127
+ /** @type {Chunk} */ (runtimeChunk)
128
+ )) {
115
129
  hash.update(`${c.id}`);
130
+ }
116
131
  }
117
132
  };
118
133
 
@@ -126,7 +141,9 @@ exports.getInitialChunkIds = (chunk, chunkGraph, filterFn) => {
126
141
  const initialChunkIds = new Set(chunk.ids);
127
142
  for (const c of chunk.getAllInitialChunks()) {
128
143
  if (c === chunk || filterFn(c, chunkGraph)) continue;
129
- for (const id of c.ids) initialChunkIds.add(id);
144
+ for (const id of /** @type {ChunkId[]} */ (c.ids)) {
145
+ initialChunkIds.add(id);
146
+ }
130
147
  }
131
148
  return initialChunkIds;
132
149
  };