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
@@ -126,6 +126,7 @@ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
126
126
  { moduleGraph, runtimeTemplate, codeGenerationResults }
127
127
  ) {
128
128
  const dep = /** @type {CssUrlDependency} */ (dependency);
129
+ const module = /** @type {Module} */ (moduleGraph.getModule(dep));
129
130
 
130
131
  /** @type {string | undefined} */
131
132
  let newValue;
@@ -134,8 +135,7 @@ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
134
135
  case "string":
135
136
  newValue = cssEscapeString(
136
137
  runtimeTemplate.assetUrl({
137
- publicPath: "",
138
- module: /** @type {Module} */ (moduleGraph.getModule(dep)),
138
+ module,
139
139
  codeGenerationResults
140
140
  })
141
141
  );
@@ -143,8 +143,7 @@ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
143
143
  case "url":
144
144
  newValue = `url(${cssEscapeString(
145
145
  runtimeTemplate.assetUrl({
146
- publicPath: "",
147
- module: /** @type {Module} */ (moduleGraph.getModule(dep)),
146
+ module,
148
147
  codeGenerationResults
149
148
  })
150
149
  )})`;
@@ -161,4 +160,6 @@ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
161
160
 
162
161
  makeSerializable(CssUrlDependency, "webpack/lib/dependencies/CssUrlDependency");
163
162
 
163
+ CssUrlDependency.PUBLIC_PATH_AUTO = "__WEBPACK_CSS_PUBLIC_PATH_AUTO__";
164
+
164
165
  module.exports = CssUrlDependency;
@@ -52,7 +52,7 @@ const getProperty = (moduleGraph, module, _exportName, property, runtime) => {
52
52
  switch (property) {
53
53
  case "canMangle": {
54
54
  const exportsInfo = moduleGraph.getExportsInfo(module);
55
- const exportInfo = exportsInfo.getExportInfo(exportName[0]);
55
+ const exportInfo = exportsInfo.getReadOnlyExportInfoRecursive(exportName);
56
56
  if (exportInfo) return exportInfo.canMangle;
57
57
  return exportsInfo.otherExportsInfo.canMangle;
58
58
  }
@@ -92,11 +92,13 @@ ExternalModuleDependency.Template = class ExternalModuleDependencyTemplate exten
92
92
  apply(dependency, source, templateContext) {
93
93
  super.apply(dependency, source, templateContext);
94
94
  const dep = /** @type {ExternalModuleDependency} */ (dependency);
95
- const { chunkInitFragments } = templateContext;
95
+ const { chunkInitFragments, runtimeTemplate } = templateContext;
96
96
 
97
97
  chunkInitFragments.push(
98
98
  new ExternalModuleInitFragment(
99
- dep.importedModule,
99
+ `${runtimeTemplate.supportNodePrefixForCoreModules() ? "node:" : ""}${
100
+ dep.importedModule
101
+ }`,
100
102
  dep.specifiers,
101
103
  dep.default
102
104
  )
@@ -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").Attributes} Attributes */
17
+ /** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
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,7 +33,7 @@ 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 {Attributes} attributes assertions
36
+ * @param {ImportAttributes} attributes import assertions
37
37
  * @param {string} operator operator
38
38
  */
39
39
  constructor(request, sourceOrder, ids, name, range, attributes, operator) {
@@ -40,7 +40,7 @@ const processExportInfo = require("./processExportInfo");
40
40
  /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
41
41
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
42
42
  /** @typedef {import("../WebpackError")} WebpackError */
43
- /** @typedef {import("../javascript/JavascriptParser").Attributes} Attributes */
43
+ /** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
44
44
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
45
45
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
46
46
  /** @typedef {import("../util/Hash")} Hash */
@@ -337,7 +337,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
337
337
  * @param {ReadonlyArray<HarmonyExportImportedSpecifierDependency> | Iterable<HarmonyExportImportedSpecifierDependency> | null} otherStarExports other star exports in the module before this import
338
338
  * @param {number} exportPresenceMode mode of checking export names
339
339
  * @param {HarmonyStarExportsList | null} allStarExports all star exports in the module
340
- * @param {Attributes=} attributes import assertions
340
+ * @param {ImportAttributes=} attributes import attributes
341
341
  */
342
342
  constructor(
343
343
  request,
@@ -26,7 +26,7 @@ const ModuleDependency = require("./ModuleDependency");
26
26
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
27
27
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
28
28
  /** @typedef {import("../WebpackError")} WebpackError */
29
- /** @typedef {import("../javascript/JavascriptParser").Attributes} Attributes */
29
+ /** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
30
30
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
31
31
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
32
32
  /** @typedef {import("../util/Hash")} Hash */
@@ -62,7 +62,7 @@ class HarmonyImportDependency extends ModuleDependency {
62
62
  *
63
63
  * @param {string} request request string
64
64
  * @param {number} sourceOrder source order
65
- * @param {Attributes=} attributes import assertions
65
+ * @param {ImportAttributes=} attributes import attributes
66
66
  */
67
67
  constructor(request, sourceOrder, attributes) {
68
68
  super(request);
@@ -29,6 +29,8 @@ const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDepend
29
29
  /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
30
30
  /** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
31
31
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
32
+ /** @typedef {import("../javascript/JavascriptParser").DestructuringAssignmentProperty} DestructuringAssignmentProperty */
33
+ /** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
32
34
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
33
35
  /** @typedef {import("../optimize/InnerGraph").InnerGraph} InnerGraph */
34
36
  /** @typedef {import("../optimize/InnerGraph").TopLevelSymbol} TopLevelSymbol */
@@ -37,7 +39,7 @@ const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDepend
37
39
  const harmonySpecifierTag = Symbol("harmony import");
38
40
 
39
41
  /**
40
- * @typedef {Object} HarmonySettings
42
+ * @typedef {object} HarmonySettings
41
43
  * @property {string[]} ids
42
44
  * @property {string} source
43
45
  * @property {number} sourceOrder
@@ -48,7 +50,7 @@ const harmonySpecifierTag = Symbol("harmony import");
48
50
 
49
51
  /**
50
52
  * @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | (ImportExpression & { arguments?: ObjectExpression[] })} node node with assertions
51
- * @returns {Record<string, any> | undefined} assertions
53
+ * @returns {ImportAttributes} import attributes
52
54
  */
53
55
  function getAttributes(node) {
54
56
  if (
@@ -61,33 +63,54 @@ function getAttributes(node) {
61
63
  node.arguments[0].properties[0].value.type === "ObjectExpression" &&
62
64
  node.arguments[0].properties[0].value.properties
63
65
  ) {
64
- const properties = /** @type {Property[]} */ (
65
- node.arguments[0].properties[0].value.properties
66
- );
67
- const result = {};
66
+ const properties =
67
+ /** @type {Property[]} */
68
+ (node.arguments[0].properties[0].value.properties);
69
+ const result = /** @type {ImportAttributes} */ ({});
68
70
  for (const property of properties) {
69
71
  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;
72
+ /** @type {string} */
73
+ (
74
+ property.key.type === "Identifier"
75
+ ? property.key.name
76
+ : /** @type {Literal} */ (property.key).value
77
+ );
78
+ result[key] =
79
+ /** @type {string} */
80
+ (/** @type {Literal} */ (property.value).value);
81
+ }
82
+ const key =
83
+ node.arguments[0].properties[0].key.type === "Identifier"
84
+ ? node.arguments[0].properties[0].key.name
85
+ : /** @type {Literal} */ (node.arguments[0].properties[0].key).value;
86
+ if (key === "assert") {
87
+ result._isLegacyAssert = true;
74
88
  }
75
89
  return result;
76
90
  }
77
91
  // TODO remove cast when @types/estree has been updated to import assertions
78
- const attributes =
79
- /** @type {{ assertions?: ImportAttributeNode[] }} */
80
- (node).assertions;
92
+ const isImportAssertion =
93
+ /** @type {{ assertions?: ImportAttributeNode[] }} */ (node).assertions !==
94
+ undefined;
95
+ const attributes = isImportAssertion
96
+ ? /** @type {{ assertions?: ImportAttributeNode[] }} */ (node).assertions
97
+ : /** @type {{ attributes?: ImportAttributeNode[] }} */ (node).attributes;
81
98
  if (attributes === undefined) {
82
99
  return undefined;
83
100
  }
84
- const result = {};
101
+ const result = /** @type {ImportAttributes} */ ({});
85
102
  for (const attribute of attributes) {
86
103
  const key =
87
- attribute.key.type === "Identifier"
88
- ? attribute.key.name
89
- : attribute.key.value;
90
- result[key] = attribute.value.value;
104
+ /** @type {string} */
105
+ (
106
+ attribute.key.type === "Identifier"
107
+ ? attribute.key.name
108
+ : attribute.key.value
109
+ );
110
+ result[key] = /** @type {string} */ (attribute.value.value);
111
+ }
112
+ if (isImportAssertion) {
113
+ result._isLegacyAssert = true;
91
114
  }
92
115
  return result;
93
116
  }
@@ -16,7 +16,7 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
16
16
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
17
17
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
18
18
  /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
19
- /** @typedef {import("../javascript/JavascriptParser").Attributes} Attributes */
19
+ /** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
20
20
  /** @typedef {import("../util/Hash")} Hash */
21
21
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
22
22
 
@@ -24,7 +24,7 @@ class HarmonyImportSideEffectDependency extends HarmonyImportDependency {
24
24
  /**
25
25
  * @param {string} request the request string
26
26
  * @param {number} sourceOrder source order
27
- * @param {Attributes=} attributes assertions
27
+ * @param {ImportAttributes=} attributes import attributes
28
28
  */
29
29
  constructor(request, sourceOrder, attributes) {
30
30
  super(request, sourceOrder, attributes);
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const Dependency = require("../Dependency");
9
+ const Template = require("../Template");
9
10
  const {
10
11
  getDependencyUsedByExportsCondition
11
12
  } = require("../optimize/InnerGraph");
@@ -27,7 +28,8 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
27
28
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
28
29
  /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
29
30
  /** @typedef {import("../WebpackError")} WebpackError */
30
- /** @typedef {import("../javascript/JavascriptParser").Attributes} Attributes */
31
+ /** @typedef {import("../javascript/JavascriptParser").DestructuringAssignmentProperty} DestructuringAssignmentProperty */
32
+ /** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
31
33
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
32
34
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
33
35
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
@@ -46,8 +48,8 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
46
48
  * @param {string} name name
47
49
  * @param {Range} range range
48
50
  * @param {TODO} exportPresenceMode export presence mode
49
- * @param {Attributes=} attributes assertions
50
- * @param {Range[]=} idRanges ranges for members of ids; the two arrays are right-aligned
51
+ * @param {ImportAttributes | undefined} attributes import attributes
52
+ * @param {Range[] | undefined} idRanges ranges for members of ids; the two arrays are right-aligned
51
53
  */
52
54
  constructor(
53
55
  request,
@@ -73,7 +75,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
73
75
  this.asiSafe = undefined;
74
76
  /** @type {Set<string> | boolean | undefined} */
75
77
  this.usedByExports = undefined;
76
- /** @type {Set<string> | undefined} */
78
+ /** @type {Set<DestructuringAssignmentProperty> | undefined} */
77
79
  this.referencedPropertiesInDestructuring = undefined;
78
80
  }
79
81
 
@@ -144,8 +146,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
144
146
  */
145
147
  getReferencedExports(moduleGraph, runtime) {
146
148
  let ids = this.getIds(moduleGraph);
147
- if (ids.length === 0)
148
- return this._getReferencedExportsInDestructuring(moduleGraph);
149
+ if (ids.length === 0) return this._getReferencedExportsInDestructuring();
149
150
  let namespaceObjectAsContext = this.namespaceObjectAsContext;
150
151
  if (ids[0] === "default") {
151
152
  const selfModule = moduleGraph.getParentModule(this);
@@ -162,7 +163,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
162
163
  case "default-only":
163
164
  case "default-with-named":
164
165
  if (ids.length === 1)
165
- return this._getReferencedExportsInDestructuring(moduleGraph);
166
+ return this._getReferencedExportsInDestructuring();
166
167
  ids = ids.slice(1);
167
168
  namespaceObjectAsContext = true;
168
169
  break;
@@ -180,31 +181,19 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
180
181
  ids = ids.slice(0, -1);
181
182
  }
182
183
 
183
- return this._getReferencedExportsInDestructuring(moduleGraph, ids);
184
+ return this._getReferencedExportsInDestructuring(ids);
184
185
  }
185
186
 
186
187
  /**
187
- * @param {ModuleGraph} moduleGraph module graph
188
188
  * @param {string[]=} ids ids
189
- * @returns {(string[] | ReferencedExport)[]} referenced exports
189
+ * @returns {string[][]} referenced exports
190
190
  */
191
- _getReferencedExportsInDestructuring(moduleGraph, ids) {
191
+ _getReferencedExportsInDestructuring(ids) {
192
192
  if (this.referencedPropertiesInDestructuring) {
193
- /** @type {ReferencedExport[]} */
193
+ /** @type {string[][]} */
194
194
  const refs = [];
195
- const importedModule = moduleGraph.getModule(this);
196
- const canMangle =
197
- Array.isArray(ids) &&
198
- ids.length > 0 &&
199
- !moduleGraph
200
- .getExportsInfo(importedModule)
201
- .getExportInfo(ids[0])
202
- .isReexport();
203
- for (const key of this.referencedPropertiesInDestructuring) {
204
- refs.push({
205
- name: ids ? ids.concat([key]) : [key],
206
- canMangle
207
- });
195
+ for (const { id } of this.referencedPropertiesInDestructuring) {
196
+ refs.push(ids ? ids.concat([id]) : [id]);
208
197
  }
209
198
  return refs;
210
199
  } else {
@@ -336,16 +325,11 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
336
325
  // Skip rendering depending when dependency is conditional
337
326
  if (connection && !connection.isTargetActive(runtime)) return;
338
327
 
328
+ const ids = dep.getIds(moduleGraph);
339
329
  const {
340
330
  trimmedRange: [trimmedRangeStart, trimmedRangeEnd],
341
331
  trimmedIds
342
- } = getTrimmedIdsAndRange(
343
- dep.getIds(moduleGraph),
344
- dep.range,
345
- dep.idRanges,
346
- moduleGraph,
347
- dep
348
- );
332
+ } = getTrimmedIdsAndRange(ids, dep.range, dep.idRanges, moduleGraph, dep);
349
333
 
350
334
  const exportExpr = this._getCodeForIds(
351
335
  dep,
@@ -358,6 +342,33 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
358
342
  } else {
359
343
  source.replace(trimmedRangeStart, trimmedRangeEnd - 1, exportExpr);
360
344
  }
345
+
346
+ if (dep.referencedPropertiesInDestructuring) {
347
+ for (let {
348
+ id,
349
+ shorthand,
350
+ range
351
+ } of dep.referencedPropertiesInDestructuring) {
352
+ const concatedIds = ids.concat([id]);
353
+ if (concatedIds[0] === "default") concatedIds.shift();
354
+ const module = moduleGraph.getModule(dep);
355
+ const used = moduleGraph
356
+ .getExportsInfo(module)
357
+ .getUsedName(concatedIds, runtime);
358
+ if (!used) return;
359
+ const newName = used[used.length - 1];
360
+ const name = concatedIds[concatedIds.length - 1];
361
+ if (newName === name) continue;
362
+
363
+ const comment = Template.toNormalComment(name) + " ";
364
+ const key = comment + JSON.stringify(newName);
365
+ source.replace(
366
+ range[0],
367
+ range[1] - 1,
368
+ shorthand ? `${key}: ${name}` : `${key}`
369
+ );
370
+ }
371
+ }
361
372
  }
362
373
 
363
374
  /**
@@ -16,7 +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
+ /** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
20
20
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
21
21
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
22
22
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
@@ -27,7 +27,7 @@ class ImportDependency extends ModuleDependency {
27
27
  * @param {string} request the request
28
28
  * @param {Range} range expression range
29
29
  * @param {(string[][] | null)=} referencedExports list of referenced exports
30
- * @param {Attributes=} attributes assertions
30
+ * @param {ImportAttributes=} attributes import attributes
31
31
  */
32
32
  constructor(request, range, referencedExports, attributes) {
33
33
  super(request);
@@ -15,7 +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
+ /** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
19
19
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
20
20
 
21
21
  class ImportEagerDependency extends ImportDependency {
@@ -23,7 +23,7 @@ class ImportEagerDependency extends ImportDependency {
23
23
  * @param {string} request the request
24
24
  * @param {Range} range expression range
25
25
  * @param {(string[][] | null)=} referencedExports list of referenced exports
26
- * @param {Attributes=} attributes assertions
26
+ * @param {ImportAttributes=} attributes import attributes
27
27
  */
28
28
  constructor(request, range, referencedExports, attributes) {
29
29
  super(request, range, referencedExports, attributes);
@@ -131,7 +131,7 @@ class ImportMetaPlugin {
131
131
  }
132
132
 
133
133
  let str = "";
134
- for (const prop of referencedPropertiesInDestructuring) {
134
+ for (const { id: prop } of referencedPropertiesInDestructuring) {
135
135
  switch (prop) {
136
136
  case "url":
137
137
  str += `url: ${importMetaUrl()},`;
@@ -256,7 +256,9 @@ class ImportParserPlugin {
256
256
  )
257
257
  );
258
258
  }
259
- exports = exportsFromEnumerable(referencedPropertiesInDestructuring);
259
+ exports = exportsFromEnumerable(
260
+ [...referencedPropertiesInDestructuring].map(({ id }) => id)
261
+ );
260
262
  }
261
263
 
262
264
  if (param.isString()) {
@@ -15,7 +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
+ /** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
19
19
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
20
20
 
21
21
  class ImportWeakDependency extends ImportDependency {
@@ -23,7 +23,7 @@ class ImportWeakDependency extends ImportDependency {
23
23
  * @param {string} request the request
24
24
  * @param {Range} range expression range
25
25
  * @param {(string[][] | null)=} referencedExports list of referenced exports
26
- * @param {Attributes=} attributes assertions
26
+ * @param {ImportAttributes=} attributes import attributes
27
27
  */
28
28
  constructor(request, range, referencedExports, attributes) {
29
29
  super(request, range, referencedExports, attributes);
@@ -29,7 +29,7 @@ const LoaderImportDependency = require("./LoaderImportDependency");
29
29
  */
30
30
 
31
31
  /**
32
- * @typedef {Object} ImportModuleOptions
32
+ * @typedef {object} ImportModuleOptions
33
33
  * @property {string=} layer the target layer
34
34
  * @property {string=} publicPath the target public path
35
35
  * @property {string=} baseUri target base uri
@@ -37,7 +37,7 @@ const LoaderImportDependency = require("./LoaderImportDependency");
37
37
 
38
38
  class LoaderPlugin {
39
39
  /**
40
- * @param {Object} options options
40
+ * @param {object} options options
41
41
  */
42
42
  constructor(options = {}) {}
43
43
 
@@ -11,7 +11,7 @@ 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
+ /** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
15
15
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
16
16
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
17
17
 
@@ -26,7 +26,7 @@ class ModuleDependency extends Dependency {
26
26
  this.range = undefined;
27
27
  // TODO move it to subclasses and rename
28
28
  // assertions must be serialized by subclasses that use it
29
- /** @type {Attributes | undefined} */
29
+ /** @type {ImportAttributes | undefined} */
30
30
  this.assertions = undefined;
31
31
  this._context = undefined;
32
32
  }
@@ -7,12 +7,13 @@
7
7
 
8
8
  const { UsageState } = require("../ExportsInfo");
9
9
  const makeSerializable = require("../util/makeSerializable");
10
- const { filterRuntime, deepMergeRuntime } = require("../util/runtime");
10
+ const { filterRuntime, runtimeToString } = require("../util/runtime");
11
11
  const NullDependency = require("./NullDependency");
12
12
 
13
13
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
14
14
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
15
15
  /** @typedef {import("../Dependency")} Dependency */
16
+ /** @typedef {import("../Dependency").RuntimeSpec} RuntimeSpec */
16
17
  /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
17
18
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
18
19
  /** @typedef {import("../Module")} Module */
@@ -32,7 +33,31 @@ class PureExpressionDependency extends NullDependency {
32
33
  this.range = range;
33
34
  /** @type {Set<string> | false} */
34
35
  this.usedByExports = false;
35
- this._hashUpdate = undefined;
36
+ }
37
+
38
+ /**
39
+ * @param {ModuleGraph} moduleGraph module graph
40
+ * @param {RuntimeSpec} runtime current runtimes
41
+ * @returns {boolean | RuntimeSpec} runtime condition
42
+ */
43
+ _getRuntimeCondition(moduleGraph, runtime) {
44
+ const usedByExports = this.usedByExports;
45
+ if (usedByExports !== false) {
46
+ const selfModule =
47
+ /** @type {Module} */
48
+ (moduleGraph.getParentModule(this));
49
+ const exportsInfo = moduleGraph.getExportsInfo(selfModule);
50
+ const runtimeCondition = filterRuntime(runtime, runtime => {
51
+ for (const exportName of usedByExports) {
52
+ if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused) {
53
+ return true;
54
+ }
55
+ }
56
+ return false;
57
+ });
58
+ return runtimeCondition;
59
+ }
60
+ return false;
36
61
  }
37
62
 
38
63
  /**
@@ -42,10 +67,22 @@ class PureExpressionDependency extends NullDependency {
42
67
  * @returns {void}
43
68
  */
44
69
  updateHash(hash, context) {
45
- if (this._hashUpdate === undefined) {
46
- this._hashUpdate = this.range + "";
70
+ const runtimeCondition = this._getRuntimeCondition(
71
+ context.chunkGraph.moduleGraph,
72
+ context.runtime
73
+ );
74
+ if (runtimeCondition === true) {
75
+ return;
76
+ } else if (runtimeCondition === false) {
77
+ hash.update("null");
78
+ } else {
79
+ hash.update(
80
+ runtimeToString(runtimeCondition) +
81
+ "|" +
82
+ runtimeToString(context.runtime)
83
+ );
47
84
  }
48
- hash.update(this._hashUpdate);
85
+ hash.update(this.range + "");
49
86
  }
50
87
 
51
88
  /**
@@ -94,54 +131,31 @@ PureExpressionDependency.Template = class PureExpressionDependencyTemplate exten
94
131
  apply(
95
132
  dependency,
96
133
  source,
97
- {
98
- chunkGraph,
99
- moduleGraph,
100
- runtime,
101
- runtimes,
102
- runtimeTemplate,
103
- runtimeRequirements
104
- }
134
+ { chunkGraph, moduleGraph, runtime, runtimeTemplate, runtimeRequirements }
105
135
  ) {
106
136
  const dep = /** @type {PureExpressionDependency} */ (dependency);
107
-
108
- const usedByExports = dep.usedByExports;
109
- if (usedByExports !== false) {
110
- const selfModule =
111
- /** @type {Module} */
112
- (moduleGraph.getParentModule(dep));
113
- const exportsInfo = moduleGraph.getExportsInfo(selfModule);
114
- const merged = deepMergeRuntime(runtimes, runtime);
115
- const runtimeCondition = filterRuntime(merged, runtime => {
116
- for (const exportName of usedByExports) {
117
- if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused) {
118
- return true;
119
- }
120
- }
121
- return false;
137
+ const runtimeCondition = dep._getRuntimeCondition(moduleGraph, runtime);
138
+ if (runtimeCondition === true) {
139
+ return;
140
+ } else if (runtimeCondition === false) {
141
+ source.insert(
142
+ dep.range[0],
143
+ `(/* unused pure expression or super */ null && (`
144
+ );
145
+ source.insert(dep.range[1], "))");
146
+ } else {
147
+ const condition = runtimeTemplate.runtimeConditionExpression({
148
+ chunkGraph,
149
+ runtime,
150
+ runtimeCondition,
151
+ runtimeRequirements
122
152
  });
123
- if (runtimeCondition === true) return;
124
- if (runtimeCondition !== false) {
125
- const condition = runtimeTemplate.runtimeConditionExpression({
126
- chunkGraph,
127
- runtime: merged,
128
- runtimeCondition,
129
- runtimeRequirements
130
- });
131
- source.insert(
132
- dep.range[0],
133
- `(/* runtime-dependent pure expression or super */ ${condition} ? (`
134
- );
135
- source.insert(dep.range[1], ") : null)");
136
- return;
137
- }
153
+ source.insert(
154
+ dep.range[0],
155
+ `(/* runtime-dependent pure expression or super */ ${condition} ? (`
156
+ );
157
+ source.insert(dep.range[1], ") : null)");
138
158
  }
139
-
140
- source.insert(
141
- dep.range[0],
142
- `(/* unused pure expression or super */ null && (`
143
- );
144
- source.insert(dep.range[1], "))");
145
159
  }
146
160
  };
147
161
 
@@ -28,7 +28,7 @@ class WorkerDependency extends ModuleDependency {
28
28
  /**
29
29
  * @param {string} request request
30
30
  * @param {Range} range range
31
- * @param {Object} workerDependencyOptions options
31
+ * @param {object} workerDependencyOptions options
32
32
  * @param {string=} workerDependencyOptions.publicPath public path for the worker
33
33
  */
34
34
  constructor(request, range, workerDependencyOptions) {