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
@@ -29,10 +29,14 @@ const makeSerializable = require("./util/makeSerializable");
29
29
 
30
30
  /** @typedef {import("webpack-sources").Source} Source */
31
31
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
32
+ /** @typedef {import("./Chunk")} Chunk */
32
33
  /** @typedef {import("./ChunkGraph")} ChunkGraph */
34
+ /** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
33
35
  /** @typedef {import("./ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
34
36
  /** @typedef {import("./Compilation")} Compilation */
37
+ /** @typedef {import("./Dependency")} Dependency */
35
38
  /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
39
+ /** @typedef {import("./Module").BuildInfo} BuildInfo */
36
40
  /** @typedef {import("./Module").BuildMeta} BuildMeta */
37
41
  /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
38
42
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
@@ -44,7 +48,7 @@ const makeSerializable = require("./util/makeSerializable");
44
48
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
45
49
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
46
50
  /** @typedef {import("./dependencies/ContextElementDependency")} ContextElementDependency */
47
- /** @typedef {import("./javascript/JavascriptParser").Attributes} Attributes */
51
+ /** @typedef {import("./javascript/JavascriptParser").ImportAttributes} ImportAttributes */
48
52
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
49
53
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
50
54
  /** @template T @typedef {import("./util/LazySet")<T>} LazySet<T> */
@@ -53,7 +57,7 @@ const makeSerializable = require("./util/makeSerializable");
53
57
  /** @typedef {"sync" | "eager" | "weak" | "async-weak" | "lazy" | "lazy-once"} ContextMode Context mode */
54
58
 
55
59
  /**
56
- * @typedef {Object} ContextOptions
60
+ * @typedef {object} ContextOptions
57
61
  * @property {ContextMode} mode
58
62
  * @property {boolean} recursive
59
63
  * @property {RegExp} regExp
@@ -67,11 +71,11 @@ const makeSerializable = require("./util/makeSerializable");
67
71
  * @property {string=} category
68
72
  * @property {(string[][] | null)=} referencedExports exports referenced from modules (won't be mangled)
69
73
  * @property {string=} layer
70
- * @property {Attributes=} attributes
74
+ * @property {ImportAttributes=} attributes
71
75
  */
72
76
 
73
77
  /**
74
- * @typedef {Object} ContextModuleOptionsExtras
78
+ * @typedef {object} ContextModuleOptionsExtras
75
79
  * @property {false|string|string[]} resource
76
80
  * @property {string=} resourceQuery
77
81
  * @property {string=} resourceFragment
@@ -93,6 +97,10 @@ const makeSerializable = require("./util/makeSerializable");
93
97
  * @param {ResolveDependenciesCallback} callback
94
98
  */
95
99
 
100
+ /** @typedef {1 | 3 | 7 | 9} FakeMapType */
101
+
102
+ /** @typedef {Map<string, string | number> | FakeMapType} FakeMap */
103
+
96
104
  const SNAPSHOT_OPTIONS = { timestamp: true };
97
105
 
98
106
  const TYPES = new Set(["javascript"]);
@@ -133,6 +141,7 @@ class ContextModule extends Module {
133
141
  }
134
142
 
135
143
  // Info from Factory
144
+ /** @type {ResolveDependencies | undefined} */
136
145
  this.resolveDependencies = resolveDependencies;
137
146
  if (options && options.resolveOptions !== undefined) {
138
147
  this.resolveOptions = options.resolveOptions;
@@ -174,6 +183,12 @@ class ContextModule extends Module {
174
183
  this.resolveDependencies = undefined;
175
184
  }
176
185
 
186
+ /**
187
+ * @private
188
+ * @param {RegExp} regexString RegExp as a string
189
+ * @param {boolean=} stripSlash do we need to strip a slsh
190
+ * @returns {string} pretty RegExp
191
+ */
177
192
  _prettyRegExp(regexString, stripSlash = true) {
178
193
  const str = (regexString + "").replace(/!/g, "%21").replace(/\|/g, "%7C");
179
194
  return stripSlash ? str.substring(1, str.length - 1) : str;
@@ -298,7 +313,9 @@ class ContextModule extends Module {
298
313
  if (this.options.groupOptions) {
299
314
  const groupOptions = this.options.groupOptions;
300
315
  for (const key of Object.keys(groupOptions)) {
301
- identifier += ` ${key}: ${groupOptions[key]}`;
316
+ identifier += ` ${key}: ${
317
+ groupOptions[/** @type {keyof RawChunkGroupOptions} */ (key)]
318
+ }`;
302
319
  }
303
320
  }
304
321
  if (this.options.namespaceObject === "strict") {
@@ -387,11 +404,13 @@ class ContextModule extends Module {
387
404
  // build if enforced
388
405
  if (this._forceBuild) return callback(null, true);
389
406
 
407
+ const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
408
+
390
409
  // always build when we have no snapshot and context
391
- if (!this.buildInfo.snapshot)
410
+ if (!buildInfo.snapshot)
392
411
  return callback(null, Boolean(this.context || this.options.resource));
393
412
 
394
- fileSystemInfo.checkSnapshotValid(this.buildInfo.snapshot, (err, valid) => {
413
+ fileSystemInfo.checkSnapshotValid(buildInfo.snapshot, (err, valid) => {
395
414
  callback(err, !valid);
396
415
  });
397
416
  }
@@ -417,7 +436,8 @@ class ContextModule extends Module {
417
436
  this.dependencies.length = 0;
418
437
  this.blocks.length = 0;
419
438
  const startTime = Date.now();
420
- this.resolveDependencies(fs, this.options, (err, dependencies) => {
439
+ /** @type {ResolveDependencies} */
440
+ (this.resolveDependencies)(fs, this.options, (err, dependencies) => {
421
441
  if (err) {
422
442
  return callback(
423
443
  makeWebpackError(err, "ContextModule.resolveDependencies")
@@ -518,7 +538,8 @@ class ContextModule extends Module {
518
538
  SNAPSHOT_OPTIONS,
519
539
  (err, snapshot) => {
520
540
  if (err) return callback(err);
521
- this.buildInfo.snapshot = snapshot;
541
+ /** @type {BuildInfo} */
542
+ (this.buildInfo).snapshot = snapshot;
522
543
  callback();
523
544
  }
524
545
  );
@@ -549,35 +570,37 @@ class ContextModule extends Module {
549
570
  }
550
571
 
551
572
  /**
552
- * @param {ContextElementDependency[]} dependencies all dependencies
573
+ * @param {Dependency[]} dependencies all dependencies
553
574
  * @param {ChunkGraph} chunkGraph chunk graph
554
- * @returns {TODO} TODO
575
+ * @returns {Map<string, string | number>} map with user requests
555
576
  */
556
577
  getUserRequestMap(dependencies, chunkGraph) {
557
578
  const moduleGraph = chunkGraph.moduleGraph;
558
579
  // if we filter first we get a new array
559
580
  // therefore we don't need to create a clone of dependencies explicitly
560
581
  // therefore the order of this is !important!
561
- const sortedDependencies = dependencies
562
- .filter(dependency => moduleGraph.getModule(dependency))
563
- .sort((a, b) => {
564
- if (a.userRequest === b.userRequest) {
565
- return 0;
566
- }
567
- return a.userRequest < b.userRequest ? -1 : 1;
568
- });
582
+ const sortedDependencies =
583
+ /** @type {ContextElementDependency[]} */
584
+ (dependencies)
585
+ .filter(dependency => moduleGraph.getModule(dependency))
586
+ .sort((a, b) => {
587
+ if (a.userRequest === b.userRequest) {
588
+ return 0;
589
+ }
590
+ return a.userRequest < b.userRequest ? -1 : 1;
591
+ });
569
592
  const map = Object.create(null);
570
593
  for (const dep of sortedDependencies) {
571
- const module = moduleGraph.getModule(dep);
594
+ const module = /** @type {Module} */ (moduleGraph.getModule(dep));
572
595
  map[dep.userRequest] = chunkGraph.getModuleId(module);
573
596
  }
574
597
  return map;
575
598
  }
576
599
 
577
600
  /**
578
- * @param {ContextElementDependency[]} dependencies all dependencies
601
+ * @param {Dependency[]} dependencies all dependencies
579
602
  * @param {ChunkGraph} chunkGraph chunk graph
580
- * @returns {TODO} TODO
603
+ * @returns {FakeMap} fake map
581
604
  */
582
605
  getFakeMap(dependencies, chunkGraph) {
583
606
  if (!this.options.namespaceObject) {
@@ -591,7 +614,9 @@ class ContextModule extends Module {
591
614
  // therefore we don't need to create a clone of dependencies explicitly
592
615
  // therefore the order of this is !important!
593
616
  const sortedModules = dependencies
594
- .map(dependency => moduleGraph.getModule(dependency))
617
+ .map(
618
+ dependency => /** @type {Module} */ (moduleGraph.getModule(dependency))
619
+ )
595
620
  .filter(Boolean)
596
621
  .sort(comparator);
597
622
  const fakeMap = Object.create(null);
@@ -640,12 +665,21 @@ class ContextModule extends Module {
640
665
  return fakeMap;
641
666
  }
642
667
 
668
+ /**
669
+ * @param {FakeMap} fakeMap fake map
670
+ * @returns {string} fake map init statement
671
+ */
643
672
  getFakeMapInitStatement(fakeMap) {
644
673
  return typeof fakeMap === "object"
645
674
  ? `var fakeMap = ${JSON.stringify(fakeMap, null, "\t")};`
646
675
  : "";
647
676
  }
648
677
 
678
+ /**
679
+ * @param {FakeMapType} type type
680
+ * @param {boolean=} asyncModule is async module
681
+ * @returns {string} return result
682
+ */
649
683
  getReturn(type, asyncModule) {
650
684
  if (type === 9) {
651
685
  return `${RuntimeGlobals.require}(id)`;
@@ -655,6 +689,12 @@ class ContextModule extends Module {
655
689
  })`;
656
690
  }
657
691
 
692
+ /**
693
+ * @param {FakeMap} fakeMap fake map
694
+ * @param {boolean=} asyncModule us async module
695
+ * @param {string=} fakeMapDataExpression fake map data expression
696
+ * @returns {string} module object source
697
+ */
658
698
  getReturnModuleObjectSource(
659
699
  fakeMap,
660
700
  asyncModule,
@@ -669,8 +709,8 @@ class ContextModule extends Module {
669
709
  }
670
710
 
671
711
  /**
672
- * @param {TODO} dependencies TODO
673
- * @param {TODO} id TODO
712
+ * @param {Dependency[]} dependencies dependencies
713
+ * @param {ModuleId} id module id
674
714
  * @param {ChunkGraph} chunkGraph the chunk graph
675
715
  * @returns {string} source code
676
716
  */
@@ -703,8 +743,8 @@ webpackContext.id = ${JSON.stringify(id)};`;
703
743
  }
704
744
 
705
745
  /**
706
- * @param {TODO} dependencies TODO
707
- * @param {TODO} id TODO
746
+ * @param {Dependency[]} dependencies dependencies
747
+ * @param {ModuleId} id module id
708
748
  * @param {ChunkGraph} chunkGraph the chunk graph
709
749
  * @returns {string} source code
710
750
  */
@@ -742,9 +782,9 @@ module.exports = webpackContext;`;
742
782
  }
743
783
 
744
784
  /**
745
- * @param {TODO} dependencies TODO
746
- * @param {TODO} id TODO
747
- * @param {Object} context context
785
+ * @param {Dependency[]} dependencies dependencies
786
+ * @param {ModuleId} id module id
787
+ * @param {object} context context
748
788
  * @param {ChunkGraph} context.chunkGraph the chunk graph
749
789
  * @param {RuntimeTemplate} context.runtimeTemplate the chunk graph
750
790
  * @returns {string} source code
@@ -791,9 +831,9 @@ module.exports = webpackAsyncContext;`;
791
831
  }
792
832
 
793
833
  /**
794
- * @param {TODO} dependencies TODO
795
- * @param {TODO} id TODO
796
- * @param {Object} context context
834
+ * @param {Dependency[]} dependencies dependencies
835
+ * @param {ModuleId} id module id
836
+ * @param {object} context context
797
837
  * @param {ChunkGraph} context.chunkGraph the chunk graph
798
838
  * @param {RuntimeTemplate} context.runtimeTemplate the chunk graph
799
839
  * @returns {string} source code
@@ -805,7 +845,7 @@ module.exports = webpackAsyncContext;`;
805
845
  const thenFunction =
806
846
  fakeMap !== 9
807
847
  ? `${arrow ? "id =>" : "function(id)"} {
808
- ${this.getReturnModuleObjectSource(fakeMap)}
848
+ ${this.getReturnModuleObjectSource(fakeMap, true)}
809
849
  }`
810
850
  : RuntimeGlobals.require;
811
851
  return `var map = ${JSON.stringify(map, null, "\t")};
@@ -835,10 +875,10 @@ module.exports = webpackAsyncContext;`;
835
875
  }
836
876
 
837
877
  /**
838
- * @param {TODO} block TODO
839
- * @param {TODO} dependencies TODO
840
- * @param {TODO} id TODO
841
- * @param {Object} options options object
878
+ * @param {AsyncDependenciesBlock} block block
879
+ * @param {Dependency[]} dependencies dependencies
880
+ * @param {ModuleId} id module id
881
+ * @param {object} options options object
842
882
  * @param {RuntimeTemplate} options.runtimeTemplate the runtime template
843
883
  * @param {ChunkGraph} options.chunkGraph the chunk graph
844
884
  * @returns {string} source code
@@ -885,9 +925,9 @@ module.exports = webpackAsyncContext;`;
885
925
  }
886
926
 
887
927
  /**
888
- * @param {TODO} blocks TODO
889
- * @param {TODO} id TODO
890
- * @param {Object} context context
928
+ * @param {AsyncDependenciesBlock[]} blocks blocks
929
+ * @param {ModuleId} id module id
930
+ * @param {object} context context
891
931
  * @param {ChunkGraph} context.chunkGraph the chunk graph
892
932
  * @param {RuntimeTemplate} context.runtimeTemplate the chunk graph
893
933
  * @returns {string} source code
@@ -904,10 +944,12 @@ module.exports = webpackAsyncContext;`;
904
944
  const hasFakeMap = typeof fakeMap === "object";
905
945
  const items = blocks
906
946
  .map(block => {
907
- const dependency = block.dependencies[0];
947
+ const dependency =
948
+ /** @type {ContextElementDependency} */
949
+ (block.dependencies[0]);
908
950
  return {
909
951
  dependency: dependency,
910
- module: moduleGraph.getModule(dependency),
952
+ module: /** @type {Module} */ (moduleGraph.getModule(dependency)),
911
953
  block: block,
912
954
  userRequest: dependency.userRequest,
913
955
  chunks: undefined
@@ -997,6 +1039,11 @@ webpackAsyncContext.id = ${JSON.stringify(id)};
997
1039
  module.exports = webpackAsyncContext;`;
998
1040
  }
999
1041
 
1042
+ /**
1043
+ * @param {ModuleId} id module id
1044
+ * @param {RuntimeTemplate} runtimeTemplate runtime template
1045
+ * @returns {string} source for empty async context
1046
+ */
1000
1047
  getSourceForEmptyContext(id, runtimeTemplate) {
1001
1048
  return `function webpackEmptyContext(req) {
1002
1049
  var e = new Error("Cannot find module '" + req + "'");
@@ -1009,6 +1056,11 @@ webpackEmptyContext.id = ${JSON.stringify(id)};
1009
1056
  module.exports = webpackEmptyContext;`;
1010
1057
  }
1011
1058
 
1059
+ /**
1060
+ * @param {ModuleId} id module id
1061
+ * @param {RuntimeTemplate} runtimeTemplate runtime template
1062
+ * @returns {string} source for empty async context
1063
+ */
1012
1064
  getSourceForEmptyAsyncContext(id, runtimeTemplate) {
1013
1065
  const arrow = runtimeTemplate.supportsArrowFunction();
1014
1066
  return `function webpackEmptyAsyncContext(req) {
@@ -27,6 +27,7 @@ const createHash = require("./util/createHash");
27
27
  /** @typedef {import("./NormalModule")} NormalModule */
28
28
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
29
29
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
30
+ /** @typedef {import("./javascript/JavascriptParser").DestructuringAssignmentProperty} DestructuringAssignmentProperty */
30
31
  /** @typedef {import("./javascript/JavascriptParser").Range} Range */
31
32
  /** @typedef {import("./logging/Logger").Logger} Logger */
32
33
 
@@ -34,7 +35,7 @@ const createHash = require("./util/createHash");
34
35
  /** @typedef {RecursiveArrayOrRecord<CodeValuePrimitive|RuntimeValue>} CodeValue */
35
36
 
36
37
  /**
37
- * @typedef {Object} RuntimeValueOptions
38
+ * @typedef {object} RuntimeValueOptions
38
39
  * @property {string[]=} fileDependencies
39
40
  * @property {string[]=} contextDependencies
40
41
  * @property {string[]=} missingDependencies
@@ -114,6 +115,15 @@ class RuntimeValue {
114
115
  }
115
116
  }
116
117
 
118
+ /**
119
+ * @param {Set<DestructuringAssignmentProperty> | undefined} properties properties
120
+ * @returns {Set<string> | undefined} used keys
121
+ */
122
+ function getObjKeys(properties) {
123
+ if (!properties) return undefined;
124
+ return new Set([...properties].map(p => p.id));
125
+ }
126
+
117
127
  /**
118
128
  * @param {any[]|{[k: string]: any}} obj obj
119
129
  * @param {JavascriptParser} parser Parser
@@ -491,7 +501,7 @@ class DefinePlugin {
491
501
  runtimeTemplate,
492
502
  logger,
493
503
  !parser.isAsiPosition(/** @type {Range} */ (expr.range)[0]),
494
- parser.destructuringAssignmentPropertiesFor(expr)
504
+ null
495
505
  );
496
506
 
497
507
  if (parser.scope.inShorthand) {
@@ -566,7 +576,7 @@ class DefinePlugin {
566
576
  /**
567
577
  * Apply Object
568
578
  * @param {string} key Key
569
- * @param {Object} obj Object
579
+ * @param {object} obj Object
570
580
  * @returns {void}
571
581
  */
572
582
  const applyObjectDefine = (key, obj) => {
@@ -597,7 +607,7 @@ class DefinePlugin {
597
607
  runtimeTemplate,
598
608
  logger,
599
609
  !parser.isAsiPosition(/** @type {Range} */ (expr.range)[0]),
600
- parser.destructuringAssignmentPropertiesFor(expr)
610
+ getObjKeys(parser.destructuringAssignmentPropertiesFor(expr))
601
611
  );
602
612
 
603
613
  if (parser.scope.inShorthand) {
package/lib/Dependency.js CHANGED
@@ -24,35 +24,35 @@ const memoize = require("./util/memoize");
24
24
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
25
25
 
26
26
  /**
27
- * @typedef {Object} UpdateHashContext
27
+ * @typedef {object} UpdateHashContext
28
28
  * @property {ChunkGraph} chunkGraph
29
29
  * @property {RuntimeSpec} runtime
30
30
  * @property {RuntimeTemplate=} runtimeTemplate
31
31
  */
32
32
 
33
33
  /**
34
- * @typedef {Object} SourcePosition
34
+ * @typedef {object} SourcePosition
35
35
  * @property {number} line
36
36
  * @property {number=} column
37
37
  */
38
38
 
39
39
  /**
40
- * @typedef {Object} RealDependencyLocation
40
+ * @typedef {object} RealDependencyLocation
41
41
  * @property {SourcePosition} start
42
42
  * @property {SourcePosition=} end
43
43
  * @property {number=} index
44
44
  */
45
45
 
46
46
  /**
47
- * @typedef {Object} SyntheticDependencyLocation
47
+ * @typedef {object} SyntheticDependencyLocation
48
48
  * @property {string} name
49
49
  * @property {number=} index
50
50
  */
51
51
 
52
- /** @typedef {SyntheticDependencyLocation|RealDependencyLocation} DependencyLocation */
52
+ /** @typedef {SyntheticDependencyLocation | RealDependencyLocation} DependencyLocation */
53
53
 
54
54
  /**
55
- * @typedef {Object} ExportSpec
55
+ * @typedef {object} ExportSpec
56
56
  * @property {string} name the name of the export
57
57
  * @property {boolean=} canMangle can the export be renamed (defaults to true)
58
58
  * @property {boolean=} terminalBinding is the export a terminal binding that should be checked for export star conflicts
@@ -64,7 +64,7 @@ const memoize = require("./util/memoize");
64
64
  */
65
65
 
66
66
  /**
67
- * @typedef {Object} ExportsSpec
67
+ * @typedef {object} ExportsSpec
68
68
  * @property {(string | ExportSpec)[] | true | null} exports exported names, true for unknown exports or null for no exports
69
69
  * @property {Set<string>=} excludeExports when exports = true, list of unaffected exports
70
70
  * @property {Set<string>=} hideExports list of maybe prior exposed, but now hidden exports
@@ -76,7 +76,7 @@ const memoize = require("./util/memoize");
76
76
  */
77
77
 
78
78
  /**
79
- * @typedef {Object} ReferencedExport
79
+ * @typedef {object} ReferencedExport
80
80
  * @property {string[]} name name of the referenced export
81
81
  * @property {boolean=} canMangle when false, referenced export can not be mangled, defaults to true
82
82
  */
@@ -24,15 +24,14 @@
24
24
  */
25
25
 
26
26
  /**
27
- * @typedef {Object} DependencyTemplateContext
27
+ * @typedef {object} DependencyTemplateContext
28
28
  * @property {RuntimeTemplate} runtimeTemplate the runtime template
29
29
  * @property {DependencyTemplates} dependencyTemplates the dependency templates
30
30
  * @property {ModuleGraph} moduleGraph the module graph
31
31
  * @property {ChunkGraph} chunkGraph the chunk graph
32
32
  * @property {RuntimeRequirements} runtimeRequirements the requirements for runtime
33
33
  * @property {Module} module current module
34
- * @property {RuntimeSpec} runtime current runtime, for which code is generated
35
- * @property {RuntimeSpec[]} [runtimes] current runtimes, for which code is generated
34
+ * @property {RuntimeSpec} runtime current runtimes, for which code is generated
36
35
  * @property {InitFragment<GenerateContext>[]} initFragments mutable array of init fragments for the current module
37
36
  * @property {ConcatenationScope=} concatenationScope when in a concatenated module, information about other concatenated modules
38
37
  * @property {CodeGenerationResults} codeGenerationResults the code generation results
@@ -40,8 +39,14 @@
40
39
  */
41
40
 
42
41
  /**
43
- * @typedef {Object} CssDependencyTemplateContextExtras
44
- * @property {Map<string, string>} cssExports the css exports
42
+ * @typedef {object} CssDependencyTemplateContextExtras
43
+ * @property {CssExportsData} cssExportsData the css exports data
44
+ */
45
+
46
+ /**
47
+ * @typedef {object} CssExportsData
48
+ * @property {boolean} esModule whether export __esModule
49
+ * @property {Map<string, string>} exports the css exports
45
50
  */
46
51
 
47
52
  /** @typedef {DependencyTemplateContext & CssDependencyTemplateContextExtras} CssDependencyTemplateContext */
@@ -35,7 +35,7 @@ class DllReferencePlugin {
35
35
  constructor(options) {
36
36
  validate(options);
37
37
  this.options = options;
38
- /** @type {WeakMap<Object, {path: string, data: DllReferencePluginOptionsManifest?, error: Error?}>} */
38
+ /** @type {WeakMap<object, {path: string, data: DllReferencePluginOptionsManifest?, error: Error?}>} */
39
39
  this._compilationData = new WeakMap();
40
40
  }
41
41
 
@@ -12,6 +12,7 @@ const RuntimeGlobals = require("./RuntimeGlobals");
12
12
  const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
13
13
 
14
14
  /** @typedef {import("webpack-sources").Source} Source */
15
+ /** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputOptions */
15
16
  /** @typedef {import("./Compiler")} Compiler */
16
17
 
17
18
  /** @type {WeakMap<Source, Source>} */
@@ -27,7 +28,17 @@ const devtoolWarning = new RawSource(`/*
27
28
  */
28
29
  `);
29
30
 
31
+ /**
32
+ * @typedef {object} EvalDevToolModulePluginOptions
33
+ * @property {OutputOptions["devtoolNamespace"]=} namespace namespace
34
+ * @property {string=} sourceUrlComment source url comment
35
+ * @property {OutputOptions["devtoolModuleFilenameTemplate"]=} moduleFilenameTemplate module filename template
36
+ */
37
+
30
38
  class EvalDevToolModulePlugin {
39
+ /**
40
+ * @param {EvalDevToolModulePluginOptions=} options options
41
+ */
31
42
  constructor(options) {
32
43
  this.namespace = options.namespace || "";
33
44
  this.sourceUrlComment = options.sourceUrlComment || "\n//# sourceURL=[url]";
@@ -171,6 +171,10 @@ class ExportsInfo {
171
171
  this._exportsAreOrdered = true;
172
172
  }
173
173
 
174
+ /**
175
+ * @param {ExportsInfo | undefined} exportsInfo exports info
176
+ * @returns {boolean} result
177
+ */
174
178
  setRedirectNamedTo(exportsInfo) {
175
179
  if (this._redirectTo === exportsInfo) return false;
176
180
  this._redirectTo = exportsInfo;
@@ -476,6 +480,7 @@ class ExportsInfo {
476
480
  * @returns {SortableSet<string> | boolean | null} set of used exports, or true (when namespace object is used), or false (when unused), or null (when unknown)
477
481
  */
478
482
  getUsedExports(runtime) {
483
+ // eslint-disable-next-line no-constant-binary-expression
479
484
  if (!this._redirectTo !== undefined) {
480
485
  switch (this._otherExportsInfo.getUsed(runtime)) {
481
486
  case UsageState.NoInfo:
@@ -524,6 +529,7 @@ class ExportsInfo {
524
529
  * @returns {null | true | string[]} list of exports when known
525
530
  */
526
531
  getProvidedExports() {
532
+ // eslint-disable-next-line no-constant-binary-expression
527
533
  if (!this._redirectTo !== undefined) {
528
534
  switch (this._otherExportsInfo.provided) {
529
535
  case undefined:
@@ -804,16 +810,28 @@ class ExportInfo {
804
810
  constructor(name, initFrom) {
805
811
  /** @type {string} */
806
812
  this.name = name;
807
- /** @private @type {string | null} */
813
+ /**
814
+ * @private
815
+ * @type {string | null}
816
+ */
808
817
  this._usedName = initFrom ? initFrom._usedName : null;
809
- /** @private @type {UsageStateType} */
818
+ /**
819
+ * @private
820
+ * @type {UsageStateType}
821
+ */
810
822
  this._globalUsed = initFrom ? initFrom._globalUsed : undefined;
811
- /** @private @type {Map<string, RuntimeUsageStateType>} */
823
+ /**
824
+ * @private
825
+ * @type {Map<string, RuntimeUsageStateType>}
826
+ */
812
827
  this._usedInRuntime =
813
828
  initFrom && initFrom._usedInRuntime
814
829
  ? new Map(initFrom._usedInRuntime)
815
830
  : undefined;
816
- /** @private @type {boolean} */
831
+ /**
832
+ * @private
833
+ * @type {boolean}
834
+ */
817
835
  this._hasUseInRuntimeInfo = initFrom
818
836
  ? initFrom._hasUseInRuntimeInfo
819
837
  : false;