webpack 5.99.5 → 5.99.7

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 (169) hide show
  1. package/README.md +1 -1
  2. package/lib/APIPlugin.js +2 -2
  3. package/lib/AutomaticPrefetchPlugin.js +21 -22
  4. package/lib/BannerPlugin.js +31 -35
  5. package/lib/Cache.js +1 -1
  6. package/lib/Chunk.js +12 -9
  7. package/lib/CleanPlugin.js +5 -3
  8. package/lib/Compilation.js +45 -35
  9. package/lib/Compiler.js +6 -4
  10. package/lib/ContextExclusionPlugin.js +4 -2
  11. package/lib/ContextModule.js +2 -1
  12. package/lib/ContextReplacementPlugin.js +5 -3
  13. package/lib/DelegatedPlugin.js +4 -2
  14. package/lib/DllEntryPlugin.js +4 -2
  15. package/lib/DllPlugin.js +5 -3
  16. package/lib/DllReferencePlugin.js +56 -60
  17. package/lib/DynamicEntryPlugin.js +4 -2
  18. package/lib/EntryOptionPlugin.js +3 -1
  19. package/lib/EntryPlugin.js +4 -2
  20. package/lib/EnvironmentPlugin.js +4 -2
  21. package/lib/EvalDevToolModulePlugin.js +9 -7
  22. package/lib/EvalSourceMapDevToolPlugin.js +137 -138
  23. package/lib/ExternalsPlugin.js +3 -1
  24. package/lib/FlagDependencyExportsPlugin.js +2 -1
  25. package/lib/HotModuleReplacementPlugin.js +3 -3
  26. package/lib/IgnorePlugin.js +6 -4
  27. package/lib/IgnoreWarningsPlugin.js +4 -2
  28. package/lib/LibManifestPlugin.js +3 -4
  29. package/lib/LoaderOptionsPlugin.js +4 -2
  30. package/lib/LoaderTargetPlugin.js +4 -2
  31. package/lib/Module.js +29 -14
  32. package/lib/ModuleFilenameHelpers.js +1 -1
  33. package/lib/ModuleGraph.js +15 -10
  34. package/lib/ModuleInfoHeaderPlugin.js +11 -12
  35. package/lib/MultiCompiler.js +5 -3
  36. package/lib/NoEmitOnErrorsPlugin.js +5 -3
  37. package/lib/NormalModule.js +6 -2
  38. package/lib/NormalModuleReplacementPlugin.js +33 -36
  39. package/lib/PlatformPlugin.js +3 -1
  40. package/lib/PrefetchPlugin.js +5 -3
  41. package/lib/ProgressPlugin.js +23 -26
  42. package/lib/RecordIdsPlugin.js +73 -103
  43. package/lib/RuntimePlugin.js +34 -32
  44. package/lib/SourceMapDevToolPlugin.js +8 -6
  45. package/lib/Template.js +1 -1
  46. package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
  47. package/lib/WarnNoModeSetPlugin.js +3 -1
  48. package/lib/WatchIgnorePlugin.js +3 -1
  49. package/lib/WebpackError.js +11 -3
  50. package/lib/WebpackOptionsApply.js +22 -5
  51. package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
  52. package/lib/buildChunkGraph.js +7 -2
  53. package/lib/cache/IdleFileCachePlugin.js +12 -13
  54. package/lib/cache/MemoryCachePlugin.js +2 -1
  55. package/lib/cache/MemoryWithGcCachePlugin.js +10 -7
  56. package/lib/cache/PackFileCacheStrategy.js +13 -21
  57. package/lib/cache/ResolverCachePlugin.js +22 -22
  58. package/lib/cli.js +8 -4
  59. package/lib/config/defaults.js +2 -2
  60. package/lib/config/normalization.js +9 -3
  61. package/lib/config/target.js +6 -6
  62. package/lib/container/ContainerReferencePlugin.js +24 -26
  63. package/lib/container/ModuleFederationPlugin.js +2 -1
  64. package/lib/css/CssGenerator.js +1 -1
  65. package/lib/css/CssModulesPlugin.js +6 -4
  66. package/lib/css/CssParser.js +1 -1
  67. package/lib/debug/ProfilingPlugin.js +1 -1
  68. package/lib/dependencies/ContextDependencyHelpers.js +1 -1
  69. package/lib/dependencies/CssIcssImportDependency.js +3 -2
  70. package/lib/dependencies/HarmonyDetectionParserPlugin.js +9 -15
  71. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  72. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
  73. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -1
  74. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
  75. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
  76. package/lib/dependencies/JsonExportsDependency.js +1 -1
  77. package/lib/dependencies/LoaderPlugin.js +5 -3
  78. package/lib/dependencies/LocalModulesHelpers.js +1 -1
  79. package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
  80. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
  81. package/lib/dependencies/RequireResolveDependency.js +1 -1
  82. package/lib/dependencies/WorkerPlugin.js +2 -2
  83. package/lib/esm/ModuleChunkLoadingPlugin.js +76 -57
  84. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +11 -9
  85. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  86. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -1
  87. package/lib/hmr/LazyCompilationPlugin.js +17 -18
  88. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
  89. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  90. package/lib/ids/DeterministicModuleIdsPlugin.js +48 -49
  91. package/lib/ids/HashedModuleIdsPlugin.js +4 -2
  92. package/lib/ids/NamedChunkIdsPlugin.js +6 -4
  93. package/lib/ids/NamedModuleIdsPlugin.js +6 -4
  94. package/lib/ids/NaturalChunkIdsPlugin.js +4 -2
  95. package/lib/ids/NaturalModuleIdsPlugin.js +4 -2
  96. package/lib/ids/OccurrenceChunkIdsPlugin.js +4 -2
  97. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -2
  98. package/lib/index.js +1 -1
  99. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  100. package/lib/javascript/JavascriptParser.js +670 -688
  101. package/lib/library/EnableLibraryPlugin.js +15 -2
  102. package/lib/library/ModuleLibraryPlugin.js +66 -43
  103. package/lib/logging/createConsoleLogger.js +0 -1
  104. package/lib/node/CommonJsChunkLoadingPlugin.js +71 -75
  105. package/lib/node/NodeEnvironmentPlugin.js +3 -1
  106. package/lib/node/NodeTemplatePlugin.js +2 -2
  107. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
  108. package/lib/node/ReadFileCompileWasmPlugin.js +3 -3
  109. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  110. package/lib/optimize/AggressiveSplittingPlugin.js +224 -232
  111. package/lib/optimize/ConcatenatedModule.js +12 -15
  112. package/lib/optimize/FlagIncludedChunksPlugin.js +92 -97
  113. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  114. package/lib/optimize/MangleExportsPlugin.js +15 -16
  115. package/lib/optimize/MinChunkSizePlugin.js +4 -2
  116. package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
  117. package/lib/optimize/RealContentHashPlugin.js +4 -2
  118. package/lib/optimize/RemoveEmptyChunksPlugin.js +5 -3
  119. package/lib/optimize/RemoveParentModulesPlugin.js +4 -2
  120. package/lib/optimize/RuntimeChunkPlugin.js +17 -18
  121. package/lib/optimize/SplitChunksPlugin.js +9 -6
  122. package/lib/performance/SizeLimitsPlugin.js +3 -1
  123. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
  124. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
  125. package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
  126. package/lib/schemes/DataUriPlugin.js +5 -3
  127. package/lib/schemes/FileUriPlugin.js +5 -3
  128. package/lib/schemes/HttpUriPlugin.js +32 -39
  129. package/lib/serialization/AggregateErrorSerializer.js +42 -0
  130. package/lib/serialization/BinaryMiddleware.js +22 -38
  131. package/lib/serialization/ErrorObjectSerializer.js +7 -2
  132. package/lib/serialization/FileMiddleware.js +29 -33
  133. package/lib/serialization/ObjectMiddleware.js +42 -30
  134. package/lib/serialization/Serializer.js +29 -18
  135. package/lib/serialization/SerializerMiddleware.js +105 -72
  136. package/lib/serialization/SingleItemMiddleware.js +4 -5
  137. package/lib/sharing/ProvideSharedPlugin.js +6 -4
  138. package/lib/stats/DefaultStatsFactoryPlugin.js +128 -57
  139. package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
  140. package/lib/stats/DefaultStatsPrinterPlugin.js +486 -334
  141. package/lib/stats/StatsFactory.js +47 -10
  142. package/lib/stats/StatsPrinter.js +52 -31
  143. package/lib/util/ArrayQueue.js +1 -1
  144. package/lib/util/AsyncQueue.js +1 -1
  145. package/lib/util/TupleQueue.js +9 -7
  146. package/lib/util/TupleSet.js +37 -18
  147. package/lib/util/WeakTupleMap.js +50 -37
  148. package/lib/util/cleverMerge.js +2 -2
  149. package/lib/util/comparators.js +1 -1
  150. package/lib/util/concatenate.js +4 -2
  151. package/lib/util/createHash.js +1 -1
  152. package/lib/util/fs.js +1 -1
  153. package/lib/util/makeSerializable.js +1 -1
  154. package/lib/util/runtime.js +1 -0
  155. package/lib/util/serialization.js +50 -42
  156. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  157. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -1
  158. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  159. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
  160. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -1
  161. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  162. package/lib/web/FetchCompileWasmPlugin.js +2 -2
  163. package/lib/web/JsonpChunkLoadingPlugin.js +73 -74
  164. package/lib/webpack.js +1 -1
  165. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
  166. package/package.json +4 -3
  167. package/schemas/WebpackOptions.check.js +1 -1
  168. package/schemas/WebpackOptions.json +24 -2
  169. package/types.d.ts +273 -128
@@ -385,15 +385,17 @@ class CssModulesPlugin {
385
385
  compilation
386
386
  ).renderModuleContent.tap(PLUGIN_NAME, (source, module) => {
387
387
  if (module instanceof CssModule && module.hot) {
388
- const exports =
389
- /** @type {BuildInfo} */
390
- (module.buildInfo).cssData.exports;
388
+ const cssData = /** @type {BuildInfo} */ (module.buildInfo).cssData;
389
+ if (!cssData) {
390
+ return source;
391
+ }
392
+ const exports = cssData.exports;
391
393
  const stringifiedExports = JSON.stringify(
392
394
  JSON.stringify(
393
395
  Array.from(exports).reduce((obj, [key, value]) => {
394
396
  obj[key] = value;
395
397
  return obj;
396
- }, {})
398
+ }, /** @type {Record<string, string>} */ ({}))
397
399
  )
398
400
  );
399
401
 
@@ -293,7 +293,7 @@ const eatSemi = walkCssTokens.eatUntil(";");
293
293
 
294
294
  class CssParser extends Parser {
295
295
  /**
296
- * @param {CssParserOptions} [options] options
296
+ * @param {CssParserOptions=} options options
297
297
  */
298
298
  constructor({
299
299
  defaultMode = "pure",
@@ -88,7 +88,7 @@ class Profiler {
88
88
 
89
89
  /**
90
90
  * @param {string} method method name
91
- * @param {Record<string, EXPECTED_ANY>} [params] params
91
+ * @param {Record<string, EXPECTED_ANY>=} params params
92
92
  * @returns {Promise<TODO>} Promise for the result
93
93
  */
94
94
  sendCommand(method, params) {
@@ -42,7 +42,7 @@ const splitContextFromPrefix = prefix => {
42
42
  };
43
43
 
44
44
  /** @typedef {Partial<Omit<ContextDependencyOptions, "resource">>} PartialContextDependencyOptions */
45
- /** @typedef {{ new(options: ContextDependencyOptions, range: Range, valueRange: [number, number], ...args: any[]): ContextDependency }} ContextDependencyConstructor */
45
+ /** @typedef {{ new(options: ContextDependencyOptions, range: Range, valueRange: Range, ...args: any[]): ContextDependency }} ContextDependencyConstructor */
46
46
 
47
47
  /**
48
48
  * @param {ContextDependencyConstructor} Dep the Dependency class
@@ -16,6 +16,7 @@ const ModuleDependency = require("./ModuleDependency");
16
16
  /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
17
17
  /** @typedef {import("../Module")} Module */
18
18
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
19
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
19
20
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
20
21
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
21
22
 
@@ -26,12 +27,12 @@ class CssIcssImportDependency extends ModuleDependency {
26
27
  *:import('./style.css') { IMPORTED_NAME: v-primary }
27
28
  * @param {string} request request request path which needs resolving
28
29
  * @param {string} exportName export name
29
- * @param {[number, number]} range the range of dependency
30
+ * @param {Range} range the range of dependency
30
31
  */
31
32
  constructor(request, exportName, range) {
32
33
  super(request);
33
- this.range = range;
34
34
  this.exportName = exportName;
35
+ this.range = range;
35
36
  }
36
37
 
37
38
  get type() {
@@ -15,6 +15,8 @@ const HarmonyExports = require("./HarmonyExports");
15
15
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
16
16
  /** @typedef {import("./HarmonyModulesPlugin").HarmonyModulesPluginOptions} HarmonyModulesPluginOptions */
17
17
 
18
+ const PLUGIN_NAME = "HarmonyDetectionParserPlugin";
19
+
18
20
  module.exports = class HarmonyDetectionParserPlugin {
19
21
  /**
20
22
  * @param {HarmonyModulesPluginOptions} options options
@@ -29,7 +31,7 @@ module.exports = class HarmonyDetectionParserPlugin {
29
31
  * @returns {void}
30
32
  */
31
33
  apply(parser) {
32
- parser.hooks.program.tap("HarmonyDetectionParserPlugin", ast => {
34
+ parser.hooks.program.tap(PLUGIN_NAME, ast => {
33
35
  const isStrictHarmony =
34
36
  parser.state.module.type === JAVASCRIPT_MODULE_TYPE_ESM;
35
37
  const isHarmony =
@@ -62,7 +64,7 @@ module.exports = class HarmonyDetectionParserPlugin {
62
64
  }
63
65
  });
64
66
 
65
- parser.hooks.topLevelAwait.tap("HarmonyDetectionParserPlugin", () => {
67
+ parser.hooks.topLevelAwait.tap(PLUGIN_NAME, () => {
66
68
  const module = parser.state.module;
67
69
  if (!this.topLevelAwait) {
68
70
  throw new Error(
@@ -105,19 +107,11 @@ module.exports = class HarmonyDetectionParserPlugin {
105
107
  for (const identifier of nonHarmonyIdentifiers) {
106
108
  parser.hooks.evaluateTypeof
107
109
  .for(identifier)
108
- .tap("HarmonyDetectionParserPlugin", nullInHarmony);
109
- parser.hooks.typeof
110
- .for(identifier)
111
- .tap("HarmonyDetectionParserPlugin", skipInHarmony);
112
- parser.hooks.evaluate
113
- .for(identifier)
114
- .tap("HarmonyDetectionParserPlugin", nullInHarmony);
115
- parser.hooks.expression
116
- .for(identifier)
117
- .tap("HarmonyDetectionParserPlugin", skipInHarmony);
118
- parser.hooks.call
119
- .for(identifier)
120
- .tap("HarmonyDetectionParserPlugin", skipInHarmony);
110
+ .tap(PLUGIN_NAME, nullInHarmony);
111
+ parser.hooks.typeof.for(identifier).tap(PLUGIN_NAME, skipInHarmony);
112
+ parser.hooks.evaluate.for(identifier).tap(PLUGIN_NAME, nullInHarmony);
113
+ parser.hooks.expression.for(identifier).tap(PLUGIN_NAME, skipInHarmony);
114
+ parser.hooks.call.for(identifier).tap(PLUGIN_NAME, skipInHarmony);
121
115
  }
122
116
  }
123
117
  };
@@ -27,7 +27,7 @@ class HarmonyExportExpressionDependency extends NullDependency {
27
27
  * @param {Range} range range
28
28
  * @param {Range} rangeStatement range statement
29
29
  * @param {string} prefix prefix
30
- * @param {string | { range: Range, prefix: string, suffix: string }} [declarationId] declaration id
30
+ * @param {string | { range: Range, prefix: string, suffix: string }=} declarationId declaration id
31
31
  */
32
32
  constructor(range, rangeStatement, prefix, declarationId) {
33
33
  super();
@@ -226,7 +226,8 @@ const getMode = (moduleGraph, dep, runtimeKey) => {
226
226
 
227
227
  const importedExportsType = importedModule.getExportsType(
228
228
  moduleGraph,
229
- /** @type {BuildMeta} */ (parentModule.buildMeta).strictHarmonyModule
229
+ /** @type {BuildMeta} */
230
+ (parentModule.buildMeta).strictHarmonyModule
230
231
  );
231
232
 
232
233
  const ids = dep.getIds(moduleGraph);
@@ -48,7 +48,7 @@ const harmonySpecifierTag = Symbol("harmony import");
48
48
  * @property {number} sourceOrder
49
49
  * @property {string} name
50
50
  * @property {boolean} await
51
- * @property {Record<string, any> | undefined} attributes
51
+ * @property {ImportAttributes=} attributes
52
52
  */
53
53
 
54
54
  module.exports = class HarmonyImportDependencyParserPlugin {
@@ -12,27 +12,27 @@ const HarmonyExports = require("./HarmonyExports");
12
12
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
13
13
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
14
14
 
15
+ const PLUGIN_NAME = "HarmonyTopLevelThisParserPlugin";
16
+
15
17
  class HarmonyTopLevelThisParserPlugin {
16
18
  /**
17
19
  * @param {JavascriptParser} parser the parser
18
20
  * @returns {void}
19
21
  */
20
22
  apply(parser) {
21
- parser.hooks.expression
22
- .for("this")
23
- .tap("HarmonyTopLevelThisParserPlugin", node => {
24
- if (!parser.scope.topLevelScope) return;
25
- if (HarmonyExports.isEnabled(parser.state)) {
26
- const dep = new ConstDependency(
27
- "undefined",
28
- /** @type {Range} */ (node.range),
29
- null
30
- );
31
- dep.loc = /** @type {DependencyLocation} */ (node.loc);
32
- parser.state.module.addPresentationalDependency(dep);
33
- return true;
34
- }
35
- });
23
+ parser.hooks.expression.for("this").tap(PLUGIN_NAME, node => {
24
+ if (!parser.scope.topLevelScope) return;
25
+ if (HarmonyExports.isEnabled(parser.state)) {
26
+ const dep = new ConstDependency(
27
+ "undefined",
28
+ /** @type {Range} */ (node.range),
29
+ null
30
+ );
31
+ dep.loc = /** @type {DependencyLocation} */ (node.loc);
32
+ parser.state.module.addPresentationalDependency(dep);
33
+ return true;
34
+ }
35
+ });
36
36
  }
37
37
  }
38
38
 
@@ -52,6 +52,8 @@ function createError(msg, loc) {
52
52
  return error;
53
53
  }
54
54
 
55
+ const PLUGIN_NAME = "ImportMetaContextDependencyParserPlugin";
56
+
55
57
  module.exports = class ImportMetaContextDependencyParserPlugin {
56
58
  /**
57
59
  * @param {JavascriptParser} parser the parser
@@ -60,7 +62,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
60
62
  apply(parser) {
61
63
  parser.hooks.evaluateIdentifier
62
64
  .for("import.meta.webpackContext")
63
- .tap("ImportMetaContextDependencyParserPlugin", expr =>
65
+ .tap(PLUGIN_NAME, expr =>
64
66
  evaluateToIdentifier(
65
67
  "import.meta.webpackContext",
66
68
  "import.meta",
@@ -70,7 +72,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
70
72
  );
71
73
  parser.hooks.call
72
74
  .for("import.meta.webpackContext")
73
- .tap("ImportMetaContextDependencyParserPlugin", expr => {
75
+ .tap(PLUGIN_NAME, expr => {
74
76
  if (expr.arguments.length < 1 || expr.arguments.length > 2) return;
75
77
  const [directoryNode, optionsNode] = expr.arguments;
76
78
  if (optionsNode && optionsNode.type !== "ObjectExpression") return;
@@ -22,7 +22,7 @@ const NullDependency = require("./NullDependency");
22
22
  /**
23
23
  * @callback GetExportsFromDataFn
24
24
  * @param {JsonValue} data raw json data
25
- * @param {number} [curDepth] current depth
25
+ * @param {number=} curDepth current depth
26
26
  * @returns {ExportSpec[] | null} export spec or nothing
27
27
  */
28
28
 
@@ -31,6 +31,8 @@ const LoaderImportDependency = require("./LoaderImportDependency");
31
31
  * @property {string=} baseUri target base uri
32
32
  */
33
33
 
34
+ const PLUGIN_NAME = "LoaderPlugin";
35
+
34
36
  class LoaderPlugin {
35
37
  /**
36
38
  * Apply the plugin
@@ -39,7 +41,7 @@ class LoaderPlugin {
39
41
  */
40
42
  apply(compiler) {
41
43
  compiler.hooks.compilation.tap(
42
- "LoaderPlugin",
44
+ PLUGIN_NAME,
43
45
  (compilation, { normalModuleFactory }) => {
44
46
  compilation.dependencyFactories.set(
45
47
  LoaderDependency,
@@ -52,10 +54,10 @@ class LoaderPlugin {
52
54
  }
53
55
  );
54
56
 
55
- compiler.hooks.compilation.tap("LoaderPlugin", compilation => {
57
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
56
58
  const moduleGraph = compilation.moduleGraph;
57
59
  NormalModule.getCompilationHooks(compilation).loader.tap(
58
- "LoaderPlugin",
60
+ PLUGIN_NAME,
59
61
  loaderContext => {
60
62
  loaderContext.loadModule = (request, callback) => {
61
63
  const dep = new LoaderDependency(request);
@@ -50,7 +50,7 @@ module.exports.addLocalModule = (state, name) => {
50
50
  /**
51
51
  * @param {ParserState} state parser state
52
52
  * @param {string} name name
53
- * @param {string} [namedModule] named module
53
+ * @param {string=} namedModule named module
54
54
  * @returns {LocalModule | null} local module or null
55
55
  */
56
56
  module.exports.getLocalModule = (state, name, namedModule) => {
@@ -12,58 +12,58 @@ const RequireContextDependency = require("./RequireContextDependency");
12
12
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
13
13
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
14
14
 
15
+ const PLUGIN_NAME = "RequireContextDependencyParserPlugin";
16
+
15
17
  module.exports = class RequireContextDependencyParserPlugin {
16
18
  /**
17
19
  * @param {JavascriptParser} parser the parser
18
20
  * @returns {void}
19
21
  */
20
22
  apply(parser) {
21
- parser.hooks.call
22
- .for("require.context")
23
- .tap("RequireContextDependencyParserPlugin", expr => {
24
- let regExp = /^\.\/.*$/;
25
- let recursive = true;
26
- /** @type {ContextMode} */
27
- let mode = "sync";
28
- switch (expr.arguments.length) {
29
- case 4: {
30
- const modeExpr = parser.evaluateExpression(expr.arguments[3]);
31
- if (!modeExpr.isString()) return;
32
- mode = /** @type {ContextMode} */ (modeExpr.string);
33
- }
34
- // falls through
35
- case 3: {
36
- const regExpExpr = parser.evaluateExpression(expr.arguments[2]);
37
- if (!regExpExpr.isRegExp()) return;
38
- regExp = /** @type {RegExp} */ (regExpExpr.regExp);
39
- }
40
- // falls through
41
- case 2: {
42
- const recursiveExpr = parser.evaluateExpression(expr.arguments[1]);
43
- if (!recursiveExpr.isBoolean()) return;
44
- recursive = /** @type {boolean} */ (recursiveExpr.bool);
45
- }
46
- // falls through
47
- case 1: {
48
- const requestExpr = parser.evaluateExpression(expr.arguments[0]);
49
- if (!requestExpr.isString()) return;
50
- const dep = new RequireContextDependency(
51
- {
52
- request: /** @type {string} */ (requestExpr.string),
53
- recursive,
54
- regExp,
55
- mode,
56
- category: "commonjs"
57
- },
58
- /** @type {Range} */
59
- (expr.range)
60
- );
61
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
62
- dep.optional = Boolean(parser.scope.inTry);
63
- parser.state.current.addDependency(dep);
64
- return true;
65
- }
23
+ parser.hooks.call.for("require.context").tap(PLUGIN_NAME, expr => {
24
+ let regExp = /^\.\/.*$/;
25
+ let recursive = true;
26
+ /** @type {ContextMode} */
27
+ let mode = "sync";
28
+ switch (expr.arguments.length) {
29
+ case 4: {
30
+ const modeExpr = parser.evaluateExpression(expr.arguments[3]);
31
+ if (!modeExpr.isString()) return;
32
+ mode = /** @type {ContextMode} */ (modeExpr.string);
33
+ }
34
+ // falls through
35
+ case 3: {
36
+ const regExpExpr = parser.evaluateExpression(expr.arguments[2]);
37
+ if (!regExpExpr.isRegExp()) return;
38
+ regExp = /** @type {RegExp} */ (regExpExpr.regExp);
39
+ }
40
+ // falls through
41
+ case 2: {
42
+ const recursiveExpr = parser.evaluateExpression(expr.arguments[1]);
43
+ if (!recursiveExpr.isBoolean()) return;
44
+ recursive = /** @type {boolean} */ (recursiveExpr.bool);
45
+ }
46
+ // falls through
47
+ case 1: {
48
+ const requestExpr = parser.evaluateExpression(expr.arguments[0]);
49
+ if (!requestExpr.isString()) return;
50
+ const dep = new RequireContextDependency(
51
+ {
52
+ request: /** @type {string} */ (requestExpr.string),
53
+ recursive,
54
+ regExp,
55
+ mode,
56
+ category: "commonjs"
57
+ },
58
+ /** @type {Range} */
59
+ (expr.range)
60
+ );
61
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
62
+ dep.optional = Boolean(parser.scope.inTry);
63
+ parser.state.current.addDependency(dep);
64
+ return true;
66
65
  }
67
- });
66
+ }
67
+ });
68
68
  }
69
69
  };
@@ -17,128 +17,122 @@ const getFunctionExpression = require("./getFunctionExpression");
17
17
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
18
18
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
19
19
 
20
+ const PLUGIN_NAME = "RequireEnsureDependenciesBlockParserPlugin";
21
+
20
22
  module.exports = class RequireEnsureDependenciesBlockParserPlugin {
21
23
  /**
22
24
  * @param {JavascriptParser} parser the parser
23
25
  * @returns {void}
24
26
  */
25
27
  apply(parser) {
26
- parser.hooks.call
27
- .for("require.ensure")
28
- .tap("RequireEnsureDependenciesBlockParserPlugin", expr => {
29
- /** @type {string | GroupOptions | null} */
30
- let chunkName = null;
31
- let errorExpressionArg = null;
32
- let errorExpression = null;
33
- switch (expr.arguments.length) {
34
- case 4: {
35
- const chunkNameExpr = parser.evaluateExpression(expr.arguments[3]);
28
+ parser.hooks.call.for("require.ensure").tap(PLUGIN_NAME, expr => {
29
+ /** @type {string | GroupOptions | null} */
30
+ let chunkName = null;
31
+ let errorExpressionArg = null;
32
+ let errorExpression = null;
33
+ switch (expr.arguments.length) {
34
+ case 4: {
35
+ const chunkNameExpr = parser.evaluateExpression(expr.arguments[3]);
36
+ if (!chunkNameExpr.isString()) return;
37
+ chunkName =
38
+ /** @type {string} */
39
+ (chunkNameExpr.string);
40
+ }
41
+ // falls through
42
+ case 3: {
43
+ errorExpressionArg = expr.arguments[2];
44
+ errorExpression = getFunctionExpression(errorExpressionArg);
45
+
46
+ if (!errorExpression && !chunkName) {
47
+ const chunkNameExpr = parser.evaluateExpression(expr.arguments[2]);
36
48
  if (!chunkNameExpr.isString()) return;
37
49
  chunkName =
38
50
  /** @type {string} */
39
51
  (chunkNameExpr.string);
40
52
  }
41
- // falls through
42
- case 3: {
43
- errorExpressionArg = expr.arguments[2];
44
- errorExpression = getFunctionExpression(errorExpressionArg);
53
+ }
54
+ // falls through
55
+ case 2: {
56
+ const dependenciesExpr = parser.evaluateExpression(expr.arguments[0]);
57
+ const dependenciesItems = /** @type {BasicEvaluatedExpression[]} */ (
58
+ dependenciesExpr.isArray()
59
+ ? dependenciesExpr.items
60
+ : [dependenciesExpr]
61
+ );
62
+ const successExpressionArg = expr.arguments[1];
63
+ const successExpression = getFunctionExpression(successExpressionArg);
45
64
 
46
- if (!errorExpression && !chunkName) {
47
- const chunkNameExpr = parser.evaluateExpression(
48
- expr.arguments[2]
49
- );
50
- if (!chunkNameExpr.isString()) return;
51
- chunkName =
52
- /** @type {string} */
53
- (chunkNameExpr.string);
54
- }
65
+ if (successExpression) {
66
+ parser.walkExpressions(successExpression.expressions);
67
+ }
68
+ if (errorExpression) {
69
+ parser.walkExpressions(errorExpression.expressions);
55
70
  }
56
- // falls through
57
- case 2: {
58
- const dependenciesExpr = parser.evaluateExpression(
59
- expr.arguments[0]
60
- );
61
- const dependenciesItems =
62
- /** @type {BasicEvaluatedExpression[]} */ (
63
- dependenciesExpr.isArray()
64
- ? dependenciesExpr.items
65
- : [dependenciesExpr]
66
- );
67
- const successExpressionArg = expr.arguments[1];
68
- const successExpression =
69
- getFunctionExpression(successExpressionArg);
70
-
71
- if (successExpression) {
72
- parser.walkExpressions(successExpression.expressions);
73
- }
74
- if (errorExpression) {
75
- parser.walkExpressions(errorExpression.expressions);
76
- }
77
71
 
78
- const depBlock = new RequireEnsureDependenciesBlock(
79
- chunkName,
80
- /** @type {DependencyLocation} */
81
- (expr.loc)
82
- );
83
- const errorCallbackExists =
84
- expr.arguments.length === 4 ||
85
- (!chunkName && expr.arguments.length === 3);
86
- const dep = new RequireEnsureDependency(
87
- /** @type {Range} */ (expr.range),
88
- /** @type {Range} */ (expr.arguments[1].range),
89
- errorCallbackExists &&
90
- /** @type {Range} */ (expr.arguments[2].range)
91
- );
92
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
93
- depBlock.addDependency(dep);
94
- const old = parser.state.current;
95
- parser.state.current = /** @type {TODO} */ (depBlock);
96
- try {
97
- let failed = false;
98
- parser.inScope([], () => {
99
- for (const ee of dependenciesItems) {
100
- if (ee.isString()) {
101
- const ensureDependency = new RequireEnsureItemDependency(
102
- /** @type {string} */ (ee.string)
103
- );
104
- ensureDependency.loc =
105
- /** @type {DependencyLocation} */
106
- (expr.loc);
107
- depBlock.addDependency(ensureDependency);
108
- } else {
109
- failed = true;
110
- }
111
- }
112
- });
113
- if (failed) {
114
- return;
115
- }
116
- if (successExpression) {
117
- if (successExpression.fn.body.type === "BlockStatement") {
118
- parser.walkStatement(successExpression.fn.body);
72
+ const depBlock = new RequireEnsureDependenciesBlock(
73
+ chunkName,
74
+ /** @type {DependencyLocation} */
75
+ (expr.loc)
76
+ );
77
+ const errorCallbackExists =
78
+ expr.arguments.length === 4 ||
79
+ (!chunkName && expr.arguments.length === 3);
80
+ const dep = new RequireEnsureDependency(
81
+ /** @type {Range} */ (expr.range),
82
+ /** @type {Range} */ (expr.arguments[1].range),
83
+ errorCallbackExists &&
84
+ /** @type {Range} */ (expr.arguments[2].range)
85
+ );
86
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
87
+ depBlock.addDependency(dep);
88
+ const old = parser.state.current;
89
+ parser.state.current = /** @type {TODO} */ (depBlock);
90
+ try {
91
+ let failed = false;
92
+ parser.inScope([], () => {
93
+ for (const ee of dependenciesItems) {
94
+ if (ee.isString()) {
95
+ const ensureDependency = new RequireEnsureItemDependency(
96
+ /** @type {string} */ (ee.string)
97
+ );
98
+ ensureDependency.loc =
99
+ /** @type {DependencyLocation} */
100
+ (expr.loc);
101
+ depBlock.addDependency(ensureDependency);
119
102
  } else {
120
- parser.walkExpression(successExpression.fn.body);
103
+ failed = true;
121
104
  }
122
105
  }
123
- old.addBlock(depBlock);
124
- } finally {
125
- parser.state.current = old;
126
- }
127
- if (!successExpression) {
128
- parser.walkExpression(successExpressionArg);
106
+ });
107
+ if (failed) {
108
+ return;
129
109
  }
130
- if (errorExpression) {
131
- if (errorExpression.fn.body.type === "BlockStatement") {
132
- parser.walkStatement(errorExpression.fn.body);
110
+ if (successExpression) {
111
+ if (successExpression.fn.body.type === "BlockStatement") {
112
+ parser.walkStatement(successExpression.fn.body);
133
113
  } else {
134
- parser.walkExpression(errorExpression.fn.body);
114
+ parser.walkExpression(successExpression.fn.body);
135
115
  }
136
- } else if (errorExpressionArg) {
137
- parser.walkExpression(errorExpressionArg);
138
116
  }
139
- return true;
117
+ old.addBlock(depBlock);
118
+ } finally {
119
+ parser.state.current = old;
120
+ }
121
+ if (!successExpression) {
122
+ parser.walkExpression(successExpressionArg);
123
+ }
124
+ if (errorExpression) {
125
+ if (errorExpression.fn.body.type === "BlockStatement") {
126
+ parser.walkStatement(errorExpression.fn.body);
127
+ } else {
128
+ parser.walkExpression(errorExpression.fn.body);
129
+ }
130
+ } else if (errorExpressionArg) {
131
+ parser.walkExpression(errorExpressionArg);
140
132
  }
133
+ return true;
141
134
  }
142
- });
135
+ }
136
+ });
143
137
  }
144
138
  };
@@ -19,7 +19,7 @@ class RequireResolveDependency extends ModuleDependency {
19
19
  /**
20
20
  * @param {string} request the request string
21
21
  * @param {Range} range location in source code
22
- * @param {string} [context] context
22
+ * @param {string=} context context
23
23
  */
24
24
  constructor(request, range, context) {
25
25
  super(request);
@@ -119,7 +119,7 @@ class WorkerPlugin {
119
119
  /**
120
120
  * @param {JavascriptParser} parser the parser
121
121
  * @param {Expression} expr expression
122
- * @returns {[string, [number, number]] | void} parsed
122
+ * @returns {[string, Range] | void} parsed
123
123
  */
124
124
  const parseModuleUrl = (parser, expr) => {
125
125
  if (expr.type !== "NewExpression" || expr.callee.type === "Super")
@@ -259,7 +259,7 @@ class WorkerPlugin {
259
259
 
260
260
  /** @type {string} */
261
261
  let url;
262
- /** @type {[number, number]} */
262
+ /** @type {Range} */
263
263
  let range;
264
264
  /** @type {boolean} */
265
265
  let needNewUrl = false;