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
@@ -20,11 +20,13 @@ const ModuleDependency = require("./ModuleDependency");
20
20
  /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
21
21
  /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
22
22
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
23
+ /** @typedef {import("../ExportsInfo")} ExportsInfo */
23
24
  /** @typedef {import("../Module")} Module */
25
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
24
26
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
25
27
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
26
28
  /** @typedef {import("../WebpackError")} WebpackError */
27
- /** @typedef {import("../javascript/JavascriptParser").Assertions} Assertions */
29
+ /** @typedef {import("../javascript/JavascriptParser").Attributes} Attributes */
28
30
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
29
31
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
30
32
  /** @typedef {import("../util/Hash")} Hash */
@@ -35,6 +37,10 @@ const ExportPresenceModes = {
35
37
  WARN: /** @type {1} */ (1),
36
38
  AUTO: /** @type {2} */ (2),
37
39
  ERROR: /** @type {3} */ (3),
40
+ /**
41
+ * @param {string | false} str param
42
+ * @returns {0 | 1 | 2 | 3} result
43
+ */
38
44
  fromUserOption(str) {
39
45
  switch (str) {
40
46
  case "error":
@@ -56,12 +62,12 @@ class HarmonyImportDependency extends ModuleDependency {
56
62
  *
57
63
  * @param {string} request request string
58
64
  * @param {number} sourceOrder source order
59
- * @param {Assertions=} assertions import assertions
65
+ * @param {Attributes=} attributes import assertions
60
66
  */
61
- constructor(request, sourceOrder, assertions) {
67
+ constructor(request, sourceOrder, attributes) {
62
68
  super(request);
63
69
  this.sourceOrder = sourceOrder;
64
- this.assertions = assertions;
70
+ this.assertions = attributes;
65
71
  }
66
72
 
67
73
  get category() {
@@ -84,15 +90,20 @@ class HarmonyImportDependency extends ModuleDependency {
84
90
  */
85
91
  getImportVar(moduleGraph) {
86
92
  const module = moduleGraph.getParentModule(this);
87
- const meta = moduleGraph.getMeta(module);
93
+ const meta = /** @type {TODO} */ (moduleGraph.getMeta(module));
88
94
  let importVarMap = meta.importVarMap;
89
95
  if (!importVarMap) meta.importVarMap = importVarMap = new Map();
90
- let importVar = importVarMap.get(moduleGraph.getModule(this));
96
+ let importVar = importVarMap.get(
97
+ /** @type {Module} */ (moduleGraph.getModule(this))
98
+ );
91
99
  if (importVar) return importVar;
92
100
  importVar = `${Template.toIdentifier(
93
101
  `${this.userRequest}`
94
102
  )}__WEBPACK_IMPORTED_MODULE_${importVarMap.size}__`;
95
- importVarMap.set(moduleGraph.getModule(this), importVar);
103
+ importVarMap.set(
104
+ /** @type {Module} */ (moduleGraph.getModule(this)),
105
+ importVar
106
+ );
96
107
  return importVar;
97
108
  }
98
109
 
@@ -107,7 +118,7 @@ class HarmonyImportDependency extends ModuleDependency {
107
118
  ) {
108
119
  return runtimeTemplate.importStatement({
109
120
  update,
110
- module: moduleGraph.getModule(this),
121
+ module: /** @type {Module} */ (moduleGraph.getModule(this)),
111
122
  chunkGraph,
112
123
  importVar: this.getImportVar(moduleGraph),
113
124
  request: this.request,
@@ -129,10 +140,12 @@ class HarmonyImportDependency extends ModuleDependency {
129
140
  return;
130
141
  }
131
142
 
132
- const parentModule = moduleGraph.getParentModule(this);
143
+ const parentModule =
144
+ /** @type {Module} */
145
+ (moduleGraph.getParentModule(this));
133
146
  const exportsType = importedModule.getExportsType(
134
147
  moduleGraph,
135
- parentModule.buildMeta.strictHarmonyModule
148
+ /** @type {BuildMeta} */ (parentModule.buildMeta).strictHarmonyModule
136
149
  );
137
150
  if (exportsType === "namespace" || exportsType === "default-with-named") {
138
151
  if (ids.length === 0) {
@@ -170,7 +183,9 @@ class HarmonyImportDependency extends ModuleDependency {
170
183
  )
171
184
  ];
172
185
  }
173
- exportsInfo = exportInfo.getNestedExportsInfo();
186
+ exportsInfo =
187
+ /** @type {ExportsInfo} */
188
+ (exportInfo.getNestedExportsInfo());
174
189
  }
175
190
 
176
191
  // General error message
@@ -207,7 +222,8 @@ class HarmonyImportDependency extends ModuleDependency {
207
222
  if (
208
223
  ids.length > 0 &&
209
224
  ids[0] !== "default" &&
210
- importedModule.buildMeta.defaultObject === "redirect-warn"
225
+ /** @type {BuildMeta} */
226
+ (importedModule.buildMeta).defaultObject === "redirect-warn"
211
227
  ) {
212
228
  // For these modules only the default export is supported
213
229
  return [
@@ -21,7 +21,10 @@ const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDepend
21
21
  /** @typedef {import("estree").Identifier} Identifier */
22
22
  /** @typedef {import("estree").ImportDeclaration} ImportDeclaration */
23
23
  /** @typedef {import("estree").ImportExpression} ImportExpression */
24
+ /** @typedef {import("estree").Literal} Literal */
24
25
  /** @typedef {import("estree").MemberExpression} MemberExpression */
26
+ /** @typedef {import("estree").ObjectExpression} ObjectExpression */
27
+ /** @typedef {import("estree").Property} Property */
25
28
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
26
29
  /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
27
30
  /** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
@@ -44,24 +47,47 @@ const harmonySpecifierTag = Symbol("harmony import");
44
47
  */
45
48
 
46
49
  /**
47
- * @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | ImportExpression} node node with assertions
50
+ * @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | (ImportExpression & { arguments?: ObjectExpression[] })} node node with assertions
48
51
  * @returns {Record<string, any> | undefined} assertions
49
52
  */
50
- function getAssertions(node) {
53
+ function getAttributes(node) {
54
+ if (
55
+ node.type === "ImportExpression" &&
56
+ node.arguments &&
57
+ node.arguments[0] &&
58
+ node.arguments[0].type === "ObjectExpression" &&
59
+ node.arguments[0].properties[0] &&
60
+ node.arguments[0].properties[0].type === "Property" &&
61
+ node.arguments[0].properties[0].value.type === "ObjectExpression" &&
62
+ node.arguments[0].properties[0].value.properties
63
+ ) {
64
+ const properties = /** @type {Property[]} */ (
65
+ node.arguments[0].properties[0].value.properties
66
+ );
67
+ const result = {};
68
+ for (const property of properties) {
69
+ const key =
70
+ property.key.type === "Identifier"
71
+ ? property.key.name
72
+ : /** @type {Literal} */ (property.key).value;
73
+ result[key] = /** @type {Literal} */ (property.value).value;
74
+ }
75
+ return result;
76
+ }
51
77
  // TODO remove cast when @types/estree has been updated to import assertions
52
- const assertions = /** @type {{ assertions?: ImportAttributeNode[] }} */ (
53
- node
54
- ).assertions;
55
- if (assertions === undefined) {
78
+ const attributes =
79
+ /** @type {{ assertions?: ImportAttributeNode[] }} */
80
+ (node).assertions;
81
+ if (attributes === undefined) {
56
82
  return undefined;
57
83
  }
58
84
  const result = {};
59
- for (const assertion of assertions) {
85
+ for (const attribute of attributes) {
60
86
  const key =
61
- assertion.key.type === "Identifier"
62
- ? assertion.key.name
63
- : assertion.key.value;
64
- result[key] = assertion.value.value;
87
+ attribute.key.type === "Identifier"
88
+ ? attribute.key.name
89
+ : attribute.key.value;
90
+ result[key] = attribute.value.value;
65
91
  }
66
92
  return result;
67
93
  }
@@ -125,11 +151,11 @@ module.exports = class HarmonyImportDependencyParserPlugin {
125
151
  clearDep.loc = /** @type {DependencyLocation} */ (statement.loc);
126
152
  parser.state.module.addPresentationalDependency(clearDep);
127
153
  parser.unsetAsiPosition(/** @type {Range} */ (statement.range)[1]);
128
- const assertions = getAssertions(statement);
154
+ const attributes = getAttributes(statement);
129
155
  const sideEffectDep = new HarmonyImportSideEffectDependency(
130
- source,
156
+ /** @type {string} */ (source),
131
157
  parser.state.lastHarmonyImportOrder,
132
- assertions
158
+ attributes
133
159
  );
134
160
  sideEffectDep.loc = /** @type {DependencyLocation} */ (statement.loc);
135
161
  parser.state.module.addDependency(sideEffectDep);
@@ -145,7 +171,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
145
171
  source,
146
172
  ids,
147
173
  sourceOrder: parser.state.lastHarmonyImportOrder,
148
- assertions: getAssertions(statement)
174
+ assertions: getAttributes(statement)
149
175
  });
150
176
  return true;
151
177
  }
@@ -368,4 +394,6 @@ module.exports = class HarmonyImportDependencyParserPlugin {
368
394
  };
369
395
 
370
396
  module.exports.harmonySpecifierTag = harmonySpecifierTag;
371
- module.exports.getAssertions = getAssertions;
397
+ // TODO remove it in webpack@6 in favor getAttributes
398
+ module.exports.getAssertions = getAttributes;
399
+ module.exports.getAttributes = getAttributes;
@@ -10,23 +10,24 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
10
10
 
11
11
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
12
12
  /** @typedef {import("../Dependency")} Dependency */
13
+ /** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */
13
14
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
14
15
  /** @typedef {import("../Module")} Module */
15
16
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
16
17
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
17
18
  /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
18
- /** @typedef {import("../javascript/JavascriptParser").Assertions} Assertions */
19
+ /** @typedef {import("../javascript/JavascriptParser").Attributes} Attributes */
19
20
  /** @typedef {import("../util/Hash")} Hash */
20
21
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
21
22
 
22
23
  class HarmonyImportSideEffectDependency extends HarmonyImportDependency {
23
24
  /**
24
- * @param {TODO} request the request string
25
+ * @param {string} request the request string
25
26
  * @param {number} sourceOrder source order
26
- * @param {Assertions=} assertions assertions
27
+ * @param {Attributes=} attributes assertions
27
28
  */
28
- constructor(request, sourceOrder, assertions) {
29
- super(request, sourceOrder, assertions);
29
+ constructor(request, sourceOrder, attributes) {
30
+ super(request, sourceOrder, attributes);
30
31
  }
31
32
 
32
33
  get type() {
@@ -35,7 +36,7 @@ class HarmonyImportSideEffectDependency extends HarmonyImportDependency {
35
36
 
36
37
  /**
37
38
  * @param {ModuleGraph} moduleGraph module graph
38
- * @returns {null | false | function(ModuleGraphConnection, RuntimeSpec): ConnectionState} function to determine if the connection is active
39
+ * @returns {null | false | GetConditionFn} function to determine if the connection is active
39
40
  */
40
41
  getCondition(moduleGraph) {
41
42
  return connection => {
@@ -17,6 +17,7 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
17
17
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
18
18
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
19
19
  /** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
20
+ /** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */
20
21
  /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
21
22
  /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
22
23
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
@@ -26,7 +27,7 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
26
27
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
27
28
  /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
28
29
  /** @typedef {import("../WebpackError")} WebpackError */
29
- /** @typedef {import("../javascript/JavascriptParser").Assertions} Assertions */
30
+ /** @typedef {import("../javascript/JavascriptParser").Attributes} Attributes */
30
31
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
31
32
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
32
33
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
@@ -45,7 +46,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
45
46
  * @param {string} name name
46
47
  * @param {Range} range range
47
48
  * @param {TODO} exportPresenceMode export presence mode
48
- * @param {Assertions=} assertions assertions
49
+ * @param {Attributes=} attributes assertions
49
50
  * @param {Range[]=} idRanges ranges for members of ids; the two arrays are right-aligned
50
51
  */
51
52
  constructor(
@@ -55,10 +56,10 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
55
56
  name,
56
57
  range,
57
58
  exportPresenceMode,
58
- assertions,
59
+ attributes,
59
60
  idRanges // TODO webpack 6 make this non-optional. It must always be set to properly trim ids.
60
61
  ) {
61
- super(request, sourceOrder, assertions);
62
+ super(request, sourceOrder, attributes);
62
63
  this.ids = ids;
63
64
  this.name = name;
64
65
  this.range = range;
@@ -117,7 +118,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
117
118
 
118
119
  /**
119
120
  * @param {ModuleGraph} moduleGraph module graph
120
- * @returns {null | false | function(ModuleGraphConnection, RuntimeSpec): ConnectionState} function to determine if the connection is active
121
+ * @returns {null | false | GetConditionFn} function to determine if the connection is active
121
122
  */
122
123
  getCondition(moduleGraph) {
123
124
  return getDependencyUsedByExportsCondition(
@@ -16,6 +16,7 @@ const ModuleDependency = require("./ModuleDependency");
16
16
  /** @typedef {import("../Module")} Module */
17
17
  /** @typedef {import("../Module").BuildMeta} BuildMeta */
18
18
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
19
+ /** @typedef {import("../javascript/JavascriptParser").Attributes} Attributes */
19
20
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
20
21
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
21
22
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
@@ -26,11 +27,13 @@ class ImportDependency extends ModuleDependency {
26
27
  * @param {string} request the request
27
28
  * @param {Range} range expression range
28
29
  * @param {(string[][] | null)=} referencedExports list of referenced exports
30
+ * @param {Attributes=} attributes assertions
29
31
  */
30
- constructor(request, range, referencedExports) {
32
+ constructor(request, range, referencedExports, attributes) {
31
33
  super(request);
32
34
  this.range = range;
33
35
  this.referencedExports = referencedExports;
36
+ this.assertions = attributes;
34
37
  }
35
38
 
36
39
  get type() {
@@ -52,7 +55,9 @@ class ImportDependency extends ModuleDependency {
52
55
  const refs = [];
53
56
  for (const referencedExport of this.referencedExports) {
54
57
  if (referencedExport[0] === "default") {
55
- const selfModule = moduleGraph.getParentModule(this);
58
+ const selfModule =
59
+ /** @type {Module} */
60
+ (moduleGraph.getParentModule(this));
56
61
  const importedModule =
57
62
  /** @type {Module} */
58
63
  (moduleGraph.getModule(this));
@@ -82,6 +87,7 @@ class ImportDependency extends ModuleDependency {
82
87
  serialize(context) {
83
88
  context.write(this.range);
84
89
  context.write(this.referencedExports);
90
+ context.write(this.assertions);
85
91
  super.serialize(context);
86
92
  }
87
93
 
@@ -91,6 +97,7 @@ class ImportDependency extends ModuleDependency {
91
97
  deserialize(context) {
92
98
  this.range = context.read();
93
99
  this.referencedExports = context.read();
100
+ this.assertions = context.read();
94
101
  super.deserialize(context);
95
102
  }
96
103
  }
@@ -15,6 +15,7 @@ const ImportDependency = require("./ImportDependency");
15
15
  /** @typedef {import("../Module")} Module */
16
16
  /** @typedef {import("../Module").BuildMeta} BuildMeta */
17
17
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
18
+ /** @typedef {import("../javascript/JavascriptParser").Attributes} Attributes */
18
19
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
19
20
 
20
21
  class ImportEagerDependency extends ImportDependency {
@@ -22,9 +23,10 @@ class ImportEagerDependency extends ImportDependency {
22
23
  * @param {string} request the request
23
24
  * @param {Range} range expression range
24
25
  * @param {(string[][] | null)=} referencedExports list of referenced exports
26
+ * @param {Attributes=} attributes assertions
25
27
  */
26
- constructor(request, range, referencedExports) {
27
- super(request, range, referencedExports);
28
+ constructor(request, range, referencedExports, attributes) {
29
+ super(request, range, referencedExports, attributes);
28
30
  }
29
31
 
30
32
  get type() {
@@ -9,7 +9,14 @@ const makeSerializable = require("../util/makeSerializable");
9
9
  const ContextDependency = require("./ContextDependency");
10
10
  const ModuleDependencyTemplateAsRequireId = require("./ModuleDependencyTemplateAsRequireId");
11
11
 
12
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
13
+ /** @typedef {import("./ContextDependency").ContextDependencyOptions} ContextDependencyOptions */
14
+
12
15
  class ImportMetaContextDependency extends ContextDependency {
16
+ /**
17
+ * @param {ContextDependencyOptions} options options
18
+ * @param {Range} range range
19
+ */
13
20
  constructor(options, range) {
14
21
  super(options);
15
22
 
@@ -16,8 +16,11 @@ const ImportMetaContextDependency = require("./ImportMetaContextDependency");
16
16
  /** @typedef {import("estree").Property} Property */
17
17
  /** @typedef {import("estree").SourceLocation} SourceLocation */
18
18
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
19
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
19
20
  /** @typedef {import("../ContextModule").ContextModuleOptions} ContextModuleOptions */
20
21
  /** @typedef {import("../ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
22
+ /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
23
+ /** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
21
24
  /** @typedef {Pick<ContextModuleOptions, 'mode'|'recursive'|'regExp'|'include'|'exclude'|'chunkName'>&{groupOptions: RawChunkGroupOptions, exports?: ContextModuleOptions["referencedExports"]}} ImportMetaContextOptions */
22
25
 
23
26
  /**
@@ -36,7 +39,7 @@ function createPropertyParseError(prop, expect) {
36
39
 
37
40
  /**
38
41
  * @param {string} msg message
39
- * @param {SourceLocation} loc location
42
+ * @param {DependencyLocation} loc location
40
43
  * @returns {WebpackError} error
41
44
  */
42
45
  function createError(msg, loc) {
@@ -72,7 +75,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
72
75
  /** @type {Expression} */ (directoryNode)
73
76
  );
74
77
  if (!requestExpr.isString()) return;
75
- const request = requestExpr.string;
78
+ const request = /** @type {string} */ (requestExpr.string);
76
79
  const errors = [];
77
80
  let regExp = /^\.\/.*$/;
78
81
  let recursive = true;
@@ -95,7 +98,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
95
98
  errors.push(
96
99
  createError(
97
100
  "Parsing import.meta.webpackContext options failed.",
98
- optionsNode.loc
101
+ /** @type {DependencyLocation} */ (optionsNode.loc)
99
102
  )
100
103
  );
101
104
  break;
@@ -108,7 +111,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
108
111
  if (!regExpExpr.isRegExp()) {
109
112
  errors.push(createPropertyParseError(prop, "RegExp"));
110
113
  } else {
111
- regExp = regExpExpr.regExp;
114
+ regExp = /** @type {RegExp} */ (regExpExpr.regExp);
112
115
  }
113
116
  break;
114
117
  }
@@ -163,21 +166,27 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
163
166
  /** @type {Expression} */ (prop.value)
164
167
  );
165
168
  if (expr.isString()) {
166
- exports = [[expr.string]];
169
+ exports = [[/** @type {string} */ (expr.string)]];
167
170
  } else if (expr.isArray()) {
168
- const items = expr.items;
171
+ const items =
172
+ /** @type {BasicEvaluatedExpression[]} */
173
+ (expr.items);
169
174
  if (
170
175
  items.every(i => {
171
176
  if (!i.isArray()) return false;
172
- const innerItems = i.items;
177
+ const innerItems =
178
+ /** @type {BasicEvaluatedExpression[]} */ (i.items);
173
179
  return innerItems.every(i => i.isString());
174
180
  })
175
181
  ) {
176
182
  exports = [];
177
183
  for (const i1 of items) {
184
+ /** @type {string[]} */
178
185
  const export_ = [];
179
- for (const i2 of i1.items) {
180
- export_.push(i2.string);
186
+ for (const i2 of /** @type {BasicEvaluatedExpression[]} */ (
187
+ i1.items
188
+ )) {
189
+ export_.push(/** @type {string} */ (i2.string));
181
190
  }
182
191
  exports.push(export_);
183
192
  }
@@ -225,7 +234,9 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
225
234
  );
226
235
  if (
227
236
  expr.isString() &&
228
- ["high", "low", "auto"].includes(expr.string)
237
+ ["high", "low", "auto"].includes(
238
+ /** @type {string} */ (expr.string)
239
+ )
229
240
  ) {
230
241
  groupOptions.fetchPriority =
231
242
  /** @type {RawChunkGroupOptions["fetchPriority"]} */ (
@@ -245,7 +256,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
245
256
  if (!recursiveExpr.isBoolean()) {
246
257
  errors.push(createPropertyParseError(prop, "boolean"));
247
258
  } else {
248
- recursive = recursiveExpr.bool;
259
+ recursive = /** @type {boolean} */ (recursiveExpr.bool);
249
260
  }
250
261
  break;
251
262
  }
@@ -255,7 +266,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
255
266
  `Parsing import.meta.webpackContext options failed. Unknown property ${JSON.stringify(
256
267
  prop.key.name
257
268
  )}.`,
258
- optionsNode.loc
269
+ /** @type {DependencyLocation} */ (optionsNode.loc)
259
270
  )
260
271
  );
261
272
  }
@@ -279,9 +290,9 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
279
290
  mode,
280
291
  category: "esm"
281
292
  },
282
- expr.range
293
+ /** @type {Range} */ (expr.range)
283
294
  );
284
- dep.loc = expr.loc;
295
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
285
296
  dep.optional = !!parser.scope.inTry;
286
297
  parser.state.current.addDependency(dep);
287
298
  return true;
@@ -9,11 +9,13 @@ const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
9
9
  const CommentCompilationWarning = require("../CommentCompilationWarning");
10
10
  const UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning");
11
11
  const ContextDependencyHelpers = require("./ContextDependencyHelpers");
12
+ const { getAttributes } = require("./HarmonyImportDependencyParserPlugin");
12
13
  const ImportContextDependency = require("./ImportContextDependency");
13
14
  const ImportDependency = require("./ImportDependency");
14
15
  const ImportEagerDependency = require("./ImportEagerDependency");
15
16
  const ImportWeakDependency = require("./ImportWeakDependency");
16
17
 
18
+ /** @typedef {import("estree").ImportExpression} ImportExpression */
17
19
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
18
20
  /** @typedef {import("../ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
19
21
  /** @typedef {import("../ContextModule").ContextMode} ContextMode */
@@ -258,18 +260,22 @@ class ImportParserPlugin {
258
260
  }
259
261
 
260
262
  if (param.isString()) {
263
+ const attributes = getAttributes(expr);
264
+
261
265
  if (mode === "eager") {
262
266
  const dep = new ImportEagerDependency(
263
267
  /** @type {string} */ (param.string),
264
268
  /** @type {Range} */ (expr.range),
265
- exports
269
+ exports,
270
+ attributes
266
271
  );
267
272
  parser.state.current.addDependency(dep);
268
273
  } else if (mode === "weak") {
269
274
  const dep = new ImportWeakDependency(
270
275
  /** @type {string} */ (param.string),
271
276
  /** @type {Range} */ (expr.range),
272
- exports
277
+ exports,
278
+ attributes
273
279
  );
274
280
  parser.state.current.addDependency(dep);
275
281
  } else {
@@ -284,7 +290,8 @@ class ImportParserPlugin {
284
290
  const dep = new ImportDependency(
285
291
  /** @type {string} */ (param.string),
286
292
  /** @type {Range} */ (expr.range),
287
- exports
293
+ exports,
294
+ attributes
288
295
  );
289
296
  dep.loc = /** @type {DependencyLocation} */ (expr.loc);
290
297
  dep.optional = !!parser.scope.inTry;
@@ -315,7 +322,8 @@ class ImportParserPlugin {
315
322
  : true,
316
323
  typePrefix: "import()",
317
324
  category: "esm",
318
- referencedExports: exports
325
+ referencedExports: exports,
326
+ attributes: getAttributes(expr)
319
327
  },
320
328
  parser
321
329
  );
@@ -15,6 +15,7 @@ const ImportDependency = require("./ImportDependency");
15
15
  /** @typedef {import("../Module")} Module */
16
16
  /** @typedef {import("../Module").BuildMeta} BuildMeta */
17
17
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
18
+ /** @typedef {import("../javascript/JavascriptParser").Attributes} Attributes */
18
19
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
19
20
 
20
21
  class ImportWeakDependency extends ImportDependency {
@@ -22,9 +23,10 @@ class ImportWeakDependency extends ImportDependency {
22
23
  * @param {string} request the request
23
24
  * @param {Range} range expression range
24
25
  * @param {(string[][] | null)=} referencedExports list of referenced exports
26
+ * @param {Attributes=} attributes assertions
25
27
  */
26
- constructor(request, range, referencedExports) {
27
- super(request, range, referencedExports);
28
+ constructor(request, range, referencedExports, attributes) {
29
+ super(request, range, referencedExports, attributes);
28
30
  this.weak = true;
29
31
  }
30
32
 
@@ -7,6 +7,7 @@
7
7
 
8
8
  const ModuleDependency = require("./ModuleDependency");
9
9
 
10
+ /** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */
10
11
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
11
12
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
12
13
  /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
@@ -30,7 +31,7 @@ class LoaderDependency extends ModuleDependency {
30
31
 
31
32
  /**
32
33
  * @param {ModuleGraph} moduleGraph module graph
33
- * @returns {null | false | function(ModuleGraphConnection, RuntimeSpec): ConnectionState} function to determine if the connection is active
34
+ * @returns {null | false | GetConditionFn} function to determine if the connection is active
34
35
  */
35
36
  getCondition(moduleGraph) {
36
37
  return false;
@@ -7,6 +7,7 @@
7
7
 
8
8
  const ModuleDependency = require("./ModuleDependency");
9
9
 
10
+ /** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */
10
11
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
11
12
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
12
13
  /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
@@ -31,7 +32,7 @@ class LoaderImportDependency extends ModuleDependency {
31
32
 
32
33
  /**
33
34
  * @param {ModuleGraph} moduleGraph module graph
34
- * @returns {null | false | function(ModuleGraphConnection, RuntimeSpec): ConnectionState} function to determine if the connection is active
35
+ * @returns {null | false | GetConditionFn} function to determine if the connection is active
35
36
  */
36
37
  getCondition(moduleGraph) {
37
38
  return false;
@@ -7,15 +7,14 @@
7
7
 
8
8
  const Dependency = require("../Dependency");
9
9
  const DependencyTemplate = require("../DependencyTemplate");
10
- const memoize = require("../util/memoize");
10
+ const RawModule = require("../RawModule");
11
11
 
12
12
  /** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
13
13
  /** @typedef {import("../Module")} Module */
14
+ /** @typedef {import("../javascript/JavascriptParser").Attributes} Attributes */
14
15
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
15
16
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
16
17
 
17
- const getRawModule = memoize(() => require("../RawModule"));
18
-
19
18
  class ModuleDependency extends Dependency {
20
19
  /**
21
20
  * @param {string} request request path which needs resolving
@@ -25,8 +24,9 @@ class ModuleDependency extends Dependency {
25
24
  this.request = request;
26
25
  this.userRequest = request;
27
26
  this.range = undefined;
27
+ // TODO move it to subclasses and rename
28
28
  // assertions must be serialized by subclasses that use it
29
- /** @type {Record<string, any> | undefined} */
29
+ /** @type {Attributes | undefined} */
30
30
  this.assertions = undefined;
31
31
  this._context = undefined;
32
32
  }
@@ -61,7 +61,6 @@ class ModuleDependency extends Dependency {
61
61
  * @returns {Module | null} a module
62
62
  */
63
63
  createIgnoredModule(context) {
64
- const RawModule = getRawModule();
65
64
  return new RawModule(
66
65
  "/* (ignored) */",
67
66
  `ignored|${context}|${this.request}`,