webpack 5.90.2 → 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 (182) 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 +263 -94
  12. package/lib/Compiler.js +199 -83
  13. package/lib/ConditionalInitFragment.js +4 -5
  14. package/lib/ContextModule.js +4 -1
  15. package/lib/ContextModuleFactory.js +4 -2
  16. package/lib/ContextReplacementPlugin.js +3 -2
  17. package/lib/CssModule.js +0 -3
  18. package/lib/DefinePlugin.js +4 -2
  19. package/lib/DelegatedModule.js +2 -1
  20. package/lib/Dependency.js +4 -2
  21. package/lib/DependencyTemplate.js +7 -2
  22. package/lib/DllModule.js +3 -1
  23. package/lib/DllReferencePlugin.js +6 -2
  24. package/lib/EntryOptionPlugin.js +4 -1
  25. package/lib/EntryPlugin.js +6 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/ExportsInfo.js +1 -4
  28. package/lib/ExternalModule.js +120 -25
  29. package/lib/ExternalModuleFactoryPlugin.js +37 -2
  30. package/lib/FileSystemInfo.js +1 -1
  31. package/lib/Generator.js +2 -1
  32. package/lib/HookWebpackError.js +2 -2
  33. package/lib/InitFragment.js +5 -3
  34. package/lib/LibManifestPlugin.js +15 -7
  35. package/lib/Module.js +54 -5
  36. package/lib/ModuleFilenameHelpers.js +1 -1
  37. package/lib/ModuleGraph.js +56 -27
  38. package/lib/ModuleGraphConnection.js +2 -1
  39. package/lib/MultiCompiler.js +61 -17
  40. package/lib/NodeStuffPlugin.js +14 -3
  41. package/lib/NormalModule.js +239 -86
  42. package/lib/NormalModuleFactory.js +163 -32
  43. package/lib/NormalModuleReplacementPlugin.js +5 -1
  44. package/lib/ProvidePlugin.js +3 -1
  45. package/lib/RawModule.js +4 -2
  46. package/lib/ResolverFactory.js +5 -1
  47. package/lib/RuntimeModule.js +6 -5
  48. package/lib/RuntimePlugin.js +1 -0
  49. package/lib/RuntimeTemplate.js +102 -34
  50. package/lib/SourceMapDevToolPlugin.js +4 -1
  51. package/lib/Stats.js +12 -5
  52. package/lib/TemplatedPathPlugin.js +32 -6
  53. package/lib/Watching.js +67 -60
  54. package/lib/WebpackError.js +6 -6
  55. package/lib/WebpackOptionsApply.js +18 -5
  56. package/lib/asset/RawDataUrlModule.js +5 -2
  57. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  58. package/lib/buildChunkGraph.js +220 -392
  59. package/lib/cache/IdleFileCachePlugin.js +8 -3
  60. package/lib/cache/MemoryCachePlugin.js +1 -1
  61. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  62. package/lib/cache/PackFileCacheStrategy.js +49 -16
  63. package/lib/cache/ResolverCachePlugin.js +14 -6
  64. package/lib/cache/getLazyHashedEtag.js +1 -1
  65. package/lib/config/defaults.js +24 -1
  66. package/lib/config/normalization.js +3 -1
  67. package/lib/container/ContainerEntryDependency.js +2 -1
  68. package/lib/container/ContainerEntryModule.js +5 -2
  69. package/lib/container/ContainerPlugin.js +14 -10
  70. package/lib/container/FallbackModule.js +3 -2
  71. package/lib/container/RemoteModule.js +2 -1
  72. package/lib/container/RemoteRuntimeModule.js +12 -3
  73. package/lib/css/CssExportsGenerator.js +34 -17
  74. package/lib/css/CssGenerator.js +20 -2
  75. package/lib/css/CssLoadingRuntimeModule.js +212 -96
  76. package/lib/css/CssModulesPlugin.js +47 -13
  77. package/lib/debug/ProfilingPlugin.js +27 -2
  78. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
  79. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  80. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
  81. package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
  82. package/lib/dependencies/CommonJsExportsDependency.js +13 -5
  83. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
  84. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
  85. package/lib/dependencies/ContextDependencyHelpers.js +49 -29
  86. package/lib/dependencies/ContextElementDependency.js +8 -1
  87. package/lib/dependencies/CssLocalIdentifierDependency.js +63 -8
  88. package/lib/dependencies/CssUrlDependency.js +5 -3
  89. package/lib/dependencies/ExportsInfoDependency.js +4 -3
  90. package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
  91. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
  92. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
  93. package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
  94. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
  95. package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
  96. package/lib/dependencies/HarmonyImportDependency.js +28 -12
  97. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +44 -16
  98. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
  99. package/lib/dependencies/HarmonyImportSpecifierDependency.js +21 -10
  100. package/lib/dependencies/ImportDependency.js +9 -2
  101. package/lib/dependencies/ImportEagerDependency.js +4 -2
  102. package/lib/dependencies/ImportMetaContextDependency.js +7 -0
  103. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
  104. package/lib/dependencies/ImportParserPlugin.js +12 -4
  105. package/lib/dependencies/ImportWeakDependency.js +4 -2
  106. package/lib/dependencies/LoaderDependency.js +2 -1
  107. package/lib/dependencies/LoaderImportDependency.js +2 -1
  108. package/lib/dependencies/ModuleDependency.js +4 -5
  109. package/lib/dependencies/PureExpressionDependency.js +4 -1
  110. package/lib/dependencies/RequireContextPlugin.js +1 -1
  111. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
  112. package/lib/dependencies/RequireEnsureDependency.js +1 -1
  113. package/lib/dependencies/URLDependency.js +7 -4
  114. package/lib/dependencies/WorkerDependency.js +1 -1
  115. package/lib/dependencies/WorkerPlugin.js +6 -5
  116. package/lib/dependencies/getFunctionExpression.js +3 -1
  117. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
  118. package/lib/hmr/LazyCompilationPlugin.js +2 -1
  119. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  120. package/lib/javascript/ChunkHelpers.js +2 -2
  121. package/lib/javascript/JavascriptParser.js +169 -57
  122. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  123. package/lib/javascript/StartupHelpers.js +22 -5
  124. package/lib/logging/Logger.js +27 -2
  125. package/lib/logging/createConsoleLogger.js +11 -7
  126. package/lib/node/NodeEnvironmentPlugin.js +13 -7
  127. package/lib/node/NodeWatchFileSystem.js +37 -26
  128. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
  129. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
  130. package/lib/node/nodeConsole.js +24 -1
  131. package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
  132. package/lib/optimize/ConcatenatedModule.js +140 -55
  133. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  134. package/lib/optimize/InnerGraph.js +7 -2
  135. package/lib/optimize/InnerGraphPlugin.js +36 -13
  136. package/lib/optimize/ModuleConcatenationPlugin.js +12 -2
  137. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  138. package/lib/optimize/RuntimeChunkPlugin.js +6 -1
  139. package/lib/optimize/SideEffectsFlagPlugin.js +46 -15
  140. package/lib/optimize/SplitChunksPlugin.js +2 -2
  141. package/lib/performance/SizeLimitsPlugin.js +11 -0
  142. package/lib/rules/ObjectMatcherRulePlugin.js +4 -0
  143. package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
  144. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  145. package/lib/serialization/FileMiddleware.js +1 -0
  146. package/lib/serialization/ObjectMiddleware.js +2 -0
  147. package/lib/serialization/Serializer.js +19 -0
  148. package/lib/sharing/ConsumeSharedModule.js +3 -2
  149. package/lib/sharing/ConsumeSharedPlugin.js +17 -3
  150. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
  151. package/lib/sharing/ProvideSharedModule.js +2 -1
  152. package/lib/sharing/ProvideSharedPlugin.js +12 -5
  153. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  154. package/lib/sharing/utils.js +13 -6
  155. package/lib/util/StackedCacheMap.js +26 -0
  156. package/lib/util/WeakTupleMap.js +57 -13
  157. package/lib/util/cleverMerge.js +24 -11
  158. package/lib/util/comparators.js +34 -14
  159. package/lib/util/conventions.js +129 -0
  160. package/lib/util/fs.js +379 -65
  161. package/lib/util/hash/BatchedHash.js +3 -0
  162. package/lib/util/hash/xxhash64.js +2 -2
  163. package/lib/util/memoize.js +2 -0
  164. package/lib/util/runtime.js +1 -1
  165. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
  166. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +15 -6
  167. package/lib/wasm-sync/WebAssemblyGenerator.js +27 -6
  168. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -1
  169. package/lib/wasm-sync/WebAssemblyParser.js +7 -4
  170. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
  171. package/lib/webpack.js +11 -5
  172. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
  173. package/package.json +25 -26
  174. package/schemas/WebpackOptions.check.js +1 -1
  175. package/schemas/WebpackOptions.json +69 -8
  176. package/schemas/plugins/BannerPlugin.check.js +1 -1
  177. package/schemas/plugins/BannerPlugin.json +5 -1
  178. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  179. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  180. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  181. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  182. package/types.d.ts +1772 -673
@@ -5,18 +5,72 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const createHash = require("../util/createHash");
9
+ const { makePathsRelative } = require("../util/identifier");
8
10
  const makeSerializable = require("../util/makeSerializable");
9
11
  const NullDependency = require("./NullDependency");
10
12
 
11
13
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
14
+ /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
15
+ /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
16
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
17
+ /** @typedef {import("../CssModule")} CssModule */
12
18
  /** @typedef {import("../Dependency")} Dependency */
13
19
  /** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
14
20
  /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
15
21
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
22
+ /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
23
+ /** @typedef {import("../css/CssExportsGenerator")} CssExportsGenerator */
24
+ /** @typedef {import("../css/CssGenerator")} CssGenerator */
16
25
  /** @typedef {import("../css/CssParser").Range} Range */
17
26
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
18
27
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
19
28
 
29
+ /**
30
+ * @param {string} local css local
31
+ * @param {CssModule} module module
32
+ * @param {ChunkGraph} chunkGraph chunk graph
33
+ * @param {RuntimeTemplate} runtimeTemplate runtime template
34
+ * @returns {string} local ident
35
+ */
36
+ const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
37
+ const localIdentName =
38
+ /** @type {CssGenerator | CssExportsGenerator} */
39
+ (module.generator).localIdentName;
40
+ const relativeResourcePath = makePathsRelative(
41
+ /** @type {string} */ (module.context),
42
+ module.resourceResolveData.path
43
+ );
44
+ const { hashFunction, hashDigest, hashDigestLength, hashSalt, uniqueName } =
45
+ runtimeTemplate.outputOptions;
46
+ const hash = createHash(hashFunction);
47
+ if (hashSalt) {
48
+ hash.update(hashSalt);
49
+ }
50
+ hash.update(relativeResourcePath);
51
+ if (!/\[local\]/.test(localIdentName)) {
52
+ hash.update(local);
53
+ }
54
+ const localIdentHash = /** @type {string} */ (hash.digest(hashDigest))
55
+ // Remove all leading digits
56
+ .replace(/^\d+/, "")
57
+ // Replace all slashes with underscores (same as in base64url)
58
+ .replace(/\//g, "_")
59
+ // Remove everything that is not an alphanumeric or underscore
60
+ .replace(/[^A-Za-z0-9_]+/g, "_")
61
+ .slice(0, hashDigestLength);
62
+ return runtimeTemplate.compilation
63
+ .getPath(localIdentName, {
64
+ filename: relativeResourcePath,
65
+ hash: localIdentHash,
66
+ contentHash: localIdentHash,
67
+ chunkGraph,
68
+ module
69
+ })
70
+ .replace(/\[local\]/g, local)
71
+ .replace(/\[uniqueName\]/g, uniqueName);
72
+ };
73
+
20
74
  class CssLocalIdentifierDependency extends NullDependency {
21
75
  /**
22
76
  * @param {string} name name
@@ -112,19 +166,20 @@ CssLocalIdentifierDependency.Template = class CssLocalIdentifierDependencyTempla
112
166
 
113
167
  if (!used) return;
114
168
 
115
- const moduleId = chunkGraph.getModuleId(module);
116
- const identifier =
169
+ const localIdent =
117
170
  dep.prefix +
118
- (runtimeTemplate.outputOptions.uniqueName
119
- ? runtimeTemplate.outputOptions.uniqueName + "-"
120
- : "") +
121
- (used ? moduleId + "-" + used : "-");
171
+ getLocalIdent(
172
+ used,
173
+ /** @type {CssModule} */ (module),
174
+ chunkGraph,
175
+ runtimeTemplate
176
+ );
122
177
  source.replace(
123
178
  dep.range[0],
124
179
  dep.range[1] - 1,
125
- escapeCssIdentifier(identifier, dep.prefix)
180
+ escapeCssIdentifier(localIdent, dep.prefix)
126
181
  );
127
- if (used) cssExports.set(used, identifier);
182
+ if (used) cssExports.set(used, localIdent);
128
183
  }
129
184
  };
130
185
 
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const RawDataUrlModule = require("../asset/RawDataUrlModule");
8
9
  const makeSerializable = require("../util/makeSerializable");
9
10
  const memoize = require("../util/memoize");
10
11
  const ModuleDependency = require("./ModuleDependency");
@@ -24,7 +25,9 @@ const ModuleDependency = require("./ModuleDependency");
24
25
  /** @typedef {import("../util/Hash")} Hash */
25
26
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
26
27
 
27
- const getRawDataUrlModule = memoize(() => require("../asset/RawDataUrlModule"));
28
+ const getIgnoredRawDataUrlModule = memoize(() => {
29
+ return new RawDataUrlModule("data:,", `ignored-asset`, `(ignored asset)`);
30
+ });
28
31
 
29
32
  class CssUrlDependency extends ModuleDependency {
30
33
  /**
@@ -51,8 +54,7 @@ class CssUrlDependency extends ModuleDependency {
51
54
  * @returns {Module | null} a module
52
55
  */
53
56
  createIgnoredModule(context) {
54
- const RawDataUrlModule = getRawDataUrlModule();
55
- return new RawDataUrlModule("data:,", `ignored-asset`, `(ignored asset)`);
57
+ return getIgnoredRawDataUrlModule();
56
58
  }
57
59
 
58
60
  /**
@@ -25,13 +25,13 @@ const NullDependency = require("./NullDependency");
25
25
  /**
26
26
  * @param {ModuleGraph} moduleGraph the module graph
27
27
  * @param {Module} module the module
28
- * @param {string[] | null} exportName name of the export if any
28
+ * @param {string[] | null} _exportName name of the export if any
29
29
  * @param {string | null} property name of the requested property
30
30
  * @param {RuntimeSpec} runtime for which runtime
31
31
  * @returns {any} value of the property
32
32
  */
33
- const getProperty = (moduleGraph, module, exportName, property, runtime) => {
34
- if (!exportName) {
33
+ const getProperty = (moduleGraph, module, _exportName, property, runtime) => {
34
+ if (!_exportName) {
35
35
  switch (property) {
36
36
  case "usedExports": {
37
37
  const usedExports = moduleGraph
@@ -48,6 +48,7 @@ const getProperty = (moduleGraph, module, exportName, property, runtime) => {
48
48
  }
49
49
  }
50
50
  }
51
+ const exportName = /** @type {string[]} */ (_exportName);
51
52
  switch (property) {
52
53
  case "canMangle": {
53
54
  const exportsInfo = moduleGraph.getExportsInfo(module);
@@ -20,7 +20,7 @@ const makeSerializable = require("../util/makeSerializable");
20
20
  class ExternalModuleInitFragment extends InitFragment {
21
21
  /**
22
22
  * @param {string} importedModule imported module
23
- * @param {Array<{ name: string, value?: string }>|ImportSpecifiers} specifiers import specifiers
23
+ * @param {Array<{ name: string, value?: string }> | ImportSpecifiers} specifiers import specifiers
24
24
  * @param {string=} defaultImport default import
25
25
  */
26
26
  constructor(importedModule, specifiers, defaultImport) {
@@ -56,7 +56,9 @@ class ExternalModuleInitFragment extends InitFragment {
56
56
  const newSpecifiersMap = new Map(this.specifiers);
57
57
  for (const [name, specifiers] of other.specifiers) {
58
58
  if (newSpecifiersMap.has(name)) {
59
- const currentSpecifiers = newSpecifiersMap.get(name);
59
+ const currentSpecifiers =
60
+ /** @type {Set<string>} */
61
+ (newSpecifiersMap.get(name));
60
62
  for (const spec of specifiers) currentSpecifiers.add(spec);
61
63
  } else {
62
64
  newSpecifiersMap.set(name, specifiers);
@@ -71,7 +73,7 @@ class ExternalModuleInitFragment extends InitFragment {
71
73
 
72
74
  /**
73
75
  * @param {GenerateContext} context context
74
- * @returns {string | Source} the source code that will be included as initialization code
76
+ * @returns {string | Source | undefined} the source code that will be included as initialization code
75
77
  */
76
78
  getContent({ runtimeRequirements }) {
77
79
  const namedImports = [];
@@ -14,7 +14,7 @@ const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDepend
14
14
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
15
15
  /** @typedef {import("../Module").BuildMeta} BuildMeta */
16
16
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
17
- /** @typedef {import("../javascript/JavascriptParser").Assertions} Assertions */
17
+ /** @typedef {import("../javascript/JavascriptParser").Attributes} Attributes */
18
18
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
19
19
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
20
20
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
@@ -33,11 +33,11 @@ class HarmonyEvaluatedImportSpecifierDependency extends HarmonyImportSpecifierDe
33
33
  * @param {TODO} ids ids
34
34
  * @param {TODO} name name
35
35
  * @param {Range} range location in source code
36
- * @param {Assertions} assertions assertions
36
+ * @param {Attributes} attributes assertions
37
37
  * @param {string} operator operator
38
38
  */
39
- constructor(request, sourceOrder, ids, name, range, assertions, operator) {
40
- super(request, sourceOrder, ids, name, range, false, assertions, []);
39
+ constructor(request, sourceOrder, ids, name, range, attributes, operator) {
40
+ super(request, sourceOrder, ids, name, range, false, attributes, []);
41
41
  this.operator = operator;
42
42
  }
43
43
 
@@ -14,11 +14,14 @@ const HarmonyExportSpecifierDependency = require("./HarmonyExportSpecifierDepend
14
14
  const { ExportPresenceModes } = require("./HarmonyImportDependency");
15
15
  const {
16
16
  harmonySpecifierTag,
17
- getAssertions
17
+ getAttributes
18
18
  } = require("./HarmonyImportDependencyParserPlugin");
19
19
  const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
20
20
 
21
+ /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
21
22
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
23
+ /** @typedef {import("../javascript/JavascriptParser").FunctionDeclaration} FunctionDeclaration */
24
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
22
25
 
23
26
  const { HarmonyStarExportsList } = HarmonyExportImportedSpecifierDependency;
24
27
 
@@ -37,16 +40,24 @@ module.exports = class HarmonyExportDependencyParserPlugin {
37
40
  : ExportPresenceModes.AUTO;
38
41
  }
39
42
 
43
+ /**
44
+ * @param {JavascriptParser} parser the parser
45
+ * @returns {void}
46
+ */
40
47
  apply(parser) {
41
48
  const { exportPresenceMode } = this;
42
49
  parser.hooks.export.tap(
43
50
  "HarmonyExportDependencyParserPlugin",
44
51
  statement => {
45
52
  const dep = new HarmonyExportHeaderDependency(
46
- statement.declaration && statement.declaration.range,
47
- statement.range
53
+ /** @type {Range | false} */ (
54
+ statement.declaration && statement.declaration.range
55
+ ),
56
+ /** @type {Range} */ (statement.range)
57
+ );
58
+ dep.loc = Object.create(
59
+ /** @type {DependencyLocation} */ (statement.loc)
48
60
  );
49
- dep.loc = Object.create(statement.loc);
50
61
  dep.loc.index = -1;
51
62
  parser.state.module.addPresentationalDependency(dep);
52
63
  return true;
@@ -57,16 +68,21 @@ module.exports = class HarmonyExportDependencyParserPlugin {
57
68
  (statement, source) => {
58
69
  parser.state.lastHarmonyImportOrder =
59
70
  (parser.state.lastHarmonyImportOrder || 0) + 1;
60
- const clearDep = new ConstDependency("", statement.range);
61
- clearDep.loc = Object.create(statement.loc);
71
+ const clearDep = new ConstDependency(
72
+ "",
73
+ /** @type {Range} */ (statement.range)
74
+ );
75
+ clearDep.loc = /** @type {DependencyLocation} */ (statement.loc);
62
76
  clearDep.loc.index = -1;
63
77
  parser.state.module.addPresentationalDependency(clearDep);
64
78
  const sideEffectDep = new HarmonyImportSideEffectDependency(
65
- source,
79
+ /** @type {string} */ (source),
66
80
  parser.state.lastHarmonyImportOrder,
67
- getAssertions(statement)
81
+ getAttributes(statement)
82
+ );
83
+ sideEffectDep.loc = Object.create(
84
+ /** @type {DependencyLocation} */ (statement.loc)
68
85
  );
69
- sideEffectDep.loc = Object.create(statement.loc);
70
86
  sideEffectDep.loc.index = -1;
71
87
  parser.state.current.addDependency(sideEffectDep);
72
88
  return true;
@@ -76,13 +92,12 @@ module.exports = class HarmonyExportDependencyParserPlugin {
76
92
  "HarmonyExportDependencyParserPlugin",
77
93
  (statement, expr) => {
78
94
  const isFunctionDeclaration = expr.type === "FunctionDeclaration";
79
- const comments = parser.getComments([
80
- statement.range[0],
81
- expr.range[0]
82
- ]);
95
+ const exprRange = /** @type {Range} */ (expr.range);
96
+ const statementRange = /** @type {Range} */ (statement.range);
97
+ const comments = parser.getComments([statementRange[0], exprRange[0]]);
83
98
  const dep = new HarmonyExportExpressionDependency(
84
- expr.range,
85
- statement.range,
99
+ exprRange,
100
+ statementRange,
86
101
  comments
87
102
  .map(c => {
88
103
  switch (c.type) {
@@ -98,12 +113,11 @@ module.exports = class HarmonyExportDependencyParserPlugin {
98
113
  ? expr.id.name
99
114
  : isFunctionDeclaration
100
115
  ? {
101
- id: expr.id ? expr.id.name : undefined,
102
116
  range: [
103
- expr.range[0],
117
+ exprRange[0],
104
118
  expr.params.length > 0
105
- ? expr.params[0].range[0]
106
- : expr.body.range[0]
119
+ ? /** @type {Range} */ (expr.params[0].range)[0]
120
+ : /** @type {Range} */ (expr.body.range)[0]
107
121
  ],
108
122
  prefix: `${expr.async ? "async " : ""}function${
109
123
  expr.generator ? "*" : ""
@@ -112,7 +126,9 @@ module.exports = class HarmonyExportDependencyParserPlugin {
112
126
  }
113
127
  : undefined
114
128
  );
115
- dep.loc = Object.create(statement.loc);
129
+ dep.loc = Object.create(
130
+ /** @type {DependencyLocation} */ (statement.loc)
131
+ );
116
132
  dep.loc.index = -1;
117
133
  parser.state.current.addDependency(dep);
118
134
  InnerGraph.addVariableUsage(
@@ -149,7 +165,9 @@ module.exports = class HarmonyExportDependencyParserPlugin {
149
165
  } else {
150
166
  dep = new HarmonyExportSpecifierDependency(id, name);
151
167
  }
152
- dep.loc = Object.create(statement.loc);
168
+ dep.loc = Object.create(
169
+ /** @type {DependencyLocation} */ (statement.loc)
170
+ );
153
171
  dep.loc.index = idx;
154
172
  parser.state.current.addDependency(dep);
155
173
  return true;
@@ -168,7 +186,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
168
186
  parser.state.harmonyStarExports || new HarmonyStarExportsList();
169
187
  }
170
188
  const dep = new HarmonyExportImportedSpecifierDependency(
171
- source,
189
+ /** @type {string} */ (source),
172
190
  parser.state.lastHarmonyImportOrder,
173
191
  id ? [id] : [],
174
192
  name,
@@ -180,7 +198,9 @@ module.exports = class HarmonyExportDependencyParserPlugin {
180
198
  if (harmonyStarExports) {
181
199
  harmonyStarExports.push(dep);
182
200
  }
183
- dep.loc = Object.create(statement.loc);
201
+ dep.loc = Object.create(
202
+ /** @type {DependencyLocation} */ (statement.loc)
203
+ );
184
204
  dep.loc.index = idx;
185
205
  parser.state.current.addDependency(dep);
186
206
  return true;
@@ -17,7 +17,7 @@ const NullDependency = require("./NullDependency");
17
17
 
18
18
  class HarmonyExportHeaderDependency extends NullDependency {
19
19
  /**
20
- * @param {Range} range range
20
+ * @param {Range | false} range range
21
21
  * @param {Range} rangeStatement range statement
22
22
  */
23
23
  constructor(range, rangeStatement) {
@@ -24,19 +24,23 @@ const processExportInfo = require("./processExportInfo");
24
24
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
25
25
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
26
26
  /** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
27
+ /** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */
27
28
  /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
28
29
  /** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
29
30
  /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
30
31
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
31
32
  /** @typedef {import("../ExportsInfo")} ExportsInfo */
32
33
  /** @typedef {import("../ExportsInfo").ExportInfo} ExportInfo */
34
+ /** @typedef {import("../Generator").GenerateContext} GenerateContext */
33
35
  /** @typedef {import("../Module")} Module */
36
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
37
+ /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
34
38
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
35
39
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
36
40
  /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
37
41
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
38
42
  /** @typedef {import("../WebpackError")} WebpackError */
39
- /** @typedef {import("../javascript/JavascriptParser").Assertions} Assertions */
43
+ /** @typedef {import("../javascript/JavascriptParser").Attributes} Attributes */
40
44
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
41
45
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
42
46
  /** @typedef {import("../util/Hash")} Hash */
@@ -78,7 +82,7 @@ class ExportMode {
78
82
  this.items = null;
79
83
 
80
84
  // for "reexport-named-default" | "reexport-fake-namespace-object" | "reexport-namespace-object"
81
- /** @type {string|null} */
85
+ /** @type {string | null} */
82
86
  this.name = null;
83
87
  /** @type {ExportInfo | null} */
84
88
  this.partialNamespaceExportInfo = null;
@@ -176,7 +180,7 @@ const getMode = (moduleGraph, dep, runtimeKey) => {
176
180
 
177
181
  const name = dep.name;
178
182
  const runtime = keyToRuntime(runtimeKey);
179
- const parentModule = moduleGraph.getParentModule(dep);
183
+ const parentModule = /** @type {Module} */ (moduleGraph.getParentModule(dep));
180
184
  const exportsInfo = moduleGraph.getExportsInfo(parentModule);
181
185
 
182
186
  if (
@@ -193,7 +197,7 @@ const getMode = (moduleGraph, dep, runtimeKey) => {
193
197
 
194
198
  const importedExportsType = importedModule.getExportsType(
195
199
  moduleGraph,
196
- parentModule.buildMeta.strictHarmonyModule
200
+ /** @type {BuildMeta} */ (parentModule.buildMeta).strictHarmonyModule
197
201
  );
198
202
 
199
203
  const ids = dep.getIds(moduleGraph);
@@ -333,7 +337,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
333
337
  * @param {ReadonlyArray<HarmonyExportImportedSpecifierDependency> | Iterable<HarmonyExportImportedSpecifierDependency> | null} otherStarExports other star exports in the module before this import
334
338
  * @param {number} exportPresenceMode mode of checking export names
335
339
  * @param {HarmonyStarExportsList | null} allStarExports all star exports in the module
336
- * @param {Assertions=} assertions import assertions
340
+ * @param {Attributes=} attributes import assertions
337
341
  */
338
342
  constructor(
339
343
  request,
@@ -344,9 +348,9 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
344
348
  otherStarExports,
345
349
  exportPresenceMode,
346
350
  allStarExports,
347
- assertions
351
+ attributes
348
352
  ) {
349
- super(request, sourceOrder, assertions);
353
+ super(request, sourceOrder, attributes);
350
354
 
351
355
  this.ids = ids;
352
356
  this.name = name;
@@ -422,11 +426,12 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
422
426
  getStarReexports(
423
427
  moduleGraph,
424
428
  runtime,
425
- exportsInfo = moduleGraph.getExportsInfo(moduleGraph.getParentModule(this)),
426
- importedModule = moduleGraph.getModule(this)
429
+ exportsInfo = moduleGraph.getExportsInfo(
430
+ /** @type {Module} */ (moduleGraph.getParentModule(this))
431
+ ),
432
+ importedModule = /** @type {Module} */ (moduleGraph.getModule(this))
427
433
  ) {
428
434
  const importedExportsInfo = moduleGraph.getExportsInfo(importedModule);
429
-
430
435
  const noExtraExports =
431
436
  importedExportsInfo.otherExportsInfo.provided === false;
432
437
  const noExtraImports =
@@ -456,7 +461,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
456
461
  const exports = new Set();
457
462
  /** @type {Set<string>} */
458
463
  const checked = new Set();
459
- /** @type {Set<string>} */
464
+ /** @type {Set<string> | undefined} */
460
465
  const hidden = hiddenExports !== undefined ? new Set() : undefined;
461
466
 
462
467
  if (noExtraImports) {
@@ -468,7 +473,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
468
473
  importedExportsInfo.getReadOnlyExportInfo(name);
469
474
  if (importedExportInfo.provided === false) continue;
470
475
  if (hiddenExports !== undefined && hiddenExports.has(name)) {
471
- hidden.add(name);
476
+ /** @type {Set<string>} */
477
+ (hidden).add(name);
472
478
  continue;
473
479
  }
474
480
  exports.add(name);
@@ -483,7 +489,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
483
489
  const exportInfo = exportsInfo.getReadOnlyExportInfo(name);
484
490
  if (exportInfo.getUsed(runtime) === UsageState.Unused) continue;
485
491
  if (hiddenExports !== undefined && hiddenExports.has(name)) {
486
- hidden.add(name);
492
+ /** @type {Set<string>} */
493
+ (hidden).add(name);
487
494
  continue;
488
495
  }
489
496
  exports.add(name);
@@ -497,7 +504,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
497
504
 
498
505
  /**
499
506
  * @param {ModuleGraph} moduleGraph module graph
500
- * @returns {null | false | function(ModuleGraphConnection, RuntimeSpec): ConnectionState} function to determine if the connection is active
507
+ * @returns {null | false | GetConditionFn} function to determine if the connection is active
501
508
  */
502
509
  getCondition(moduleGraph) {
503
510
  return (connection, runtime) => {
@@ -633,7 +640,9 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
633
640
  case "missing":
634
641
  return undefined;
635
642
  case "dynamic-reexport": {
636
- const from = moduleGraph.getConnection(this);
643
+ const from =
644
+ /** @type {ModuleGraphConnection} */
645
+ (moduleGraph.getConnection(this));
637
646
  return {
638
647
  exports: true,
639
648
  from,
@@ -649,11 +658,13 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
649
658
  return {
650
659
  exports: [],
651
660
  hideExports: mode.hidden,
652
- dependencies: [moduleGraph.getModule(this)]
661
+ dependencies: [/** @type {Module} */ (moduleGraph.getModule(this))]
653
662
  };
654
663
  // falls through
655
664
  case "normal-reexport": {
656
- const from = moduleGraph.getConnection(this);
665
+ const from =
666
+ /** @type {ModuleGraphConnection} */
667
+ (moduleGraph.getConnection(this));
657
668
  return {
658
669
  exports: Array.from(mode.items, item => ({
659
670
  name: item.name,
@@ -667,11 +678,13 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
667
678
  }
668
679
  case "reexport-dynamic-default": {
669
680
  {
670
- const from = moduleGraph.getConnection(this);
681
+ const from =
682
+ /** @type {ModuleGraphConnection} */
683
+ (moduleGraph.getConnection(this));
671
684
  return {
672
685
  exports: [
673
686
  {
674
- name: mode.name,
687
+ name: /** @type {string} */ (mode.name),
675
688
  from,
676
689
  export: ["default"]
677
690
  }
@@ -683,15 +696,17 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
683
696
  }
684
697
  case "reexport-undefined":
685
698
  return {
686
- exports: [mode.name],
687
- dependencies: [moduleGraph.getModule(this)]
699
+ exports: [/** @type {string} */ (mode.name)],
700
+ dependencies: [/** @type {Module} */ (moduleGraph.getModule(this))]
688
701
  };
689
702
  case "reexport-fake-namespace-object": {
690
- const from = moduleGraph.getConnection(this);
703
+ const from =
704
+ /** @type {ModuleGraphConnection} */
705
+ (moduleGraph.getConnection(this));
691
706
  return {
692
707
  exports: [
693
708
  {
694
- name: mode.name,
709
+ name: /** @type {string} */ (mode.name),
695
710
  from,
696
711
  export: null,
697
712
  exports: [
@@ -709,11 +724,13 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
709
724
  };
710
725
  }
711
726
  case "reexport-namespace-object": {
712
- const from = moduleGraph.getConnection(this);
727
+ const from =
728
+ /** @type {ModuleGraphConnection} */
729
+ (moduleGraph.getConnection(this));
713
730
  return {
714
731
  exports: [
715
732
  {
716
- name: mode.name,
733
+ name: /** @type {string} */ (mode.name),
717
734
  from,
718
735
  export: null
719
736
  }
@@ -723,11 +740,13 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
723
740
  };
724
741
  }
725
742
  case "reexport-named-default": {
726
- const from = moduleGraph.getConnection(this);
743
+ const from =
744
+ /** @type {ModuleGraphConnection} */
745
+ (moduleGraph.getConnection(this));
727
746
  return {
728
747
  exports: [
729
748
  {
730
- name: mode.name,
749
+ name: /** @type {string} */ (mode.name),
731
750
  from,
732
751
  export: ["default"]
733
752
  }
@@ -748,7 +767,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
748
767
  _getEffectiveExportPresenceLevel(moduleGraph) {
749
768
  if (this.exportPresenceMode !== ExportPresenceModes.AUTO)
750
769
  return this.exportPresenceMode;
751
- return moduleGraph.getParentModule(this).buildMeta.strictHarmonyModule
770
+ const module = /** @type {Module} */ (moduleGraph.getParentModule(this));
771
+ return /** @type {BuildMeta} */ (module.buildMeta).strictHarmonyModule
752
772
  ? ExportPresenceModes.ERROR
753
773
  : ExportPresenceModes.WARN;
754
774
  }
@@ -826,7 +846,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
826
846
  );
827
847
  if (conflictingModule === importedModule) continue;
828
848
  const conflictingExportInfo = moduleGraph.getExportInfo(
829
- conflictingModule,
849
+ /** @type {Module} */ (conflictingModule),
830
850
  exportInfo.name
831
851
  );
832
852
  const conflictingTarget =
@@ -948,14 +968,14 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
948
968
  }
949
969
 
950
970
  /**
951
- * @param {InitFragment[]} initFragments target array for init fragments
971
+ * @param {InitFragment<GenerateContext>[]} initFragments target array for init fragments
952
972
  * @param {HarmonyExportImportedSpecifierDependency} dep dependency
953
973
  * @param {ExportMode} mode the export mode
954
974
  * @param {Module} module the current module
955
975
  * @param {ModuleGraph} moduleGraph the module graph
956
976
  * @param {RuntimeSpec} runtime the runtime
957
977
  * @param {RuntimeTemplate} runtimeTemplate the runtime template
958
- * @param {Set<string>} runtimeRequirements runtime requirements
978
+ * @param {RuntimeRequirements} runtimeRequirements runtime requirements
959
979
  * @returns {void}
960
980
  */
961
981
  _addExportFragments(
@@ -968,7 +988,7 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
968
988
  runtimeTemplate,
969
989
  runtimeRequirements
970
990
  ) {
971
- const importedModule = moduleGraph.getModule(dep);
991
+ const importedModule = /** @type {Module} */ (moduleGraph.getModule(dep));
972
992
  const importVar = dep.getImportVar(moduleGraph);
973
993
 
974
994
  switch (mode.type) {
@@ -1169,6 +1189,14 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
1169
1189
  return new HarmonyExportInitFragment(module.exportsArgument, map);
1170
1190
  }
1171
1191
 
1192
+ /**
1193
+ * @param {Module} module module
1194
+ * @param {string | string[] | false} key key
1195
+ * @param {string} name name
1196
+ * @param {number} fakeType fake type
1197
+ * @param {RuntimeRequirements} runtimeRequirements runtime requirements
1198
+ * @returns {[InitFragment<GenerateContext>, HarmonyExportInitFragment]} init fragments
1199
+ */
1172
1200
  getReexportFakeNamespaceObjectFragments(
1173
1201
  module,
1174
1202
  key,
@@ -1199,6 +1227,14 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
1199
1227
  ];
1200
1228
  }
1201
1229
 
1230
+ /**
1231
+ * @param {Module} module module
1232
+ * @param {string} key key
1233
+ * @param {string} name name
1234
+ * @param {string | string[] | false} valueKey value key
1235
+ * @param {RuntimeRequirements} runtimeRequirements runtime requirements
1236
+ * @returns {string} result
1237
+ */
1202
1238
  getConditionalReexportStatement(
1203
1239
  module,
1204
1240
  key,
@@ -1226,6 +1262,11 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
1226
1262
  )}: function() { return ${returnValue}; } });\n`;
1227
1263
  }
1228
1264
 
1265
+ /**
1266
+ * @param {string} name name
1267
+ * @param {null | false | string | string[]} valueKey value key
1268
+ * @returns {string | undefined} value
1269
+ */
1229
1270
  getReturnValue(name, valueKey) {
1230
1271
  if (valueKey === null) {
1231
1272
  return `${name}_default.a`;