webpack 5.87.0 → 5.88.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (144) hide show
  1. package/lib/APIPlugin.js +1 -1
  2. package/lib/AsyncDependenciesBlock.js +3 -3
  3. package/lib/ChunkGraph.js +4 -4
  4. package/lib/ChunkGroup.js +9 -3
  5. package/lib/CompatibilityPlugin.js +50 -30
  6. package/lib/Compilation.js +2 -1
  7. package/lib/ContextModule.js +4 -1
  8. package/lib/ContextReplacementPlugin.js +13 -0
  9. package/lib/DelegatedModule.js +15 -3
  10. package/lib/DelegatedModuleFactoryPlugin.js +6 -0
  11. package/lib/Dependency.js +11 -5
  12. package/lib/DllEntryPlugin.js +11 -1
  13. package/lib/DllReferencePlugin.js +13 -1
  14. package/lib/Entrypoint.js +1 -1
  15. package/lib/ErrorHelpers.js +1 -0
  16. package/lib/EvalSourceMapDevToolPlugin.js +4 -0
  17. package/lib/ExportsInfo.js +17 -3
  18. package/lib/ExportsInfoApiPlugin.js +14 -5
  19. package/lib/ExternalModule.js +5 -0
  20. package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
  21. package/lib/FlagDependencyUsagePlugin.js +3 -1
  22. package/lib/HotModuleReplacementPlugin.js +8 -0
  23. package/lib/InitFragment.js +28 -5
  24. package/lib/JavascriptMetaInfoPlugin.js +11 -6
  25. package/lib/LibManifestPlugin.js +20 -4
  26. package/lib/Module.js +7 -2
  27. package/lib/ModuleProfile.js +1 -0
  28. package/lib/ModuleRestoreError.js +2 -0
  29. package/lib/NodeStuffPlugin.js +32 -6
  30. package/lib/ProvidePlugin.js +13 -4
  31. package/lib/RawModule.js +3 -1
  32. package/lib/RequireJsStuffPlugin.js +7 -0
  33. package/lib/RuntimeModule.js +3 -3
  34. package/lib/RuntimePlugin.js +4 -2
  35. package/lib/RuntimeTemplate.js +2 -2
  36. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  37. package/lib/SourceMapDevToolPlugin.js +7 -2
  38. package/lib/UseStrictPlugin.js +10 -3
  39. package/lib/WebpackIsIncludedPlugin.js +6 -4
  40. package/lib/asset/AssetGenerator.js +2 -1
  41. package/lib/asset/AssetParser.js +11 -6
  42. package/lib/asset/AssetSourceParser.js +8 -3
  43. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  44. package/lib/cache/IdleFileCachePlugin.js +2 -1
  45. package/lib/cache/PackFileCacheStrategy.js +35 -14
  46. package/lib/config/browserslistTargetHandler.js +7 -7
  47. package/lib/config/defaults.js +12 -24
  48. package/lib/container/RemoteRuntimeModule.js +1 -1
  49. package/lib/css/CssLoadingRuntimeModule.js +30 -13
  50. package/lib/css/CssParser.js +11 -1
  51. package/lib/dependencies/AMDDefineDependency.js +34 -4
  52. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
  53. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  54. package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
  55. package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
  56. package/lib/dependencies/CommonJsPlugin.js +13 -8
  57. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  58. package/lib/dependencies/ContextDependency.js +7 -2
  59. package/lib/dependencies/CssImportDependency.js +1 -1
  60. package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
  61. package/lib/dependencies/CssUrlDependency.js +3 -3
  62. package/lib/dependencies/DllEntryDependency.js +5 -0
  63. package/lib/dependencies/DynamicExports.js +10 -6
  64. package/lib/dependencies/ExportsInfoDependency.js +14 -4
  65. package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
  66. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
  67. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
  68. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
  69. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
  70. package/lib/dependencies/HarmonyExports.js +9 -5
  71. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +32 -17
  72. package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
  73. package/lib/dependencies/HarmonyImportSpecifierDependency.js +19 -9
  74. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  75. package/lib/dependencies/ImportDependency.js +5 -3
  76. package/lib/dependencies/ImportEagerDependency.js +5 -3
  77. package/lib/dependencies/ImportMetaPlugin.js +31 -15
  78. package/lib/dependencies/ImportParserPlugin.js +38 -25
  79. package/lib/dependencies/ImportWeakDependency.js +5 -3
  80. package/lib/dependencies/ModuleDependency.js +1 -1
  81. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  82. package/lib/dependencies/ProvidedDependency.js +4 -1
  83. package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
  84. package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
  85. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
  86. package/lib/dependencies/RequireHeaderDependency.js +4 -0
  87. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
  88. package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
  89. package/lib/dependencies/SystemPlugin.js +17 -5
  90. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  91. package/lib/dependencies/URLDependency.js +2 -2
  92. package/lib/dependencies/URLPlugin.js +9 -4
  93. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  94. package/lib/dependencies/WorkerPlugin.js +59 -22
  95. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
  96. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  97. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  98. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  99. package/lib/javascript/JavascriptParser.js +17 -5
  100. package/lib/logging/runtime.js +1 -1
  101. package/lib/logging/truncateArgs.js +4 -0
  102. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
  103. package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
  104. package/lib/optimize/InnerGraph.js +1 -1
  105. package/lib/optimize/InnerGraphPlugin.js +2 -1
  106. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +1 -1
  107. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +1 -1
  108. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -1
  109. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -1
  110. package/lib/runtime/AsyncModuleRuntimeModule.js +4 -4
  111. package/lib/runtime/AutoPublicPathRuntimeModule.js +1 -1
  112. package/lib/runtime/BaseUriRuntimeModule.js +1 -1
  113. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  114. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
  115. package/lib/runtime/CompatRuntimeModule.js +1 -1
  116. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
  117. package/lib/runtime/CreateScriptRuntimeModule.js +1 -1
  118. package/lib/runtime/CreateScriptUrlRuntimeModule.js +1 -1
  119. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +1 -1
  120. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -1
  121. package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -1
  122. package/lib/runtime/GetFullHashRuntimeModule.js +1 -1
  123. package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -1
  124. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  125. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  126. package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
  127. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  128. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
  129. package/lib/runtime/NonceRuntimeModule.js +1 -1
  130. package/lib/runtime/OnChunksLoadedRuntimeModule.js +1 -1
  131. package/lib/runtime/PublicPathRuntimeModule.js +1 -1
  132. package/lib/runtime/RelativeUrlRuntimeModule.js +1 -1
  133. package/lib/runtime/RuntimeIdRuntimeModule.js +1 -1
  134. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
  135. package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -1
  136. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  137. package/lib/sharing/ConsumeSharedRuntimeModule.js +1 -1
  138. package/lib/sharing/ShareRuntimeModule.js +1 -1
  139. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +1 -1
  140. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +1 -1
  141. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
  142. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  143. package/package.json +2 -1
  144. package/types.d.ts +86 -38
@@ -189,6 +189,10 @@ class HotModuleReplacementPlugin {
189
189
  return true;
190
190
  };
191
191
 
192
+ /**
193
+ * @param {JavascriptParser} parser the parser
194
+ * @returns {void}
195
+ */
192
196
  const applyModuleHot = parser => {
193
197
  parser.hooks.evaluateIdentifier.for("module.hot").tap(
194
198
  {
@@ -221,6 +225,10 @@ class HotModuleReplacementPlugin {
221
225
  .tap(PLUGIN_NAME, createHMRExpressionHandler(parser));
222
226
  };
223
227
 
228
+ /**
229
+ * @param {JavascriptParser} parser the parser
230
+ * @returns {void}
231
+ */
224
232
  const applyImportMetaHot = parser => {
225
233
  parser.hooks.evaluateIdentifier
226
234
  .for("import.meta.webpackHot")
@@ -10,17 +10,21 @@ const makeSerializable = require("./util/makeSerializable");
10
10
 
11
11
  /** @typedef {import("webpack-sources").Source} Source */
12
12
  /** @typedef {import("./Generator").GenerateContext} GenerateContext */
13
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
14
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
13
15
 
14
16
  /**
15
- * @param {InitFragment} fragment the init fragment
17
+ * @template T
18
+ * @param {InitFragment<T>} fragment the init fragment
16
19
  * @param {number} index index
17
- * @returns {[InitFragment, number]} tuple with both
20
+ * @returns {[InitFragment<T>, number]} tuple with both
18
21
  */
19
22
  const extractFragmentIndex = (fragment, index) => [fragment, index];
20
23
 
21
24
  /**
22
- * @param {[InitFragment, number]} a first pair
23
- * @param {[InitFragment, number]} b second pair
25
+ * @template T
26
+ * @param {[InitFragment<T>, number]} a first pair
27
+ * @param {[InitFragment<T>, number]} b second pair
24
28
  * @returns {number} sort value
25
29
  */
26
30
  const sortFragmentWithIndex = ([a, i], [b, j]) => {
@@ -66,6 +70,14 @@ class InitFragment {
66
70
  return this.endContent;
67
71
  }
68
72
 
73
+ /**
74
+ * @template Context
75
+ * @template T
76
+ * @param {Source} source sources
77
+ * @param {InitFragment<T>[]} initFragments init fragments
78
+ * @param {Context} context context
79
+ * @returns {Source} source
80
+ */
69
81
  static addToSource(source, initFragments, context) {
70
82
  if (initFragments.length > 0) {
71
83
  // Sort fragments by position. If 2 fragments have the same position,
@@ -77,7 +89,12 @@ class InitFragment {
77
89
  // Deduplicate fragments. If a fragment has no key, it is always included.
78
90
  const keyedFragments = new Map();
79
91
  for (const [fragment] of sortedFragments) {
80
- if (typeof fragment.mergeAll === "function") {
92
+ if (
93
+ typeof (
94
+ /** @type {InitFragment<T> & { mergeAll?: (fragments: InitFragment[]) => InitFragment[] }} */
95
+ (fragment).mergeAll
96
+ ) === "function"
97
+ ) {
81
98
  if (!fragment.key) {
82
99
  throw new Error(
83
100
  `InitFragment with mergeAll function must have a valid key: ${fragment.constructor.name}`
@@ -125,6 +142,9 @@ class InitFragment {
125
142
  }
126
143
  }
127
144
 
145
+ /**
146
+ * @param {ObjectSerializerContext} context context
147
+ */
128
148
  serialize(context) {
129
149
  const { write } = context;
130
150
 
@@ -135,6 +155,9 @@ class InitFragment {
135
155
  write(this.endContent);
136
156
  }
137
157
 
158
+ /**
159
+ * @param {ObjectDeserializerContext} context context
160
+ */
138
161
  deserialize(context) {
139
162
  const { read } = context;
140
163
 
@@ -13,6 +13,7 @@ const {
13
13
  const InnerGraph = require("./optimize/InnerGraph");
14
14
 
15
15
  /** @typedef {import("./Compiler")} Compiler */
16
+ /** @typedef {import("./Module").BuildInfo} BuildInfo */
16
17
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
17
18
 
18
19
  const PLUGIN_NAME = "JavascriptMetaInfoPlugin";
@@ -33,8 +34,11 @@ class JavascriptMetaInfoPlugin {
33
34
  */
34
35
  const handler = parser => {
35
36
  parser.hooks.call.for("eval").tap(PLUGIN_NAME, () => {
36
- parser.state.module.buildInfo.moduleConcatenationBailout = "eval()";
37
- parser.state.module.buildInfo.usingEval = true;
37
+ const buildInfo =
38
+ /** @type {BuildInfo} */
39
+ (parser.state.module.buildInfo);
40
+ buildInfo.moduleConcatenationBailout = "eval()";
41
+ buildInfo.usingEval = true;
38
42
  const currentSymbol = InnerGraph.getTopLevelSymbol(parser.state);
39
43
  if (currentSymbol) {
40
44
  InnerGraph.addUsage(parser.state, null, currentSymbol);
@@ -43,11 +47,12 @@ class JavascriptMetaInfoPlugin {
43
47
  }
44
48
  });
45
49
  parser.hooks.finish.tap(PLUGIN_NAME, () => {
46
- let topLevelDeclarations =
47
- parser.state.module.buildInfo.topLevelDeclarations;
50
+ const buildInfo =
51
+ /** @type {BuildInfo} */
52
+ (parser.state.module.buildInfo);
53
+ let topLevelDeclarations = buildInfo.topLevelDeclarations;
48
54
  if (topLevelDeclarations === undefined) {
49
- topLevelDeclarations =
50
- parser.state.module.buildInfo.topLevelDeclarations = new Set();
55
+ topLevelDeclarations = buildInfo.topLevelDeclarations = new Set();
51
56
  }
52
57
  for (const name of parser.scope.definitions.asSet()) {
53
58
  const freeInfo = parser.getFreeInfoFromVariable(name);
@@ -12,15 +12,29 @@ const { compareModulesById } = require("./util/comparators");
12
12
  const { dirname, mkdirp } = require("./util/fs");
13
13
 
14
14
  /** @typedef {import("./Compiler")} Compiler */
15
+ /** @typedef {import("./Module").BuildMeta} BuildMeta */
15
16
 
16
17
  /**
17
18
  * @typedef {Object} ManifestModuleData
18
19
  * @property {string | number} id
19
- * @property {Object} buildMeta
20
- * @property {boolean | string[]} exports
20
+ * @property {BuildMeta} buildMeta
21
+ * @property {boolean | string[] | undefined} exports
22
+ */
23
+
24
+ /**
25
+ * @typedef {Object} LibManifestPluginOptions
26
+ * @property {string=} context Context of requests in the manifest file (defaults to the webpack context).
27
+ * @property {boolean=} entryOnly If true, only entry points will be exposed (default: true).
28
+ * @property {boolean=} format If true, manifest json file (output) will be formatted.
29
+ * @property {string=} name Name of the exposed dll function (external name, use value of 'output.library').
30
+ * @property {string} path Absolute path to the manifest json file (output).
31
+ * @property {string=} type Type of the dll bundle (external type, use value of 'output.libraryTarget').
21
32
  */
22
33
 
23
34
  class LibManifestPlugin {
35
+ /**
36
+ * @param {LibManifestPluginOptions} options the options
37
+ */
24
38
  constructor(options) {
25
39
  this.options = options;
26
40
  }
@@ -67,7 +81,9 @@ class LibManifestPlugin {
67
81
  continue;
68
82
  }
69
83
  const ident = module.libIdent({
70
- context: this.options.context || compiler.options.context,
84
+ context:
85
+ this.options.context ||
86
+ /** @type {string} */ (compiler.options.context),
71
87
  associatedObjectForCache: compiler.root
72
88
  });
73
89
  if (ident) {
@@ -76,7 +92,7 @@ class LibManifestPlugin {
76
92
  /** @type {ManifestModuleData} */
77
93
  const data = {
78
94
  id: chunkGraph.getModuleId(module),
79
- buildMeta: module.buildMeta,
95
+ buildMeta: /** @type {BuildMeta} */ (module.buildMeta),
80
96
  exports: Array.isArray(providedExports)
81
97
  ? providedExports
82
98
  : undefined
package/lib/Module.js CHANGED
@@ -109,6 +109,11 @@ const makeSerializable = require("./util/makeSerializable");
109
109
  /** @typedef {KnownBuildMeta & Record<string, any>} BuildMeta */
110
110
  /** @typedef {Record<string, any>} BuildInfo */
111
111
 
112
+ /**
113
+ * @typedef {Object} FactoryMeta
114
+ * @property {boolean=} sideEffectFree
115
+ */
116
+
112
117
  const EMPTY_RESOLVE_OPTIONS = {};
113
118
 
114
119
  let debugId = 1000;
@@ -159,7 +164,7 @@ class Module extends DependenciesBlock {
159
164
  // Info from Factory
160
165
  /** @type {ResolveOptions | undefined} */
161
166
  this.resolveOptions = EMPTY_RESOLVE_OPTIONS;
162
- /** @type {object | undefined} */
167
+ /** @type {FactoryMeta | undefined} */
163
168
  this.factoryMeta = undefined;
164
169
  // TODO refactor this -> options object filled from Factory
165
170
  // TODO webpack 6: use an enum
@@ -439,7 +444,7 @@ class Module extends DependenciesBlock {
439
444
 
440
445
  /**
441
446
  * @param {ModuleGraph} moduleGraph the module graph
442
- * @param {boolean} strict the importing module is strict
447
+ * @param {boolean | undefined} strict the importing module is strict
443
448
  * @returns {"namespace" | "default-only" | "default-with-named" | "dynamic"} export type
444
449
  * "namespace": Exports is already a namespace object. namespace = exports.
445
450
  * "dynamic": Check at runtime if __esModule is set. When set: namespace = { ...exports, default: exports }. When not set: namespace = { default: exports }.
@@ -34,6 +34,7 @@ class ModuleProfile {
34
34
  this.storing = 0;
35
35
  this.storingParallelismFactor = 0;
36
36
 
37
+ /** @type {{ start: number, end: number }[] | undefined } */
37
38
  this.additionalFactoryTimes = undefined;
38
39
  this.additionalFactories = 0;
39
40
  this.additionalFactoriesParallelismFactor = 0;
@@ -16,6 +16,7 @@ class ModuleRestoreError extends WebpackError {
16
16
  */
17
17
  constructor(module, err) {
18
18
  let message = "Module restore failed: ";
19
+ /** @type {string | undefined} */
19
20
  let details = undefined;
20
21
  if (err !== null && typeof err === "object") {
21
22
  if (typeof err.stack === "string" && err.stack) {
@@ -33,6 +34,7 @@ class ModuleRestoreError extends WebpackError {
33
34
  super(message);
34
35
 
35
36
  this.name = "ModuleRestoreError";
37
+ /** @type {string | undefined} */
36
38
  this.details = details;
37
39
  this.module = module;
38
40
  this.error = err;
@@ -21,14 +21,23 @@ const { relative } = require("./util/fs");
21
21
  const { parseResource } = require("./util/identifier");
22
22
 
23
23
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
24
+ /** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
25
+ /** @typedef {import("../declarations/WebpackOptions").NodeOptions} NodeOptions */
24
26
  /** @typedef {import("./Compiler")} Compiler */
25
27
  /** @typedef {import("./Dependency")} Dependency */
28
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
26
29
  /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
30
+ /** @typedef {import("./NormalModule")} NormalModule */
27
31
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
32
+ /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
33
+ /** @typedef {import("./javascript/JavascriptParser").Range} Range */
28
34
 
29
35
  const PLUGIN_NAME = "NodeStuffPlugin";
30
36
 
31
37
  class NodeStuffPlugin {
38
+ /**
39
+ * @param {NodeOptions} options options
40
+ */
32
41
  constructor(options) {
33
42
  this.options = options;
34
43
  }
@@ -43,6 +52,11 @@ class NodeStuffPlugin {
43
52
  compiler.hooks.compilation.tap(
44
53
  PLUGIN_NAME,
45
54
  (compilation, { normalModuleFactory }) => {
55
+ /**
56
+ * @param {JavascriptParser} parser the parser
57
+ * @param {JavascriptParserOptions} parserOptions options
58
+ * @returns {void}
59
+ */
46
60
  const handler = (parser, parserOptions) => {
47
61
  if (parserOptions.node === false) return;
48
62
 
@@ -56,10 +70,10 @@ class NodeStuffPlugin {
56
70
  parser.hooks.expression.for("global").tap(PLUGIN_NAME, expr => {
57
71
  const dep = new ConstDependency(
58
72
  RuntimeGlobals.global,
59
- expr.range,
73
+ /** @type {Range} */ (expr.range),
60
74
  [RuntimeGlobals.global]
61
75
  );
62
- dep.loc = expr.loc;
76
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
63
77
  parser.state.module.addPresentationalDependency(dep);
64
78
 
65
79
  // TODO webpack 6 remove
@@ -76,25 +90,31 @@ class NodeStuffPlugin {
76
90
  parser.hooks.rename.for("global").tap(PLUGIN_NAME, expr => {
77
91
  const dep = new ConstDependency(
78
92
  RuntimeGlobals.global,
79
- expr.range,
93
+ /** @type {Range} */ (expr.range),
80
94
  [RuntimeGlobals.global]
81
95
  );
82
- dep.loc = expr.loc;
96
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
83
97
  parser.state.module.addPresentationalDependency(dep);
84
98
  return false;
85
99
  });
86
100
  }
87
101
 
102
+ /**
103
+ * @param {string} expressionName expression name
104
+ * @param {(module: NormalModule) => string} fn function
105
+ * @param {string=} warning warning
106
+ * @returns {void}
107
+ */
88
108
  const setModuleConstant = (expressionName, fn, warning) => {
89
109
  parser.hooks.expression
90
110
  .for(expressionName)
91
111
  .tap(PLUGIN_NAME, expr => {
92
112
  const dep = new CachedConstDependency(
93
113
  JSON.stringify(fn(parser.state.module)),
94
- expr.range,
114
+ /** @type {Range} */ (expr.range),
95
115
  expressionName
96
116
  );
97
- dep.loc = expr.loc;
117
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
98
118
  parser.state.module.addPresentationalDependency(dep);
99
119
 
100
120
  // TODO webpack 6 remove
@@ -108,6 +128,12 @@ class NodeStuffPlugin {
108
128
  });
109
129
  };
110
130
 
131
+ /**
132
+ * @param {string} expressionName expression name
133
+ * @param {string} value value
134
+ * @param {string=} warning warning
135
+ * @returns {void}
136
+ */
111
137
  const setConstant = (expressionName, value, warning) =>
112
138
  setModuleConstant(expressionName, () => value, warning);
113
139
 
@@ -14,7 +14,11 @@ const ConstDependency = require("./dependencies/ConstDependency");
14
14
  const ProvidedDependency = require("./dependencies/ProvidedDependency");
15
15
  const { approve } = require("./javascript/JavascriptParserHelpers");
16
16
 
17
+ /** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
17
18
  /** @typedef {import("./Compiler")} Compiler */
19
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
20
+ /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
21
+ /** @typedef {import("./javascript/JavascriptParser").Range} Range */
18
22
 
19
23
  const PLUGIN_NAME = "ProvidePlugin";
20
24
 
@@ -48,6 +52,11 @@ class ProvidePlugin {
48
52
  ProvidedDependency,
49
53
  new ProvidedDependency.Template()
50
54
  );
55
+ /**
56
+ * @param {JavascriptParser} parser the parser
57
+ * @param {JavascriptParserOptions} parserOptions options
58
+ * @returns {void}
59
+ */
51
60
  const handler = (parser, parserOptions) => {
52
61
  Object.keys(definitions).forEach(name => {
53
62
  const request = [].concat(definitions[name]);
@@ -67,9 +76,9 @@ class ProvidePlugin {
67
76
  request[0],
68
77
  nameIdentifier,
69
78
  request.slice(1),
70
- expr.range
79
+ /** @type {Range} */ (expr.range)
71
80
  );
72
- dep.loc = expr.loc;
81
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
73
82
  parser.state.module.addDependency(dep);
74
83
  return true;
75
84
  });
@@ -82,9 +91,9 @@ class ProvidePlugin {
82
91
  request[0],
83
92
  nameIdentifier,
84
93
  request.slice(1),
85
- expr.callee.range
94
+ /** @type {Range} */ (expr.callee.range)
86
95
  );
87
- dep.loc = expr.callee.loc;
96
+ dep.loc = /** @type {DependencyLocation} */ (expr.callee.loc);
88
97
  parser.state.module.addDependency(dep);
89
98
  parser.walkExpressions(expr.arguments);
90
99
  return true;
package/lib/RawModule.js CHANGED
@@ -72,7 +72,9 @@ class RawModule extends Module {
72
72
  * @returns {string} a user readable identifier of the module
73
73
  */
74
74
  readableIdentifier(requestShortener) {
75
- return requestShortener.shorten(this.readableIdentifierStr);
75
+ return /** @type {string} */ (
76
+ requestShortener.shorten(this.readableIdentifierStr)
77
+ );
76
78
  }
77
79
 
78
80
  /**
@@ -15,7 +15,9 @@ const {
15
15
  toConstantDependency
16
16
  } = require("./javascript/JavascriptParserHelpers");
17
17
 
18
+ /** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
18
19
  /** @typedef {import("./Compiler")} Compiler */
20
+ /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
19
21
 
20
22
  const PLUGIN_NAME = "RequireJsStuffPlugin";
21
23
 
@@ -33,6 +35,11 @@ module.exports = class RequireJsStuffPlugin {
33
35
  ConstDependency,
34
36
  new ConstDependency.Template()
35
37
  );
38
+ /**
39
+ * @param {JavascriptParser} parser the parser
40
+ * @param {JavascriptParserOptions} parserOptions options
41
+ * @returns {void}
42
+ */
36
43
  const handler = (parser, parserOptions) => {
37
44
  if (
38
45
  parserOptions.requireJs === undefined ||
@@ -166,7 +166,7 @@ class RuntimeModule extends Module {
166
166
  /* istanbul ignore next */
167
167
  /**
168
168
  * @abstract
169
- * @returns {string} runtime code
169
+ * @returns {string | null} runtime code
170
170
  */
171
171
  generate() {
172
172
  const AbstractMethodError = require("./AbstractMethodError");
@@ -174,11 +174,11 @@ class RuntimeModule extends Module {
174
174
  }
175
175
 
176
176
  /**
177
- * @returns {string} runtime code
177
+ * @returns {string | null} runtime code
178
178
  */
179
179
  getGeneratedCode() {
180
180
  if (this._cachedGeneratedCode) {
181
- return this._cachedGeneratedCode;
181
+ return /** @type {string | null} */ (this._cachedGeneratedCode);
182
182
  }
183
183
  return (this._cachedGeneratedCode = this.generate());
184
184
  }
@@ -128,7 +128,8 @@ class RuntimePlugin {
128
128
  });
129
129
  }
130
130
  for (const req of Object.keys(TREE_DEPENDENCIES)) {
131
- const deps = TREE_DEPENDENCIES[req];
131
+ const deps =
132
+ TREE_DEPENDENCIES[/** @type {keyof TREE_DEPENDENCIES} */ (req)];
132
133
  compilation.hooks.runtimeRequirementInTree
133
134
  .for(req)
134
135
  .tap("RuntimePlugin", (chunk, set) => {
@@ -136,7 +137,8 @@ class RuntimePlugin {
136
137
  });
137
138
  }
138
139
  for (const req of Object.keys(MODULE_DEPENDENCIES)) {
139
- const deps = MODULE_DEPENDENCIES[req];
140
+ const deps =
141
+ MODULE_DEPENDENCIES[/** @type {keyof MODULE_DEPENDENCIES} */ (req)];
140
142
  compilation.hooks.runtimeRequirementInModule
141
143
  .for(req)
142
144
  .tap("RuntimePlugin", (chunk, set) => {
@@ -396,7 +396,7 @@ class RuntimeTemplate {
396
396
 
397
397
  /**
398
398
  * @param {Object} options options object
399
- * @param {Module} options.module the module
399
+ * @param {Module | null} options.module the module
400
400
  * @param {ChunkGraph} options.chunkGraph the chunk graph
401
401
  * @param {string} options.request the request that should be printed as comment
402
402
  * @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
@@ -439,7 +439,7 @@ class RuntimeTemplate {
439
439
 
440
440
  /**
441
441
  * @param {Object} options options object
442
- * @param {Module} options.module the module
442
+ * @param {Module | null} options.module the module
443
443
  * @param {ChunkGraph} options.chunkGraph the chunk graph
444
444
  * @param {string} options.request the request that should be printed as comment
445
445
  * @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
@@ -7,9 +7,13 @@
7
7
 
8
8
  const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
9
9
 
10
+ /** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
10
11
  /** @typedef {import("./Compilation")} Compilation */
11
12
 
12
13
  class SourceMapDevToolModuleOptionsPlugin {
14
+ /**
15
+ * @param {SourceMapDevToolPluginOptions} options options
16
+ */
13
17
  constructor(options) {
14
18
  this.options = options;
15
19
  }
@@ -22,6 +22,7 @@ const { makePathsAbsolute } = require("./util/identifier");
22
22
  /** @typedef {import("./Cache").Etag} Etag */
23
23
  /** @typedef {import("./CacheFacade").ItemCacheFacade} ItemCacheFacade */
24
24
  /** @typedef {import("./Chunk")} Chunk */
25
+ /** @typedef {import("./Compilation").Asset} Asset */
25
26
  /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
26
27
  /** @typedef {import("./Compilation").PathData} PathData */
27
28
  /** @typedef {import("./Compiler")} Compiler */
@@ -227,7 +228,9 @@ class SourceMapDevToolPlugin {
227
228
  asyncLib.each(
228
229
  files,
229
230
  (file, callback) => {
230
- const asset = compilation.getAsset(file);
231
+ const asset =
232
+ /** @type {Readonly<Asset>} */
233
+ (compilation.getAsset(file));
231
234
  if (asset.info.related && asset.info.related.sourceMap) {
232
235
  fileIndex++;
233
236
  return callback();
@@ -363,7 +366,9 @@ class SourceMapDevToolPlugin {
363
366
  // find modules with conflicting source names
364
367
  for (let idx = 0; idx < allModules.length; idx++) {
365
368
  const module = allModules[idx];
366
- let sourceName = moduleToSourceNameMapping.get(module);
369
+ let sourceName =
370
+ /** @type {string} */
371
+ (moduleToSourceNameMapping.get(module));
367
372
  let hasName = conflictDetectionSet.has(sourceName);
368
373
  if (!hasName) {
369
374
  conflictDetectionSet.add(sourceName);
@@ -13,7 +13,10 @@ const {
13
13
  const ConstDependency = require("./dependencies/ConstDependency");
14
14
 
15
15
  /** @typedef {import("./Compiler")} Compiler */
16
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
17
+ /** @typedef {import("./Module").BuildInfo} BuildInfo */
16
18
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
19
+ /** @typedef {import("./javascript/JavascriptParser").Range} Range */
17
20
 
18
21
  const PLUGIN_NAME = "UseStrictPlugin";
19
22
 
@@ -42,10 +45,14 @@ class UseStrictPlugin {
42
45
  // Remove "use strict" expression. It will be added later by the renderer again.
43
46
  // This is necessary in order to not break the strict mode when webpack prepends code.
44
47
  // @see https://github.com/webpack/webpack/issues/1970
45
- const dep = new ConstDependency("", firstNode.range);
46
- dep.loc = firstNode.loc;
48
+ const dep = new ConstDependency(
49
+ "",
50
+ /** @type {Range} */ (firstNode.range)
51
+ );
52
+ dep.loc = /** @type {DependencyLocation} */ (firstNode.loc);
47
53
  parser.state.module.addPresentationalDependency(dep);
48
- parser.state.module.buildInfo.strict = true;
54
+ /** @type {BuildInfo} */
55
+ (parser.state.module.buildInfo).strict = true;
49
56
  }
50
57
  });
51
58
  };
@@ -16,10 +16,12 @@ const {
16
16
  toConstantDependency
17
17
  } = require("./javascript/JavascriptParserHelpers");
18
18
 
19
- /** @typedef {import("enhanced-resolve/lib/Resolver")} Resolver */
19
+ /** @typedef {import("enhanced-resolve").Resolver} Resolver */
20
20
  /** @typedef {import("./Compiler")} Compiler */
21
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
21
22
  /** @typedef {import("./Module")} Module */
22
23
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
24
+ /** @typedef {import("./javascript/JavascriptParser").Range} Range */
23
25
 
24
26
  const PLUGIN_NAME = "WebpackIsIncludedPlugin";
25
27
 
@@ -61,10 +63,10 @@ class WebpackIsIncludedPlugin {
61
63
  if (!request.isString()) return;
62
64
 
63
65
  const dep = new WebpackIsIncludedDependency(
64
- request.string,
65
- expr.range
66
+ /** @type {string} */ (request.string),
67
+ /** @type {Range} */ (expr.range)
66
68
  );
67
- dep.loc = expr.loc;
69
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
68
70
  parser.state.module.addDependency(dep);
69
71
  return true;
70
72
  });
@@ -181,6 +181,7 @@ class AssetGenerator extends Generator {
181
181
  );
182
182
  }
183
183
 
184
+ /** @type {string | boolean | undefined} */
184
185
  let mimeType = this.dataUrlOptions.mimetype;
185
186
  if (mimeType === undefined) {
186
187
  const ext = path.extname(module.nameForCondition());
@@ -213,7 +214,7 @@ class AssetGenerator extends Generator {
213
214
  );
214
215
  }
215
216
 
216
- return mimeType;
217
+ return /** @type {string} */ (mimeType);
217
218
  }
218
219
 
219
220
  /**
@@ -9,6 +9,8 @@ const Parser = require("../Parser");
9
9
 
10
10
  /** @typedef {import("../../declarations/WebpackOptions").AssetParserDataUrlOptions} AssetParserDataUrlOptions */
11
11
  /** @typedef {import("../../declarations/WebpackOptions").AssetParserOptions} AssetParserOptions */
12
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
13
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
12
14
  /** @typedef {import("../Parser").ParserState} ParserState */
13
15
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
14
16
 
@@ -30,22 +32,25 @@ class AssetParser extends Parser {
30
32
  if (typeof source === "object" && !Buffer.isBuffer(source)) {
31
33
  throw new Error("AssetParser doesn't accept preparsed AST");
32
34
  }
33
- state.module.buildInfo.strict = true;
34
- state.module.buildMeta.exportsType = "default";
35
- state.module.buildMeta.defaultObject = false;
35
+
36
+ const buildInfo = /** @type {BuildInfo} */ (state.module.buildInfo);
37
+ buildInfo.strict = true;
38
+ const buildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
39
+ buildMeta.exportsType = "default";
40
+ buildMeta.defaultObject = false;
36
41
 
37
42
  if (typeof this.dataUrlCondition === "function") {
38
- state.module.buildInfo.dataUrl = this.dataUrlCondition(source, {
43
+ buildInfo.dataUrl = this.dataUrlCondition(source, {
39
44
  filename: state.module.matchResource || state.module.resource,
40
45
  module: state.module
41
46
  });
42
47
  } else if (typeof this.dataUrlCondition === "boolean") {
43
- state.module.buildInfo.dataUrl = this.dataUrlCondition;
48
+ buildInfo.dataUrl = this.dataUrlCondition;
44
49
  } else if (
45
50
  this.dataUrlCondition &&
46
51
  typeof this.dataUrlCondition === "object"
47
52
  ) {
48
- state.module.buildInfo.dataUrl =
53
+ buildInfo.dataUrl =
49
54
  Buffer.byteLength(source) <=
50
55
  /** @type {NonNullable<AssetParserDataUrlOptions["maxSize"]>} */
51
56
  (this.dataUrlCondition.maxSize);