webpack 5.94.0 → 5.96.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.
Files changed (151) hide show
  1. package/README.md +1 -1
  2. package/lib/AsyncDependenciesBlock.js +1 -1
  3. package/lib/BannerPlugin.js +2 -1
  4. package/lib/Chunk.js +30 -0
  5. package/lib/ChunkGraph.js +11 -6
  6. package/lib/ChunkGroup.js +2 -2
  7. package/lib/CleanPlugin.js +4 -5
  8. package/lib/CodeGenerationResults.js +6 -5
  9. package/lib/Compilation.js +71 -48
  10. package/lib/Compiler.js +7 -5
  11. package/lib/ConcatenationScope.js +7 -20
  12. package/lib/ContextModule.js +7 -8
  13. package/lib/CssModule.js +25 -21
  14. package/lib/DefinePlugin.js +14 -8
  15. package/lib/DelegatedModule.js +3 -3
  16. package/lib/DllModule.js +4 -4
  17. package/lib/DynamicEntryPlugin.js +29 -22
  18. package/lib/EnvironmentPlugin.js +3 -2
  19. package/lib/EvalDevToolModulePlugin.js +5 -2
  20. package/lib/EvalSourceMapDevToolPlugin.js +5 -2
  21. package/lib/ExternalModule.js +118 -99
  22. package/lib/ExternalModuleFactoryPlugin.js +33 -9
  23. package/lib/FileSystemInfo.js +12 -8
  24. package/lib/Generator.js +5 -4
  25. package/lib/HotModuleReplacementPlugin.js +8 -6
  26. package/lib/IgnorePlugin.js +19 -1
  27. package/lib/LoaderOptionsPlugin.js +3 -1
  28. package/lib/Module.js +9 -8
  29. package/lib/ModuleSourceTypesConstants.js +100 -0
  30. package/lib/NormalModule.js +27 -13
  31. package/lib/NormalModuleFactory.js +38 -22
  32. package/lib/OptionsApply.js +12 -1
  33. package/lib/ProgressPlugin.js +50 -10
  34. package/lib/RawModule.js +3 -4
  35. package/lib/RuntimeModule.js +3 -4
  36. package/lib/RuntimePlugin.js +11 -4
  37. package/lib/RuntimeTemplate.js +13 -42
  38. package/lib/SourceMapDevToolPlugin.js +10 -7
  39. package/lib/TemplatedPathPlugin.js +9 -3
  40. package/lib/Watching.js +2 -2
  41. package/lib/WebpackOptionsApply.js +42 -21
  42. package/lib/asset/AssetGenerator.js +347 -194
  43. package/lib/asset/AssetModulesPlugin.js +2 -1
  44. package/lib/asset/AssetSourceGenerator.js +82 -27
  45. package/lib/asset/RawDataUrlModule.js +5 -4
  46. package/lib/buildChunkGraph.js +79 -62
  47. package/lib/cache/PackFileCacheStrategy.js +69 -31
  48. package/lib/cache/ResolverCachePlugin.js +248 -173
  49. package/lib/config/defaults.js +135 -126
  50. package/lib/container/ContainerEntryModule.js +3 -4
  51. package/lib/container/ContainerPlugin.js +8 -0
  52. package/lib/container/FallbackModule.js +2 -2
  53. package/lib/container/HoistContainerReferencesPlugin.js +250 -0
  54. package/lib/container/ModuleFederationPlugin.js +38 -1
  55. package/lib/container/RemoteModule.js +4 -2
  56. package/lib/container/RemoteRuntimeModule.js +4 -2
  57. package/lib/css/CssExportsGenerator.js +16 -12
  58. package/lib/css/CssGenerator.js +22 -16
  59. package/lib/css/CssLoadingRuntimeModule.js +7 -6
  60. package/lib/css/CssModulesPlugin.js +122 -77
  61. package/lib/css/CssParser.js +655 -526
  62. package/lib/css/walkCssTokens.js +1168 -338
  63. package/lib/debug/ProfilingPlugin.js +5 -0
  64. package/lib/dependencies/CommonJsExportsParserPlugin.js +5 -2
  65. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -6
  66. package/lib/dependencies/ContextDependency.js +6 -1
  67. package/lib/dependencies/ContextElementDependency.js +33 -6
  68. package/lib/dependencies/CssExportDependency.js +3 -3
  69. package/lib/dependencies/CssLocalIdentifierDependency.js +26 -17
  70. package/lib/dependencies/CssUrlDependency.js +33 -3
  71. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
  72. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +39 -14
  73. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +15 -82
  74. package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -2
  75. package/lib/dependencies/ImportParserPlugin.js +9 -7
  76. package/lib/dependencies/LoaderPlugin.js +19 -0
  77. package/lib/dependencies/SystemPlugin.js +2 -1
  78. package/lib/dependencies/URLPlugin.js +7 -1
  79. package/lib/dependencies/WorkerPlugin.js +1 -1
  80. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +4 -2
  81. package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
  82. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
  83. package/lib/hmr/LazyCompilationPlugin.js +16 -4
  84. package/lib/hmr/lazyCompilationBackend.js +1 -7
  85. package/lib/index.js +35 -6
  86. package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
  87. package/lib/javascript/JavascriptGenerator.js +8 -8
  88. package/lib/javascript/JavascriptModulesPlugin.js +166 -88
  89. package/lib/javascript/JavascriptParser.js +338 -117
  90. package/lib/json/JsonGenerator.js +5 -5
  91. package/lib/library/EnableLibraryPlugin.js +2 -2
  92. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  93. package/lib/library/UmdLibraryPlugin.js +16 -8
  94. package/lib/logging/Logger.js +11 -11
  95. package/lib/logging/createConsoleLogger.js +14 -14
  96. package/lib/logging/truncateArgs.js +1 -1
  97. package/lib/node/NodeWatchFileSystem.js +3 -1
  98. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +20 -18
  99. package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
  100. package/lib/node/nodeConsole.js +11 -8
  101. package/lib/optimize/AggressiveSplittingPlugin.js +21 -7
  102. package/lib/optimize/ConcatenatedModule.js +44 -148
  103. package/lib/optimize/FlagIncludedChunksPlugin.js +6 -0
  104. package/lib/optimize/InnerGraphPlugin.js +57 -16
  105. package/lib/optimize/LimitChunkCountPlugin.js +2 -4
  106. package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
  107. package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
  108. package/lib/optimize/RealContentHashPlugin.js +1 -1
  109. package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
  110. package/lib/rules/RuleSetCompiler.js +2 -2
  111. package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -2
  112. package/lib/schemes/DataUriPlugin.js +1 -1
  113. package/lib/serialization/BinaryMiddleware.js +32 -19
  114. package/lib/serialization/ObjectMiddleware.js +23 -9
  115. package/lib/serialization/SerializerMiddleware.js +3 -2
  116. package/lib/serialization/types.js +2 -2
  117. package/lib/sharing/ConsumeSharedModule.js +2 -3
  118. package/lib/sharing/ConsumeSharedRuntimeModule.js +3 -1
  119. package/lib/sharing/ProvideSharedModule.js +2 -3
  120. package/lib/stats/DefaultStatsFactoryPlugin.js +22 -20
  121. package/lib/stats/StatsFactory.js +12 -12
  122. package/lib/stats/StatsPrinter.js +7 -7
  123. package/lib/util/AsyncQueue.js +17 -1
  124. package/lib/util/IterableHelpers.js +1 -1
  125. package/lib/util/LazySet.js +12 -0
  126. package/lib/util/SetHelpers.js +1 -1
  127. package/lib/util/cleverMerge.js +48 -24
  128. package/lib/util/concatenate.js +227 -0
  129. package/lib/util/create-schema-validation.js +22 -9
  130. package/lib/util/deprecation.js +86 -28
  131. package/lib/util/fs.js +10 -10
  132. package/lib/util/hash/wasm-hash.js +12 -1
  133. package/lib/util/magicComment.js +21 -0
  134. package/lib/util/makeSerializable.js +24 -1
  135. package/lib/util/memoize.js +2 -1
  136. package/lib/util/runtime.js +10 -1
  137. package/lib/util/semver.js +130 -23
  138. package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
  139. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  140. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +5 -5
  141. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -5
  142. package/lib/wasm-sync/WebAssemblyGenerator.js +8 -9
  143. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -5
  144. package/lib/web/FetchCompileAsyncWasmPlugin.js +1 -2
  145. package/lib/web/FetchCompileWasmPlugin.js +1 -2
  146. package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
  147. package/package.json +19 -20
  148. package/schemas/WebpackOptions.check.js +1 -1
  149. package/schemas/WebpackOptions.json +12 -2
  150. package/types.d.ts +817 -269
  151. package/lib/util/mergeScope.js +0 -76
@@ -16,6 +16,7 @@ const {
16
16
  const ConcatenationScope = require("../ConcatenationScope");
17
17
  const { UsageState } = require("../ExportsInfo");
18
18
  const Module = require("../Module");
19
+ const { JS_TYPES } = require("../ModuleSourceTypesConstants");
19
20
  const { JAVASCRIPT_MODULE_TYPE_ESM } = require("../ModuleTypeConstants");
20
21
  const RuntimeGlobals = require("../RuntimeGlobals");
21
22
  const Template = require("../Template");
@@ -24,10 +25,17 @@ const JavascriptParser = require("../javascript/JavascriptParser");
24
25
  const { equals } = require("../util/ArrayHelpers");
25
26
  const LazySet = require("../util/LazySet");
26
27
  const { concatComparators } = require("../util/comparators");
28
+ const {
29
+ RESERVED_NAMES,
30
+ findNewName,
31
+ addScopeSymbols,
32
+ getAllReferences,
33
+ getPathInAst,
34
+ getUsedNamesInScopeInfo
35
+ } = require("../util/concatenate");
27
36
  const createHash = require("../util/createHash");
28
37
  const { makePathsRelative } = require("../util/identifier");
29
38
  const makeSerializable = require("../util/makeSerializable");
30
- const { getAllReferences, getPathInAst } = require("../util/mergeScope");
31
39
  const propertyAccess = require("../util/propertyAccess");
32
40
  const { propertyName } = require("../util/propertyName");
33
41
  const {
@@ -58,6 +66,7 @@ const {
58
66
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
59
67
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
60
68
  /** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
69
+ /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
61
70
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
62
71
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
63
72
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
@@ -73,6 +82,7 @@ const {
73
82
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
74
83
  /** @typedef {import("../util/Hash")} Hash */
75
84
  /** @typedef {typeof import("../util/Hash")} HashConstructor */
85
+ /** @typedef {import("../util/concatenate").UsedNames} UsedNames */
76
86
  /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
77
87
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
78
88
 
@@ -130,7 +140,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
130
140
  * @property {number} index
131
141
  * @property {Program | undefined} ast
132
142
  * @property {Source | undefined} internalSource
133
- * @property {ReplaceSource} source
143
+ * @property {ReplaceSource | undefined} source
134
144
  * @property {InitFragment<ChunkRenderContext>[]=} chunkInitFragments
135
145
  * @property {ReadOnlyRuntimeRequirements | undefined} runtimeRequirements
136
146
  * @property {Scope | undefined} globalScope
@@ -167,55 +177,16 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
167
177
  * @typedef {object} ReferenceToModuleInfo
168
178
  * @property {"reference"} type
169
179
  * @property {RuntimeSpec | boolean} runtimeCondition
170
- * @property {ConcatenatedModuleInfo | ExternalModuleInfo} target
180
+ * @property {ModuleInfo} target
171
181
  */
172
182
 
173
- /** @typedef {Set<string>} UsedNames */
174
-
175
- const RESERVED_NAMES = new Set(
176
- [
177
- // internal names (should always be renamed)
178
- ConcatenationScope.DEFAULT_EXPORT,
179
- ConcatenationScope.NAMESPACE_OBJECT_EXPORT,
180
-
181
- // keywords
182
- "abstract,arguments,async,await,boolean,break,byte,case,catch,char,class,const,continue",
183
- "debugger,default,delete,do,double,else,enum,eval,export,extends,false,final,finally,float",
184
- "for,function,goto,if,implements,import,in,instanceof,int,interface,let,long,native,new,null",
185
- "package,private,protected,public,return,short,static,super,switch,synchronized,this,throw",
186
- "throws,transient,true,try,typeof,var,void,volatile,while,with,yield",
187
-
188
- // commonjs/amd
189
- "module,__dirname,__filename,exports,require,define",
190
-
191
- // js globals
192
- "Array,Date,eval,function,hasOwnProperty,Infinity,isFinite,isNaN,isPrototypeOf,length,Math",
193
- "NaN,name,Number,Object,prototype,String,toString,undefined,valueOf",
194
-
195
- // browser globals
196
- "alert,all,anchor,anchors,area,assign,blur,button,checkbox,clearInterval,clearTimeout",
197
- "clientInformation,close,closed,confirm,constructor,crypto,decodeURI,decodeURIComponent",
198
- "defaultStatus,document,element,elements,embed,embeds,encodeURI,encodeURIComponent,escape",
199
- "event,fileUpload,focus,form,forms,frame,innerHeight,innerWidth,layer,layers,link,location",
200
- "mimeTypes,navigate,navigator,frames,frameRate,hidden,history,image,images,offscreenBuffering",
201
- "open,opener,option,outerHeight,outerWidth,packages,pageXOffset,pageYOffset,parent,parseFloat",
202
- "parseInt,password,pkcs11,plugin,prompt,propertyIsEnum,radio,reset,screenX,screenY,scroll",
203
- "secure,select,self,setInterval,setTimeout,status,submit,taint,text,textarea,top,unescape",
204
- "untaint,window",
205
-
206
- // window events
207
- "onblur,onclick,onerror,onfocus,onkeydown,onkeypress,onkeyup,onmouseover,onload,onmouseup,onmousedown,onsubmit"
208
- ]
209
- .join(",")
210
- .split(",")
211
- );
212
-
213
183
  /**
214
184
  * @template T
215
185
  * @param {string} property property
216
186
  * @param {function(T[keyof T], T[keyof T]): 0 | 1 | -1} comparator comparator
217
187
  * @returns {Comparator<T>} comparator
218
188
  */
189
+
219
190
  const createComparator = (property, comparator) => (a, b) =>
220
191
  comparator(
221
192
  a[/** @type {keyof T} */ (property)],
@@ -627,30 +598,9 @@ const getFinalName = (
627
598
  }
628
599
  };
629
600
 
630
- /**
631
- * @param {Scope | null} s scope
632
- * @param {UsedNames} nameSet name set
633
- * @param {TODO} scopeSet1 scope set 1
634
- * @param {TODO} scopeSet2 scope set 2
635
- */
636
- const addScopeSymbols = (s, nameSet, scopeSet1, scopeSet2) => {
637
- let scope = s;
638
- while (scope) {
639
- if (scopeSet1.has(scope)) break;
640
- if (scopeSet2.has(scope)) break;
641
- scopeSet1.add(scope);
642
- for (const variable of scope.variables) {
643
- nameSet.add(variable.name);
644
- }
645
- scope = scope.upper;
646
- }
647
- };
648
-
649
- const TYPES = new Set(["javascript"]);
650
-
651
601
  /**
652
602
  * @typedef {object} ConcatenateModuleHooks
653
- * @property {SyncBailHook<[Record<string, string>], boolean>} exportsDefinitions
603
+ * @property {SyncBailHook<[Record<string, string>], boolean | void>} exportsDefinitions
654
604
  */
655
605
 
656
606
  /** @type {WeakMap<Compilation, ConcatenateModuleHooks>} */
@@ -707,9 +657,9 @@ class ConcatenatedModule extends Module {
707
657
  /**
708
658
  * @param {object} options options
709
659
  * @param {string} options.identifier the identifier of the module
710
- * @param {Module=} options.rootModule the root module of the concatenation
660
+ * @param {Module} options.rootModule the root module of the concatenation
711
661
  * @param {RuntimeSpec} options.runtime the selected runtime
712
- * @param {Set<Module>=} options.modules all concatenated modules
662
+ * @param {Set<Module>} options.modules all concatenated modules
713
663
  * @param {Compilation} options.compilation the compilation
714
664
  */
715
665
  constructor({ identifier, rootModule, modules, runtime, compilation }) {
@@ -743,7 +693,7 @@ class ConcatenatedModule extends Module {
743
693
  * @returns {SourceTypes} types available (do not mutate)
744
694
  */
745
695
  getSourceTypes() {
746
- return TYPES;
696
+ return JS_TYPES;
747
697
  }
748
698
 
749
699
  get modules() {
@@ -1148,7 +1098,7 @@ class ConcatenatedModule extends Module {
1148
1098
  runtime: generationRuntime,
1149
1099
  codeGenerationResults
1150
1100
  }) {
1151
- /** @type {Set<string>} */
1101
+ /** @type {RuntimeRequirements} */
1152
1102
  const runtimeRequirements = new Set();
1153
1103
  const runtime = intersectRuntime(generationRuntime, this._runtime);
1154
1104
 
@@ -1174,7 +1124,8 @@ class ConcatenatedModule extends Module {
1174
1124
  moduleGraph,
1175
1125
  chunkGraph,
1176
1126
  runtime,
1177
- codeGenerationResults
1127
+ /** @type {CodeGenerationResults} */
1128
+ (codeGenerationResults)
1178
1129
  );
1179
1130
  }
1180
1131
 
@@ -1191,18 +1142,6 @@ class ConcatenatedModule extends Module {
1191
1142
  * @param {string} id export id
1192
1143
  * @returns {{ usedNames: UsedNames, alreadyCheckedScopes: Set<TODO> }} info
1193
1144
  */
1194
- const getUsedNamesInScopeInfo = (module, id) => {
1195
- const key = `${module}-${id}`;
1196
- let info = usedNamesInScopeInfo.get(key);
1197
- if (info === undefined) {
1198
- info = {
1199
- usedNames: new Set(),
1200
- alreadyCheckedScopes: new Set()
1201
- };
1202
- usedNamesInScopeInfo.set(key, info);
1203
- }
1204
- return info;
1205
- };
1206
1145
 
1207
1146
  // Set of already checked scopes
1208
1147
  const ignoredScopes = new Set();
@@ -1272,6 +1211,7 @@ class ConcatenatedModule extends Module {
1272
1211
  if (!binding.ids) continue;
1273
1212
  const { usedNames, alreadyCheckedScopes } =
1274
1213
  getUsedNamesInScopeInfo(
1214
+ usedNamesInScopeInfo,
1275
1215
  binding.info.module.identifier(),
1276
1216
  "name" in binding ? binding.name : ""
1277
1217
  );
@@ -1304,14 +1244,17 @@ class ConcatenatedModule extends Module {
1304
1244
  // generate names for symbols
1305
1245
  for (const info of moduleToInfoMap.values()) {
1306
1246
  const { usedNames: namespaceObjectUsedNames } = getUsedNamesInScopeInfo(
1247
+ usedNamesInScopeInfo,
1307
1248
  info.module.identifier(),
1308
1249
  ""
1309
1250
  );
1310
1251
  switch (info.type) {
1311
1252
  case "concatenated": {
1312
- for (const variable of info.moduleScope.variables) {
1253
+ const variables = /** @type {Scope} */ (info.moduleScope).variables;
1254
+ for (const variable of variables) {
1313
1255
  const name = variable.name;
1314
1256
  const { usedNames, alreadyCheckedScopes } = getUsedNamesInScopeInfo(
1257
+ usedNamesInScopeInfo,
1315
1258
  info.module.identifier(),
1316
1259
  name
1317
1260
  );
@@ -1325,7 +1268,7 @@ class ConcatenatedModule extends Module {
1325
1268
  ignoredScopes
1326
1269
  );
1327
1270
  }
1328
- const newName = this.findNewName(
1271
+ const newName = findNewName(
1329
1272
  name,
1330
1273
  allUsedNames,
1331
1274
  usedNames,
@@ -1334,7 +1277,7 @@ class ConcatenatedModule extends Module {
1334
1277
  allUsedNames.add(newName);
1335
1278
  info.internalNames.set(name, newName);
1336
1279
  topLevelDeclarations.add(newName);
1337
- const source = info.source;
1280
+ const source = /** @type {ReplaceSource} */ (info.source);
1338
1281
  const allIdentifiers = new Set(
1339
1282
  references.map(r => r.identifier).concat(variable.identifiers)
1340
1283
  );
@@ -1373,7 +1316,7 @@ class ConcatenatedModule extends Module {
1373
1316
  info.namespaceExportSymbol
1374
1317
  );
1375
1318
  } else {
1376
- namespaceObjectName = this.findNewName(
1319
+ namespaceObjectName = findNewName(
1377
1320
  "namespaceObject",
1378
1321
  allUsedNames,
1379
1322
  namespaceObjectUsedNames,
@@ -1388,7 +1331,7 @@ class ConcatenatedModule extends Module {
1388
1331
  break;
1389
1332
  }
1390
1333
  case "external": {
1391
- const externalName = this.findNewName(
1334
+ const externalName = findNewName(
1392
1335
  "",
1393
1336
  allUsedNames,
1394
1337
  namespaceObjectUsedNames,
@@ -1402,7 +1345,7 @@ class ConcatenatedModule extends Module {
1402
1345
  }
1403
1346
  const buildMeta = /** @type {BuildMeta} */ (info.module.buildMeta);
1404
1347
  if (buildMeta.exportsType !== "namespace") {
1405
- const externalNameInterop = this.findNewName(
1348
+ const externalNameInterop = findNewName(
1406
1349
  "namespaceObject",
1407
1350
  allUsedNames,
1408
1351
  namespaceObjectUsedNames,
@@ -1416,7 +1359,7 @@ class ConcatenatedModule extends Module {
1416
1359
  buildMeta.exportsType === "default" &&
1417
1360
  buildMeta.defaultObject !== "redirect"
1418
1361
  ) {
1419
- const externalNameInterop = this.findNewName(
1362
+ const externalNameInterop = findNewName(
1420
1363
  "namespaceObject2",
1421
1364
  allUsedNames,
1422
1365
  namespaceObjectUsedNames,
@@ -1427,7 +1370,7 @@ class ConcatenatedModule extends Module {
1427
1370
  topLevelDeclarations.add(externalNameInterop);
1428
1371
  }
1429
1372
  if (buildMeta.exportsType === "dynamic" || !buildMeta.exportsType) {
1430
- const externalNameInterop = this.findNewName(
1373
+ const externalNameInterop = findNewName(
1431
1374
  "default",
1432
1375
  allUsedNames,
1433
1376
  namespaceObjectUsedNames,
@@ -1466,7 +1409,7 @@ class ConcatenatedModule extends Module {
1466
1409
  match.asiSafe
1467
1410
  );
1468
1411
  const r = /** @type {Range} */ (reference.identifier.range);
1469
- const source = info.source;
1412
+ const source = /** @type {ReplaceSource} */ (info.source);
1470
1413
  // range is extended by 2 chars to cover the appended "._"
1471
1414
  source.replace(r[0], r[1] + 1, finalName);
1472
1415
  }
@@ -1660,11 +1603,9 @@ ${defineGetters}`
1660
1603
  switch (info.type) {
1661
1604
  case "concatenated": {
1662
1605
  result.add(
1663
- `\n;// CONCATENATED MODULE: ${info.module.readableIdentifier(
1664
- requestShortener
1665
- )}\n`
1606
+ `\n;// ${info.module.readableIdentifier(requestShortener)}\n`
1666
1607
  );
1667
- result.add(info.source);
1608
+ result.add(/** @type {ReplaceSource} */ (info.source));
1668
1609
  if (info.chunkInitFragments) {
1669
1610
  for (const f of info.chunkInitFragments) chunkInitFragments.push(f);
1670
1611
  }
@@ -1780,7 +1721,7 @@ ${defineGetters}`
1780
1721
  runtime,
1781
1722
  concatenationScope,
1782
1723
  codeGenerationResults,
1783
- sourceTypes: TYPES
1724
+ sourceTypes: JS_TYPES
1784
1725
  });
1785
1726
  const source = /** @type {Source} */ (
1786
1727
  codeGenResult.sources.get("javascript")
@@ -1818,7 +1759,9 @@ ${defineGetters}`
1818
1759
  const globalScope = /** @type {Scope} */ (scopeManager.acquire(ast));
1819
1760
  const moduleScope = globalScope.childScopes[0];
1820
1761
  const resultSource = new ReplaceSource(source);
1821
- info.runtimeRequirements = codeGenResult.runtimeRequirements;
1762
+ info.runtimeRequirements =
1763
+ /** @type {ReadOnlyRuntimeRequirements} */
1764
+ (codeGenResult.runtimeRequirements);
1822
1765
  info.ast = ast;
1823
1766
  info.internalSource = source;
1824
1767
  info.source = resultSource;
@@ -1913,53 +1856,6 @@ ${defineGetters}`
1913
1856
  return [list, map];
1914
1857
  }
1915
1858
 
1916
- /**
1917
- * @param {string} oldName old name
1918
- * @param {UsedNames} usedNamed1 used named 1
1919
- * @param {UsedNames} usedNamed2 used named 2
1920
- * @param {string} extraInfo extra info
1921
- * @returns {string} found new name
1922
- */
1923
- findNewName(oldName, usedNamed1, usedNamed2, extraInfo) {
1924
- let name = oldName;
1925
-
1926
- if (name === ConcatenationScope.DEFAULT_EXPORT) {
1927
- name = "";
1928
- }
1929
- if (name === ConcatenationScope.NAMESPACE_OBJECT_EXPORT) {
1930
- name = "namespaceObject";
1931
- }
1932
-
1933
- // Remove uncool stuff
1934
- extraInfo = extraInfo.replace(
1935
- /\.+\/|(\/index)?\.([a-zA-Z0-9]{1,4})($|\s|\?)|\s*\+\s*\d+\s*modules/g,
1936
- ""
1937
- );
1938
-
1939
- const splittedInfo = extraInfo.split("/");
1940
- while (splittedInfo.length) {
1941
- name = splittedInfo.pop() + (name ? `_${name}` : "");
1942
- const nameIdent = Template.toIdentifier(name);
1943
- if (
1944
- !usedNamed1.has(nameIdent) &&
1945
- (!usedNamed2 || !usedNamed2.has(nameIdent))
1946
- )
1947
- return nameIdent;
1948
- }
1949
-
1950
- let i = 0;
1951
- let nameWithNumber = Template.toIdentifier(`${name}_${i}`);
1952
- while (
1953
- usedNamed1.has(nameWithNumber) ||
1954
- // eslint-disable-next-line no-unmodified-loop-condition
1955
- (usedNamed2 && usedNamed2.has(nameWithNumber))
1956
- ) {
1957
- i++;
1958
- nameWithNumber = Template.toIdentifier(`${name}_${i}`);
1959
- }
1960
- return nameWithNumber;
1961
- }
1962
-
1963
1859
  /**
1964
1860
  * @param {Hash} hash the hash used to track dependencies
1965
1861
  * @param {UpdateHashContext} context context
@@ -1992,11 +1888,11 @@ ${defineGetters}`
1992
1888
  */
1993
1889
  static deserialize(context) {
1994
1890
  const obj = new ConcatenatedModule({
1995
- identifier: undefined,
1996
- rootModule: undefined,
1997
- modules: undefined,
1891
+ identifier: /** @type {EXPECTED_ANY} */ (undefined),
1892
+ rootModule: /** @type {EXPECTED_ANY} */ (undefined),
1893
+ modules: /** @type {EXPECTED_ANY} */ (undefined),
1998
1894
  runtime: undefined,
1999
- compilation: undefined
1895
+ compilation: /** @type {EXPECTED_ANY} */ (undefined)
2000
1896
  });
2001
1897
  obj.deserialize(context);
2002
1898
  return obj;
@@ -5,6 +5,8 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { compareIds } = require("../util/comparators");
9
+
8
10
  /** @typedef {import("../Chunk")} Chunk */
9
11
  /** @typedef {import("../Chunk").ChunkId} ChunkId */
10
12
  /** @typedef {import("../Compiler")} Compiler */
@@ -112,8 +114,12 @@ class FlagIncludedChunksPlugin {
112
114
  for (const m of chunkGraph.getChunkModulesIterable(chunkA)) {
113
115
  if (!chunkGraph.isModuleInChunk(m, chunkB)) continue loopB;
114
116
  }
117
+
115
118
  /** @type {ChunkId[]} */
116
119
  (chunkB.ids).push(/** @type {ChunkId} */ (chunkA.id));
120
+ // https://github.com/webpack/webpack/issues/18837
121
+ /** @type {ChunkId[]} */
122
+ (chunkB.ids).sort(compareIds);
117
123
  }
118
124
  }
119
125
  }
@@ -12,8 +12,9 @@ const {
12
12
  const PureExpressionDependency = require("../dependencies/PureExpressionDependency");
13
13
  const InnerGraph = require("./InnerGraph");
14
14
 
15
- /** @typedef {import("estree").ClassDeclaration} ClassDeclarationNode */
16
- /** @typedef {import("estree").ClassExpression} ClassExpressionNode */
15
+ /** @typedef {import("estree").ClassDeclaration} ClassDeclaration */
16
+ /** @typedef {import("estree").ClassExpression} ClassExpression */
17
+ /** @typedef {import("estree").Expression} Expression */
17
18
  /** @typedef {import("estree").Node} Node */
18
19
  /** @typedef {import("estree").VariableDeclarator} VariableDeclaratorNode */
19
20
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
@@ -53,6 +54,9 @@ class InnerGraphPlugin {
53
54
  * @returns {void}
54
55
  */
55
56
  const handler = (parser, parserOptions) => {
57
+ /**
58
+ * @param {Expression} sup sup
59
+ */
56
60
  const onUsageSuper = sup => {
57
61
  InnerGraph.onUsage(parser.state, usedByExports => {
58
62
  switch (usedByExports) {
@@ -60,8 +64,11 @@ class InnerGraphPlugin {
60
64
  case true:
61
65
  return;
62
66
  default: {
63
- const dep = new PureExpressionDependency(sup.range);
64
- dep.loc = sup.loc;
67
+ const dep = new PureExpressionDependency(
68
+ /** @type {Range} */
69
+ (sup.range)
70
+ );
71
+ dep.loc = /** @type {DependencyLocation} */ (sup.loc);
65
72
  dep.usedByExports = usedByExports;
66
73
  parser.state.module.addDependency(dep);
67
74
  break;
@@ -96,7 +103,7 @@ class InnerGraphPlugin {
96
103
  /** @type {WeakMap<Node, Node>} */
97
104
  const statementPurePart = new WeakMap();
98
105
 
99
- /** @type {WeakMap<ClassExpressionNode | ClassDeclarationNode, TopLevelSymbol>} */
106
+ /** @type {WeakMap<ClassExpression | ClassDeclaration, TopLevelSymbol>} */
100
107
  const classWithTopLevelSymbol = new WeakMap();
101
108
 
102
109
  /** @type {WeakMap<VariableDeclaratorNode, TopLevelSymbol>} */
@@ -114,7 +121,9 @@ class InnerGraphPlugin {
114
121
  statement.type === "FunctionDeclaration"
115
122
  ) {
116
123
  const name = statement.id ? statement.id.name : "*default*";
117
- const fn = InnerGraph.tagTopLevelSymbol(parser, name);
124
+ const fn =
125
+ /** @type {TopLevelSymbol} */
126
+ (InnerGraph.tagTopLevelSymbol(parser, name));
118
127
  statementWithTopLevelSymbol.set(statement, fn);
119
128
  return true;
120
129
  }
@@ -132,22 +141,40 @@ class InnerGraphPlugin {
132
141
  )
133
142
  ) {
134
143
  const name = statement.id ? statement.id.name : "*default*";
135
- const fn = InnerGraph.tagTopLevelSymbol(parser, name);
144
+ const fn = /** @type {TopLevelSymbol} */ (
145
+ InnerGraph.tagTopLevelSymbol(parser, name)
146
+ );
136
147
  classWithTopLevelSymbol.set(statement, fn);
137
148
  return true;
138
149
  }
139
150
  if (statement.type === "ExportDefaultDeclaration") {
140
151
  const name = "*default*";
141
- const fn = InnerGraph.tagTopLevelSymbol(parser, name);
152
+ const fn =
153
+ /** @type {TopLevelSymbol} */
154
+ (InnerGraph.tagTopLevelSymbol(parser, name));
142
155
  const decl = statement.declaration;
143
156
  if (
144
157
  (decl.type === "ClassExpression" ||
145
158
  decl.type === "ClassDeclaration") &&
146
- parser.isPure(decl, /** @type {Range} */ (decl.range)[0])
159
+ parser.isPure(
160
+ /** @type {ClassExpression | ClassDeclaration} */
161
+ (decl),
162
+ /** @type {Range} */
163
+ (decl.range)[0]
164
+ )
147
165
  ) {
148
- classWithTopLevelSymbol.set(decl, fn);
166
+ classWithTopLevelSymbol.set(
167
+ /** @type {ClassExpression | ClassDeclaration} */
168
+ (decl),
169
+ fn
170
+ );
149
171
  } else if (
150
- parser.isPure(decl, /** @type {Range} */ (statement.range)[0])
172
+ parser.isPure(
173
+ /** @type {Expression} */
174
+ (decl),
175
+ /** @type {Range} */
176
+ (statement.range)[0]
177
+ )
151
178
  ) {
152
179
  statementWithTopLevelSymbol.set(statement, fn);
153
180
  if (
@@ -155,7 +182,11 @@ class InnerGraphPlugin {
155
182
  !decl.type.endsWith("Declaration") &&
156
183
  decl.type !== "Literal"
157
184
  ) {
158
- statementPurePart.set(statement, decl);
185
+ statementPurePart.set(
186
+ statement,
187
+ /** @type {Expression} */
188
+ (decl)
189
+ );
159
190
  }
160
191
  }
161
192
  }
@@ -177,7 +208,9 @@ class InnerGraphPlugin {
177
208
  /** @type {Range} */ (decl.id.range)[1]
178
209
  )
179
210
  ) {
180
- const fn = InnerGraph.tagTopLevelSymbol(parser, name);
211
+ const fn =
212
+ /** @type {TopLevelSymbol} */
213
+ (InnerGraph.tagTopLevelSymbol(parser, name));
181
214
  classWithTopLevelSymbol.set(decl.init, fn);
182
215
  } else if (
183
216
  parser.isPure(
@@ -185,7 +218,9 @@ class InnerGraphPlugin {
185
218
  /** @type {Range} */ (decl.id.range)[1]
186
219
  )
187
220
  ) {
188
- const fn = InnerGraph.tagTopLevelSymbol(parser, name);
221
+ const fn =
222
+ /** @type {TopLevelSymbol} */
223
+ (InnerGraph.tagTopLevelSymbol(parser, name));
189
224
  declWithTopLevelSymbol.set(decl, fn);
190
225
  if (
191
226
  !decl.init.type.endsWith("FunctionExpression") &&
@@ -333,7 +368,10 @@ class InnerGraphPlugin {
333
368
  if (fn) {
334
369
  InnerGraph.setTopLevelSymbol(parser.state, fn);
335
370
  if (pureDeclarators.has(decl)) {
336
- if (decl.init.type === "ClassExpression") {
371
+ if (
372
+ /** @type {ClassExpression} */
373
+ (decl.init).type === "ClassExpression"
374
+ ) {
337
375
  if (decl.init.superClass) {
338
376
  onUsageSuper(decl.init.superClass);
339
377
  }
@@ -345,7 +383,10 @@ class InnerGraphPlugin {
345
383
  return;
346
384
  default: {
347
385
  const dep = new PureExpressionDependency(
348
- /** @type {Range} */ (decl.init.range)
386
+ /** @type {Range} */ (
387
+ /** @type {ClassExpression} */
388
+ (decl.init).range
389
+ )
349
390
  );
350
391
  dep.loc = /** @type {DependencyLocation} */ (decl.loc);
351
392
  dep.usedByExports = usedByExports;
@@ -57,7 +57,7 @@ class LimitChunkCountPlugin {
57
57
  */
58
58
  constructor(options) {
59
59
  validate(options);
60
- this.options = options;
60
+ this.options = /** @type {LimitChunkCountPluginOptions} */ (options);
61
61
  }
62
62
 
63
63
  /**
@@ -74,9 +74,7 @@ class LimitChunkCountPlugin {
74
74
  },
75
75
  chunks => {
76
76
  const chunkGraph = compilation.chunkGraph;
77
- const maxChunks =
78
- /** @type {LimitChunkCountPluginOptions} */
79
- (options).maxChunks;
77
+ const maxChunks = options.maxChunks;
80
78
  if (!maxChunks) return;
81
79
  if (maxChunks < 1) return;
82
80
  if (compilation.chunks.size <= maxChunks) return;
@@ -5,7 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { STAGE_BASIC } = require("../OptimizationStages");
8
+ const { STAGE_ADVANCED } = require("../OptimizationStages");
9
9
  const { runtimeEqual } = require("../util/runtime");
10
10
 
11
11
  /** @typedef {import("../Compiler")} Compiler */
@@ -22,7 +22,7 @@ class MergeDuplicateChunksPlugin {
22
22
  compilation.hooks.optimizeChunks.tap(
23
23
  {
24
24
  name: "MergeDuplicateChunksPlugin",
25
- stage: STAGE_BASIC
25
+ stage: STAGE_ADVANCED
26
26
  },
27
27
  chunks => {
28
28
  const { chunkGraph, moduleGraph } = compilation;
@@ -395,8 +395,10 @@ class ModuleConcatenationPlugin {
395
395
  newModule.build(
396
396
  compiler.options,
397
397
  compilation,
398
- null,
399
- null,
398
+ /** @type {TODO} */
399
+ (null),
400
+ /** @type {TODO} */
401
+ (null),
400
402
  err => {
401
403
  if (err) {
402
404
  if (!err.module) {
@@ -101,7 +101,7 @@ const toCachedSource = source => {
101
101
 
102
102
  /**
103
103
  * @typedef {object} CompilationHooks
104
- * @property {SyncBailHook<[Buffer[], string], string>} updateHash
104
+ * @property {SyncBailHook<[Buffer[], string], string | void>} updateHash
105
105
  */
106
106
 
107
107
  /** @type {WeakMap<Compilation, CompilationHooks>} */
@@ -24,6 +24,7 @@ const formatLocation = require("../formatLocation");
24
24
  /** @typedef {import("../Module")} Module */
25
25
  /** @typedef {import("../Module").BuildMeta} BuildMeta */
26
26
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
27
+ /** @typedef {import("../NormalModuleFactory").ModuleSettings} ModuleSettings */
27
28
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
28
29
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
29
30
 
@@ -112,11 +113,12 @@ class SideEffectsFlagPlugin {
112
113
  return module;
113
114
  });
114
115
  normalModuleFactory.hooks.module.tap(PLUGIN_NAME, (module, data) => {
115
- if (typeof data.settings.sideEffects === "boolean") {
116
+ const settings = /** @type {ModuleSettings} */ (data.settings);
117
+ if (typeof settings.sideEffects === "boolean") {
116
118
  if (module.factoryMeta === undefined) {
117
119
  module.factoryMeta = {};
118
120
  }
119
- module.factoryMeta.sideEffectFree = !data.settings.sideEffects;
121
+ module.factoryMeta.sideEffectFree = !settings.sideEffects;
120
122
  }
121
123
  return module;
122
124
  });
@@ -212,7 +214,8 @@ class SideEffectsFlagPlugin {
212
214
  case "ExportDefaultDeclaration":
213
215
  if (
214
216
  !parser.isPure(
215
- statement.declaration,
217
+ /** @type {TODO} */
218
+ (statement.declaration),
216
219
  /** @type {Range} */ (statement.range)[0]
217
220
  )
218
221
  ) {