webpack 5.91.0 → 5.92.1

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/bin/webpack.js +1 -2
  2. package/lib/APIPlugin.js +6 -2
  3. package/lib/Cache.js +1 -1
  4. package/lib/Chunk.js +7 -4
  5. package/lib/ChunkGraph.js +20 -7
  6. package/lib/ChunkGroup.js +9 -3
  7. package/lib/CleanPlugin.js +1 -1
  8. package/lib/Compilation.js +33 -27
  9. package/lib/Compiler.js +28 -8
  10. package/lib/ConcatenationScope.js +3 -3
  11. package/lib/ContextModule.js +95 -43
  12. package/lib/DefinePlugin.js +14 -4
  13. package/lib/Dependency.js +8 -8
  14. package/lib/DependencyTemplate.js +10 -5
  15. package/lib/DllReferencePlugin.js +1 -1
  16. package/lib/EvalDevToolModulePlugin.js +11 -0
  17. package/lib/ExportsInfo.js +22 -4
  18. package/lib/ExternalModule.js +49 -18
  19. package/lib/FileSystemInfo.js +68 -41
  20. package/lib/FlagDependencyExportsPlugin.js +21 -7
  21. package/lib/Generator.js +2 -3
  22. package/lib/HotModuleReplacementPlugin.js +108 -45
  23. package/lib/IgnorePlugin.js +4 -1
  24. package/lib/LibManifestPlugin.js +2 -2
  25. package/lib/Module.js +11 -12
  26. package/lib/ModuleFactory.js +3 -3
  27. package/lib/ModuleFilenameHelpers.js +29 -16
  28. package/lib/ModuleGraph.js +5 -5
  29. package/lib/MultiCompiler.js +36 -1
  30. package/lib/NormalModule.js +10 -12
  31. package/lib/NormalModuleFactory.js +17 -8
  32. package/lib/Parser.js +1 -1
  33. package/lib/PlatformPlugin.js +39 -0
  34. package/lib/ProgressPlugin.js +1 -1
  35. package/lib/RecordIdsPlugin.js +4 -4
  36. package/lib/ResolverFactory.js +3 -3
  37. package/lib/RuntimeTemplate.js +22 -18
  38. package/lib/Stats.js +1 -1
  39. package/lib/Template.js +5 -5
  40. package/lib/TemplatedPathPlugin.js +16 -1
  41. package/lib/asset/AssetGenerator.js +15 -0
  42. package/lib/buildChunkGraph.js +3 -3
  43. package/lib/cache/MemoryWithGcCachePlugin.js +1 -1
  44. package/lib/cache/PackFileCacheStrategy.js +2 -2
  45. package/lib/cache/ResolverCachePlugin.js +8 -8
  46. package/lib/cache/getLazyHashedEtag.js +1 -1
  47. package/lib/cli.js +5 -5
  48. package/lib/config/browserslistTargetHandler.js +7 -1
  49. package/lib/config/defaults.js +85 -34
  50. package/lib/config/target.js +18 -11
  51. package/lib/container/ContainerEntryModule.js +1 -1
  52. package/lib/css/CssExportsGenerator.js +43 -17
  53. package/lib/css/CssGenerator.js +22 -12
  54. package/lib/css/CssLoadingRuntimeModule.js +8 -5
  55. package/lib/css/CssModulesPlugin.js +197 -100
  56. package/lib/css/CssParser.js +24 -15
  57. package/lib/css/walkCssTokens.js +1 -1
  58. package/lib/debug/ProfilingPlugin.js +1 -1
  59. package/lib/dependencies/ContextElementDependency.js +2 -2
  60. package/lib/dependencies/CssExportDependency.js +2 -2
  61. package/lib/dependencies/CssLocalIdentifierDependency.js +9 -2
  62. package/lib/dependencies/CssUrlDependency.js +5 -4
  63. package/lib/dependencies/ExportsInfoDependency.js +1 -1
  64. package/lib/dependencies/ExternalModuleDependency.js +4 -2
  65. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +2 -2
  66. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -2
  67. package/lib/dependencies/HarmonyImportDependency.js +2 -2
  68. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +41 -18
  69. package/lib/dependencies/HarmonyImportSideEffectDependency.js +2 -2
  70. package/lib/dependencies/HarmonyImportSpecifierDependency.js +43 -32
  71. package/lib/dependencies/ImportDependency.js +2 -2
  72. package/lib/dependencies/ImportEagerDependency.js +2 -2
  73. package/lib/dependencies/ImportMetaPlugin.js +1 -1
  74. package/lib/dependencies/ImportParserPlugin.js +3 -1
  75. package/lib/dependencies/ImportWeakDependency.js +2 -2
  76. package/lib/dependencies/LoaderPlugin.js +2 -2
  77. package/lib/dependencies/ModuleDependency.js +2 -2
  78. package/lib/dependencies/PureExpressionDependency.js +63 -49
  79. package/lib/dependencies/WorkerDependency.js +1 -1
  80. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +90 -2
  81. package/lib/hmr/LazyCompilationPlugin.js +2 -2
  82. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
  83. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  84. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  85. package/lib/ids/IdHelpers.js +6 -6
  86. package/lib/ids/NamedChunkIdsPlugin.js +1 -1
  87. package/lib/ids/NamedModuleIdsPlugin.js +1 -1
  88. package/lib/ids/SyncModuleIdsPlugin.js +2 -2
  89. package/lib/index.js +11 -0
  90. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  91. package/lib/javascript/JavascriptGenerator.js +0 -1
  92. package/lib/javascript/JavascriptModulesPlugin.js +174 -17
  93. package/lib/javascript/JavascriptParser.js +37 -16
  94. package/lib/library/AbstractLibraryPlugin.js +2 -2
  95. package/lib/library/AmdLibraryPlugin.js +2 -2
  96. package/lib/library/AssignLibraryPlugin.js +3 -3
  97. package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
  98. package/lib/library/JsonpLibraryPlugin.js +2 -2
  99. package/lib/library/ModuleLibraryPlugin.js +2 -2
  100. package/lib/library/SystemLibraryPlugin.js +2 -2
  101. package/lib/library/UmdLibraryPlugin.js +33 -12
  102. package/lib/logging/createConsoleLogger.js +2 -2
  103. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
  104. package/lib/node/NodeEnvironmentPlugin.js +1 -1
  105. package/lib/node/NodeTemplatePlugin.js +1 -1
  106. package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
  107. package/lib/node/nodeConsole.js +1 -1
  108. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  109. package/lib/optimize/ConcatenatedModule.js +11 -76
  110. package/lib/optimize/InnerGraph.js +1 -1
  111. package/lib/optimize/LimitChunkCountPlugin.js +1 -2
  112. package/lib/optimize/ModuleConcatenationPlugin.js +1 -1
  113. package/lib/optimize/RealContentHashPlugin.js +3 -3
  114. package/lib/optimize/SideEffectsFlagPlugin.js +2 -2
  115. package/lib/optimize/SplitChunksPlugin.js +8 -8
  116. package/lib/performance/SizeLimitsPlugin.js +2 -2
  117. package/lib/rules/ObjectMatcherRulePlugin.js +11 -1
  118. package/lib/rules/RuleSetCompiler.js +9 -7
  119. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  120. package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
  121. package/lib/schemes/HttpUriPlugin.js +1 -1
  122. package/lib/serialization/BinaryMiddleware.js +4 -4
  123. package/lib/serialization/FileMiddleware.js +3 -3
  124. package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
  125. package/lib/serialization/ObjectMiddleware.js +6 -5
  126. package/lib/serialization/PlainObjectSerializer.js +2 -2
  127. package/lib/serialization/SerializerMiddleware.js +2 -2
  128. package/lib/serialization/SingleItemMiddleware.js +2 -2
  129. package/lib/serialization/types.js +1 -1
  130. package/lib/sharing/ConsumeSharedModule.js +1 -1
  131. package/lib/sharing/ProvideSharedPlugin.js +1 -1
  132. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  133. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
  134. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  135. package/lib/stats/StatsFactory.js +2 -2
  136. package/lib/stats/StatsPrinter.js +6 -6
  137. package/lib/util/ArrayQueue.js +14 -21
  138. package/lib/util/AsyncQueue.js +1 -1
  139. package/lib/util/Queue.js +8 -2
  140. package/lib/util/SortableSet.js +16 -4
  141. package/lib/util/TupleQueue.js +8 -2
  142. package/lib/util/WeakTupleMap.js +3 -3
  143. package/lib/util/binarySearchBounds.js +1 -1
  144. package/lib/util/cleverMerge.js +2 -2
  145. package/lib/util/comparators.js +4 -2
  146. package/lib/util/conventions.js +1 -1
  147. package/lib/util/createHash.js +3 -5
  148. package/lib/util/deprecation.js +3 -3
  149. package/lib/util/deterministicGrouping.js +2 -2
  150. package/lib/util/findGraphRoots.js +1 -1
  151. package/lib/util/fs.js +15 -15
  152. package/lib/util/identifier.js +5 -5
  153. package/lib/util/mergeScope.js +79 -0
  154. package/lib/util/runtime.js +2 -17
  155. package/lib/util/semver.js +3 -0
  156. package/lib/util/smartGrouping.js +3 -3
  157. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
  158. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  159. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  160. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +1 -1
  161. package/lib/wasm-sync/WebAssemblyGenerator.js +17 -17
  162. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  163. package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
  164. package/lib/web/FetchCompileWasmPlugin.js +1 -1
  165. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
  166. package/lib/webpack.js +12 -3
  167. package/package.json +20 -18
  168. package/schemas/WebpackOptions.check.js +1 -1
  169. package/schemas/WebpackOptions.json +30 -2
  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 +213 -81
@@ -6,7 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const { Parser: AcornParser } = require("acorn");
9
- const { importAssertions } = require("acorn-import-assertions");
9
+ const { importAttributesOrAssertions } = require("acorn-import-attributes");
10
10
  const { SyncBailHook, HookMap } = require("tapable");
11
11
  const vm = require("vm");
12
12
  const Parser = require("../Parser");
@@ -88,7 +88,6 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
88
88
  /** @typedef {import("estree").TaggedTemplateExpression} TaggedTemplateExpression */
89
89
  /** @typedef {import("estree").TemplateLiteral} TemplateLiteral */
90
90
  /** @typedef {import("estree").AssignmentProperty} AssignmentProperty */
91
- /** @typedef {Record<string, any>} Attributes */
92
91
  /**
93
92
  * @template T
94
93
  * @typedef {import("tapable").AsArray<T>} AsArray<T>
@@ -100,6 +99,8 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
100
99
  /** @typedef {Statement | ModuleDeclaration | Expression} StatementPathItem */
101
100
  /** @typedef {TODO} OnIdent */
102
101
 
102
+ /** @typedef {Record<string, string> & { _isLegacyAssert?: boolean }} ImportAttributes */
103
+
103
104
  /** @type {string[]} */
104
105
  const EMPTY_ARRAY = [];
105
106
  const ALLOWED_MEMBER_TYPES_CALL_EXPRESSION = 0b01;
@@ -108,7 +109,7 @@ const ALLOWED_MEMBER_TYPES_ALL = 0b11;
108
109
 
109
110
  // Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API
110
111
 
111
- const parser = AcornParser.extend(importAssertions);
112
+ const parser = AcornParser.extend(importAttributesOrAssertions);
112
113
 
113
114
  class VariableInfo {
114
115
  /**
@@ -128,14 +129,14 @@ class VariableInfo {
128
129
  /** @typedef {Omit<AcornOptions, "sourceType" | "ecmaVersion"> & { sourceType: "module" | "script" | "auto", ecmaVersion?: AcornOptions["ecmaVersion"] }} ParseOptions */
129
130
 
130
131
  /**
131
- * @typedef {Object} TagInfo
132
+ * @typedef {object} TagInfo
132
133
  * @property {any} tag
133
134
  * @property {any} data
134
135
  * @property {TagInfo | undefined} next
135
136
  */
136
137
 
137
138
  /**
138
- * @typedef {Object} ScopeInfo
139
+ * @typedef {object} ScopeInfo
139
140
  * @property {StackedMap<string, VariableInfo | ScopeInfo>} definitions
140
141
  * @property {boolean | "arrow"} topLevelScope
141
142
  * @property {boolean | string} inShorthand
@@ -147,6 +148,13 @@ class VariableInfo {
147
148
 
148
149
  /** @typedef {[number, number]} Range */
149
150
 
151
+ /**
152
+ * @typedef {object} DestructuringAssignmentProperty
153
+ * @property {string} id
154
+ * @property {Range | undefined=} range
155
+ * @property {boolean | string} shorthand
156
+ */
157
+
150
158
  /**
151
159
  * Helper function for joining two ranges into a single range. This is useful
152
160
  * when working with AST nodes, as it allows you to combine the ranges of child nodes
@@ -437,7 +445,7 @@ class JavascriptParser extends Parser {
437
445
  this.statementPath = undefined;
438
446
  /** @type {Statement | ModuleDeclaration | Expression | undefined} */
439
447
  this.prevStatement = undefined;
440
- /** @type {WeakMap<Expression, Set<string>> | undefined} */
448
+ /** @type {WeakMap<Expression, Set<DestructuringAssignmentProperty>> | undefined} */
441
449
  this.destructuringAssignmentProperties = undefined;
442
450
  this.currentTagData = undefined;
443
451
  this.magicCommentContext = vm.createContext(undefined, {
@@ -605,7 +613,7 @@ class JavascriptParser extends Parser {
605
613
  *
606
614
  * import("./" + foo + bar); // webpack will auto evaluate this into import("./foobar")
607
615
  * ```
608
- * @param {boolean | number | BigInt | string} value the value to convert to an expression
616
+ * @param {boolean | number | bigint | string} value the value to convert to an expression
609
617
  * @param {BinaryExpression | UnaryExpression} expr the expression being evaluated
610
618
  * @param {boolean} sideEffects whether the expression has side effects
611
619
  * @returns {BasicEvaluatedExpression | undefined} the evaluated expression
@@ -663,7 +671,7 @@ class JavascriptParser extends Parser {
663
671
  * Evaluates a binary expression if and only if it is a const operation (e.g. 1 + 2, "a" + "b", etc.).
664
672
  *
665
673
  * @template T
666
- * @param {(leftOperand: T, rightOperand: T) => boolean | number | BigInt | string} operandHandler the handler for the operation (e.g. (a, b) => a + b)
674
+ * @param {(leftOperand: T, rightOperand: T) => boolean | number | bigint | string} operandHandler the handler for the operation (e.g. (a, b) => a + b)
667
675
  * @returns {BasicEvaluatedExpression | undefined} the evaluated expression
668
676
  */
669
677
  const handleConstOperation = operandHandler => {
@@ -1076,7 +1084,7 @@ class JavascriptParser extends Parser {
1076
1084
  * Evaluates a UnaryExpression if and only if it is a basic const operator (e.g. +a, -a, ~a).
1077
1085
  *
1078
1086
  * @template T
1079
- * @param {(operand: T) => boolean | number | BigInt | string} operandHandler handler for the operand
1087
+ * @param {(operand: T) => boolean | number | bigint | string} operandHandler handler for the operand
1080
1088
  * @returns {BasicEvaluatedExpression | undefined} evaluated expression
1081
1089
  */
1082
1090
  const handleConstOperation = operandHandler => {
@@ -1701,7 +1709,7 @@ class JavascriptParser extends Parser {
1701
1709
 
1702
1710
  /**
1703
1711
  * @param {Expression} node node
1704
- * @returns {Set<string>|undefined} destructured identifiers
1712
+ * @returns {Set<DestructuringAssignmentProperty> | undefined} destructured identifiers
1705
1713
  */
1706
1714
  destructuringAssignmentPropertiesFor(node) {
1707
1715
  if (!this.destructuringAssignmentProperties) return undefined;
@@ -2332,7 +2340,7 @@ class JavascriptParser extends Parser {
2332
2340
  // check multiple assignments
2333
2341
  if (this.destructuringAssignmentProperties.has(expression)) {
2334
2342
  const set =
2335
- /** @type {Set<string>} */
2343
+ /** @type {Set<DestructuringAssignmentProperty>} */
2336
2344
  (this.destructuringAssignmentProperties.get(expression));
2337
2345
  this.destructuringAssignmentProperties.delete(expression);
2338
2346
  for (const id of set) keys.add(id);
@@ -2627,30 +2635,43 @@ class JavascriptParser extends Parser {
2627
2635
 
2628
2636
  /**
2629
2637
  * @param {ObjectPattern} objectPattern object pattern
2630
- * @returns {Set<string> | undefined} set of names or undefined if not all keys are identifiers
2638
+ * @returns {Set<DestructuringAssignmentProperty> | undefined} set of names or undefined if not all keys are identifiers
2631
2639
  */
2632
2640
  _preWalkObjectPattern(objectPattern) {
2633
- const ids = new Set();
2641
+ /** @type {Set<DestructuringAssignmentProperty>} */
2642
+ const props = new Set();
2634
2643
  const properties = objectPattern.properties;
2635
2644
  for (let i = 0; i < properties.length; i++) {
2636
2645
  const property = properties[i];
2637
2646
  if (property.type !== "Property") return;
2647
+ if (property.shorthand && property.value.type === "Identifier") {
2648
+ this.scope.inShorthand = property.value.name;
2649
+ }
2638
2650
  const key = property.key;
2639
2651
  if (key.type === "Identifier") {
2640
- ids.add(key.name);
2652
+ props.add({
2653
+ id: key.name,
2654
+ range: key.range,
2655
+ shorthand: this.scope.inShorthand
2656
+ });
2641
2657
  } else {
2642
2658
  const id = this.evaluateExpression(/** @type {TODO} */ (key));
2643
2659
  const str = id.asString();
2644
2660
  if (str) {
2645
- ids.add(str);
2661
+ props.add({
2662
+ id: str,
2663
+ range: key.range,
2664
+ shorthand: this.scope.inShorthand
2665
+ });
2646
2666
  } else {
2647
2667
  // could not evaluate key
2648
2668
  return;
2649
2669
  }
2650
2670
  }
2671
+ this.scope.inShorthand = false;
2651
2672
  }
2652
2673
 
2653
- return ids;
2674
+ return props;
2654
2675
  }
2655
2676
 
2656
2677
  /**
@@ -26,7 +26,7 @@ const COMMON_LIBRARY_NAME_MESSAGE =
26
26
 
27
27
  /**
28
28
  * @template T
29
- * @typedef {Object} LibraryContext
29
+ * @typedef {object} LibraryContext
30
30
  * @property {Compilation} compilation
31
31
  * @property {ChunkGraph} chunkGraph
32
32
  * @property {T} options
@@ -37,7 +37,7 @@ const COMMON_LIBRARY_NAME_MESSAGE =
37
37
  */
38
38
  class AbstractLibraryPlugin {
39
39
  /**
40
- * @param {Object} options options
40
+ * @param {object} options options
41
41
  * @param {string} options.pluginName name of the plugin
42
42
  * @param {LibraryType} options.type used library type
43
43
  */
@@ -21,13 +21,13 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
21
21
  /** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
22
22
 
23
23
  /**
24
- * @typedef {Object} AmdLibraryPluginOptions
24
+ * @typedef {object} AmdLibraryPluginOptions
25
25
  * @property {LibraryType} type
26
26
  * @property {boolean=} requireAsWrapper
27
27
  */
28
28
 
29
29
  /**
30
- * @typedef {Object} AmdLibraryPluginParsed
30
+ * @typedef {object} AmdLibraryPluginParsed
31
31
  * @property {string} name
32
32
  * @property {string} amdContainer
33
33
  */
@@ -91,7 +91,7 @@ const accessWithInit = (accessor, existingLength, initLast = false) => {
91
91
  };
92
92
 
93
93
  /**
94
- * @typedef {Object} AssignLibraryPluginOptions
94
+ * @typedef {object} AssignLibraryPluginOptions
95
95
  * @property {LibraryType} type
96
96
  * @property {string[] | "global"} prefix name prefix
97
97
  * @property {string | false} declare declare name as variable
@@ -100,7 +100,7 @@ const accessWithInit = (accessor, existingLength, initLast = false) => {
100
100
  */
101
101
 
102
102
  /**
103
- * @typedef {Object} AssignLibraryPluginParsed
103
+ * @typedef {object} AssignLibraryPluginParsed
104
104
  * @property {string | string[]} name
105
105
  * @property {string | string[] | undefined} export
106
106
  */
@@ -323,7 +323,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
323
323
  true
324
324
  )};\n`
325
325
  );
326
- /** @type {String} */
326
+ /** @type {string} */
327
327
  let exports = RuntimeGlobals.exports;
328
328
  if (exportAccess) {
329
329
  result.add(
@@ -22,12 +22,12 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
22
22
  /** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
23
23
 
24
24
  /**
25
- * @typedef {Object} ExportPropertyLibraryPluginParsed
25
+ * @typedef {object} ExportPropertyLibraryPluginParsed
26
26
  * @property {string | string[]} export
27
27
  */
28
28
 
29
29
  /**
30
- * @typedef {Object} ExportPropertyLibraryPluginOptions
30
+ * @typedef {object} ExportPropertyLibraryPluginOptions
31
31
  * @property {LibraryType} type
32
32
  * @property {boolean} nsObjectUsed the namespace object is used
33
33
  */
@@ -19,12 +19,12 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
19
19
  /** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
20
20
 
21
21
  /**
22
- * @typedef {Object} JsonpLibraryPluginOptions
22
+ * @typedef {object} JsonpLibraryPluginOptions
23
23
  * @property {LibraryType} type
24
24
  */
25
25
 
26
26
  /**
27
- * @typedef {Object} JsonpLibraryPluginParsed
27
+ * @typedef {object} JsonpLibraryPluginParsed
28
28
  * @property {string} name
29
29
  */
30
30
 
@@ -23,12 +23,12 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
23
23
  /** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
24
24
 
25
25
  /**
26
- * @typedef {Object} ModuleLibraryPluginOptions
26
+ * @typedef {object} ModuleLibraryPluginOptions
27
27
  * @property {LibraryType} type
28
28
  */
29
29
 
30
30
  /**
31
- * @typedef {Object} ModuleLibraryPluginParsed
31
+ * @typedef {object} ModuleLibraryPluginParsed
32
32
  * @property {string} name
33
33
  */
34
34
 
@@ -23,12 +23,12 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
23
23
  /** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
24
24
 
25
25
  /**
26
- * @typedef {Object} SystemLibraryPluginOptions
26
+ * @typedef {object} SystemLibraryPluginOptions
27
27
  * @property {LibraryType} type
28
28
  */
29
29
 
30
30
  /**
31
- * @typedef {Object} SystemLibraryPluginParsed
31
+ * @typedef {object} SystemLibraryPluginParsed
32
32
  * @property {string} name
33
33
  */
34
34
 
@@ -18,8 +18,13 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
18
18
  /** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
19
19
  /** @typedef {import("../Compiler")} Compiler */
20
20
  /** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
21
+ /** @typedef {import("../ExternalModule").RequestRecord} RequestRecord */
21
22
  /** @typedef {import("../util/Hash")} Hash */
22
- /** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
23
+ /**
24
+ * @template T
25
+ * @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>}
26
+ * LibraryContext<T>
27
+ */
23
28
 
24
29
  /**
25
30
  * @param {string[]} accessor the accessor to convert to path
@@ -53,13 +58,13 @@ const accessorAccess = (base, accessor, joinWith = ", ") => {
53
58
  /** @typedef {string | string[] | LibraryCustomUmdObject} UmdLibraryPluginName */
54
59
 
55
60
  /**
56
- * @typedef {Object} UmdLibraryPluginOptions
61
+ * @typedef {object} UmdLibraryPluginOptions
57
62
  * @property {LibraryType} type
58
63
  * @property {boolean=} optionalAmdExternalAsGlobal
59
64
  */
60
65
 
61
66
  /**
62
- * @typedef {Object} UmdLibraryPluginParsed
67
+ * @typedef {object} UmdLibraryPluginParsed
63
68
  * @property {string | string[]} name
64
69
  * @property {LibraryCustomUmdObject} names
65
70
  * @property {string | LibraryCustomUmdCommentObject} auxiliaryComment
@@ -158,24 +163,38 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
158
163
  });
159
164
  };
160
165
 
166
+ /**
167
+ * @param {ExternalModule[]} modules external modules
168
+ * @returns {string} result
169
+ */
161
170
  const externalsDepsArray = modules => {
162
171
  return `[${replaceKeys(
163
172
  modules
164
173
  .map(m =>
165
174
  JSON.stringify(
166
- typeof m.request === "object" ? m.request.amd : m.request
175
+ typeof m.request === "object"
176
+ ? /** @type {RequestRecord} */
177
+ (m.request).amd
178
+ : m.request
167
179
  )
168
180
  )
169
181
  .join(", ")
170
182
  )}]`;
171
183
  };
172
184
 
185
+ /**
186
+ * @param {ExternalModule[]} modules external modules
187
+ * @returns {string} result
188
+ */
173
189
  const externalsRootArray = modules => {
174
190
  return replaceKeys(
175
191
  modules
176
192
  .map(m => {
177
193
  let request = m.request;
178
- if (typeof request === "object") request = request.root;
194
+ if (typeof request === "object")
195
+ request =
196
+ /** @type {RequestRecord} */
197
+ (request).root;
179
198
  return `root${accessorToObjectAccess([].concat(request))}`;
180
199
  })
181
200
  .join(", ")
@@ -194,7 +213,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
194
213
  let request = m.request;
195
214
  if (typeof request === "object") {
196
215
  request =
197
- /** @type {Record<string, string | string[]>} */
216
+ /** @type {RequestRecord} */
198
217
  (request)[type];
199
218
  }
200
219
  if (request === undefined) {
@@ -233,8 +252,14 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
233
252
  .join(", ");
234
253
  };
235
254
 
255
+ /**
256
+ * @param {string| string[]} library library name
257
+ * @returns {string} stringified library name
258
+ */
236
259
  const libraryName = library => {
237
- return JSON.stringify(replaceKeys([].concat(library).pop()));
260
+ return JSON.stringify(
261
+ replaceKeys(/** @type {string[]} */ ([]).concat(library).pop())
262
+ );
238
263
  };
239
264
 
240
265
  let amdFactory;
@@ -313,11 +338,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
313
338
  " else\n" +
314
339
  " " +
315
340
  replaceKeys(
316
- accessorAccess(
317
- "root",
318
- /** @type {string | string[]} */ (names.root) ||
319
- /** @type {string} */ (names.commonjs)
320
- )
341
+ accessorAccess("root", names.root || names.commonjs)
321
342
  ) +
322
343
  " = factory(" +
323
344
  externalsRootArray(externals) +
@@ -15,7 +15,7 @@ const { LogType } = require("./Logger");
15
15
  /** @typedef {function(string, LogTypeEnum, any[]): void} LoggingFunction */
16
16
 
17
17
  /**
18
- * @typedef {Object} LoggerConsole
18
+ * @typedef {object} LoggerConsole
19
19
  * @property {function(): void} clear
20
20
  * @property {function(): void} trace
21
21
  * @property {(...args: any[]) => void} info
@@ -33,7 +33,7 @@ const { LogType } = require("./Logger");
33
33
  */
34
34
 
35
35
  /**
36
- * @typedef {Object} LoggerOptions
36
+ * @typedef {object} LoggerOptions
37
37
  * @property {false|true|"none"|"error"|"warn"|"info"|"log"|"verbose"} level loglevel
38
38
  * @property {FilterTypes|boolean} debug filter for debug logging
39
39
  * @property {LoggerConsole} console the console to log to
@@ -11,7 +11,8 @@ const StartupChunkDependenciesPlugin = require("../runtime/StartupChunkDependenc
11
11
  /** @typedef {import("../Chunk")} Chunk */
12
12
  /** @typedef {import("../Compiler")} Compiler */
13
13
 
14
- /** @typedef {Object} CommonJsChunkLoadingPluginOptions
14
+ /**
15
+ * @typedef {object} CommonJsChunkLoadingPluginOptions
15
16
  * @property {boolean} [asyncChunkLoading] enable async chunk loading
16
17
  */
17
18
 
@@ -17,7 +17,7 @@ const nodeConsole = require("./nodeConsole");
17
17
 
18
18
  class NodeEnvironmentPlugin {
19
19
  /**
20
- * @param {Object} options options
20
+ * @param {object} options options
21
21
  * @param {InfrastructureLogging} options.infrastructureLogging infrastructure logging options
22
22
  */
23
23
  constructor(options) {
@@ -11,7 +11,7 @@ const EnableChunkLoadingPlugin = require("../javascript/EnableChunkLoadingPlugin
11
11
  /** @typedef {import("../Compiler")} Compiler */
12
12
 
13
13
  /**
14
- * @typedef {Object} NodeTemplatePluginOptions
14
+ * @typedef {object} NodeTemplatePluginOptions
15
15
  * @property {boolean} [asyncChunkLoading] enable async chunk loading
16
16
  */
17
17
 
@@ -14,7 +14,7 @@ const WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRunt
14
14
  /** @typedef {import("../Compiler")} Compiler */
15
15
 
16
16
  /**
17
- * @typedef {Object} ReadFileCompileWasmPluginOptions
17
+ * @typedef {object} ReadFileCompileWasmPluginOptions
18
18
  * @property {boolean} [mangleImports] mangle imports
19
19
  */
20
20
 
@@ -11,7 +11,7 @@ const truncateArgs = require("../logging/truncateArgs");
11
11
  /** @typedef {import("../logging/createConsoleLogger").LoggerConsole} LoggerConsole */
12
12
 
13
13
  /**
14
- * @param {Object} options options
14
+ * @param {object} options options
15
15
  * @param {boolean=} options.colors colors
16
16
  * @param {boolean=} options.appendOnly append only
17
17
  * @param {NodeJS.WritableStream} options.stream stream
@@ -11,7 +11,7 @@ const { STAGE_ADVANCED } = require("../OptimizationStages");
11
11
  /** @typedef {import("../Compiler")} Compiler */
12
12
 
13
13
  /**
14
- * @typedef {Object} AggressiveMergingPluginOptions
14
+ * @typedef {object} AggressiveMergingPluginOptions
15
15
  * @property {number=} minSizeReduce minimal size reduction to trigger merging
16
16
  */
17
17
 
@@ -26,6 +26,7 @@ const { concatComparators } = require("../util/comparators");
26
26
  const createHash = require("../util/createHash");
27
27
  const { makePathsRelative } = require("../util/identifier");
28
28
  const makeSerializable = require("../util/makeSerializable");
29
+ const { getAllReferences, getPathInAst } = require("../util/mergeScope");
29
30
  const propertyAccess = require("../util/propertyAccess");
30
31
  const { propertyName } = require("../util/propertyName");
31
32
  const {
@@ -92,7 +93,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
92
93
  }
93
94
 
94
95
  /**
95
- * @typedef {Object} ReexportInfo
96
+ * @typedef {object} ReexportInfo
96
97
  * @property {Module} module
97
98
  * @property {string[]} export
98
99
  */
@@ -100,7 +101,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
100
101
  /** @typedef {RawBinding | SymbolBinding} Binding */
101
102
 
102
103
  /**
103
- * @typedef {Object} RawBinding
104
+ * @typedef {object} RawBinding
104
105
  * @property {ModuleInfo} info
105
106
  * @property {string} rawName
106
107
  * @property {string=} comment
@@ -109,7 +110,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
109
110
  */
110
111
 
111
112
  /**
112
- * @typedef {Object} SymbolBinding
113
+ * @typedef {object} SymbolBinding
113
114
  * @property {ConcatenatedModuleInfo} info
114
115
  * @property {string} name
115
116
  * @property {string=} comment
@@ -121,7 +122,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
121
122
  /** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo | ReferenceToModuleInfo } ModuleInfoOrReference */
122
123
 
123
124
  /**
124
- * @typedef {Object} ConcatenatedModuleInfo
125
+ * @typedef {object} ConcatenatedModuleInfo
125
126
  * @property {"concatenated"} type
126
127
  * @property {Module} module
127
128
  * @property {number} index
@@ -146,7 +147,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
146
147
  */
147
148
 
148
149
  /**
149
- * @typedef {Object} ExternalModuleInfo
150
+ * @typedef {object} ExternalModuleInfo
150
151
  * @property {"external"} type
151
152
  * @property {Module} module
152
153
  * @property {RuntimeSpec | boolean} runtimeCondition
@@ -161,7 +162,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
161
162
  */
162
163
 
163
164
  /**
164
- * @typedef {Object} ReferenceToModuleInfo
165
+ * @typedef {object} ReferenceToModuleInfo
165
166
  * @property {"reference"} type
166
167
  * @property {RuntimeSpec | boolean} runtimeCondition
167
168
  * @property {ConcatenatedModuleInfo | ExternalModuleInfo} target
@@ -254,7 +255,7 @@ const joinIterableWithComma = iterable => {
254
255
  };
255
256
 
256
257
  /**
257
- * @typedef {Object} ConcatenationEntry
258
+ * @typedef {object} ConcatenationEntry
258
259
  * @property {"concatenated" | "external"} type
259
260
  * @property {Module} module
260
261
  * @property {RuntimeSpec | boolean} runtimeCondition
@@ -625,72 +626,6 @@ const addScopeSymbols = (s, nameSet, scopeSet1, scopeSet2) => {
625
626
  }
626
627
  };
627
628
 
628
- /**
629
- * @param {Variable} variable variable
630
- * @returns {Reference[]} references
631
- */
632
- const getAllReferences = variable => {
633
- let set = variable.references;
634
- // Look for inner scope variables too (like in class Foo { t() { Foo } })
635
- const identifiers = new Set(variable.identifiers);
636
- for (const scope of variable.scope.childScopes) {
637
- for (const innerVar of scope.variables) {
638
- if (innerVar.identifiers.some(id => identifiers.has(id))) {
639
- set = set.concat(innerVar.references);
640
- break;
641
- }
642
- }
643
- }
644
- return set;
645
- };
646
-
647
- /**
648
- * @param {TODO} ast ast
649
- * @param {TODO} node node
650
- * @returns {TODO} result
651
- */
652
- const getPathInAst = (ast, node) => {
653
- if (ast === node) {
654
- return [];
655
- }
656
-
657
- const nr = node.range;
658
-
659
- const enterNode = n => {
660
- if (!n) return undefined;
661
- const r = n.range;
662
- if (r) {
663
- if (r[0] <= nr[0] && r[1] >= nr[1]) {
664
- const path = getPathInAst(n, node);
665
- if (path) {
666
- path.push(n);
667
- return path;
668
- }
669
- }
670
- }
671
- return undefined;
672
- };
673
-
674
- if (Array.isArray(ast)) {
675
- for (let i = 0; i < ast.length; i++) {
676
- const enterResult = enterNode(ast[i]);
677
- if (enterResult !== undefined) return enterResult;
678
- }
679
- } else if (ast && typeof ast === "object") {
680
- const keys = Object.keys(ast);
681
- for (let i = 0; i < keys.length; i++) {
682
- const value = ast[keys[i]];
683
- if (Array.isArray(value)) {
684
- const pathResult = getPathInAst(value, node);
685
- if (pathResult !== undefined) return pathResult;
686
- } else if (value && typeof value === "object") {
687
- const enterResult = enterNode(value);
688
- if (enterResult !== undefined) return enterResult;
689
- }
690
- }
691
- }
692
- };
693
-
694
629
  const TYPES = new Set(["javascript"]);
695
630
 
696
631
  class ConcatenatedModule extends Module {
@@ -698,7 +633,7 @@ class ConcatenatedModule extends Module {
698
633
  * @param {Module} rootModule the root module of the concatenation
699
634
  * @param {Set<Module>} modules all modules in the concatenation (including the root module)
700
635
  * @param {RuntimeSpec} runtime the runtime
701
- * @param {Object=} associatedObjectForCache object for caching
636
+ * @param {object=} associatedObjectForCache object for caching
702
637
  * @param {string | HashConstructor=} hashFunction hash function to use
703
638
  * @returns {ConcatenatedModule} the module
704
639
  */
@@ -724,7 +659,7 @@ class ConcatenatedModule extends Module {
724
659
  }
725
660
 
726
661
  /**
727
- * @param {Object} options options
662
+ * @param {object} options options
728
663
  * @param {string} options.identifier the identifier of the module
729
664
  * @param {Module=} options.rootModule the root module of the concatenation
730
665
  * @param {RuntimeSpec} options.runtime the selected runtime
@@ -1098,7 +1033,7 @@ class ConcatenatedModule extends Module {
1098
1033
  /**
1099
1034
  * @param {Module} rootModule the root module of the concatenation
1100
1035
  * @param {Set<Module>} modules all modules in the concatenation (including the root module)
1101
- * @param {Object=} associatedObjectForCache object for caching
1036
+ * @param {object=} associatedObjectForCache object for caching
1102
1037
  * @param {string | HashConstructor=} hashFunction hash function to use
1103
1038
  * @returns {string} the identifier
1104
1039
  */
@@ -21,7 +21,7 @@ const { UsageState } = require("../ExportsInfo");
21
21
  /** @typedef {function(boolean | Set<string> | undefined): void} UsageCallback */
22
22
 
23
23
  /**
24
- * @typedef {Object} StateObject
24
+ * @typedef {object} StateObject
25
25
  * @property {InnerGraph} innerGraph
26
26
  * @property {TopLevelSymbol=} currentTopLevelSymbol
27
27
  * @property {Map<TopLevelSymbol, Set<UsageCallback>>} usageCallbackMap