webpack 5.90.2 → 5.91.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.
- package/README.md +5 -5
- package/bin/webpack.js +5 -1
- package/lib/APIPlugin.js +8 -4
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/Cache.js +7 -1
- package/lib/CacheFacade.js +3 -3
- package/lib/ChunkGraph.js +32 -18
- package/lib/ChunkGroup.js +14 -14
- package/lib/CleanPlugin.js +7 -5
- package/lib/Compilation.js +263 -94
- package/lib/Compiler.js +199 -83
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +4 -1
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/CssModule.js +0 -3
- package/lib/DefinePlugin.js +4 -2
- package/lib/DelegatedModule.js +2 -1
- package/lib/Dependency.js +4 -2
- package/lib/DependencyTemplate.js +7 -2
- package/lib/DllModule.js +3 -1
- package/lib/DllReferencePlugin.js +6 -2
- package/lib/EntryOptionPlugin.js +4 -1
- package/lib/EntryPlugin.js +6 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ExportsInfo.js +1 -4
- package/lib/ExternalModule.js +120 -25
- package/lib/ExternalModuleFactoryPlugin.js +37 -2
- package/lib/FileSystemInfo.js +1 -1
- package/lib/Generator.js +2 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/InitFragment.js +5 -3
- package/lib/LibManifestPlugin.js +15 -7
- package/lib/Module.js +54 -5
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +56 -27
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +61 -17
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +239 -86
- package/lib/NormalModuleFactory.js +163 -32
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +4 -2
- package/lib/ResolverFactory.js +5 -1
- package/lib/RuntimeModule.js +6 -5
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +102 -34
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +12 -5
- package/lib/TemplatedPathPlugin.js +32 -6
- package/lib/Watching.js +67 -60
- package/lib/WebpackError.js +6 -6
- package/lib/WebpackOptionsApply.js +18 -5
- package/lib/asset/RawDataUrlModule.js +5 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +220 -392
- package/lib/cache/IdleFileCachePlugin.js +8 -3
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +49 -16
- package/lib/cache/ResolverCachePlugin.js +14 -6
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/config/defaults.js +24 -1
- package/lib/config/normalization.js +3 -1
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +5 -2
- package/lib/container/ContainerPlugin.js +14 -10
- package/lib/container/FallbackModule.js +3 -2
- package/lib/container/RemoteModule.js +2 -1
- package/lib/container/RemoteRuntimeModule.js +12 -3
- package/lib/css/CssExportsGenerator.js +34 -17
- package/lib/css/CssGenerator.js +20 -2
- package/lib/css/CssLoadingRuntimeModule.js +212 -96
- package/lib/css/CssModulesPlugin.js +47 -13
- package/lib/debug/ProfilingPlugin.js +27 -2
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
- package/lib/dependencies/CommonJsExportsDependency.js +13 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
- package/lib/dependencies/ContextDependencyHelpers.js +49 -29
- package/lib/dependencies/ContextElementDependency.js +8 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +63 -8
- package/lib/dependencies/CssUrlDependency.js +5 -3
- package/lib/dependencies/ExportsInfoDependency.js +4 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
- package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
- package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
- package/lib/dependencies/HarmonyImportDependency.js +28 -12
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +44 -16
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +21 -10
- package/lib/dependencies/ImportDependency.js +9 -2
- package/lib/dependencies/ImportEagerDependency.js +4 -2
- package/lib/dependencies/ImportMetaContextDependency.js +7 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
- package/lib/dependencies/ImportParserPlugin.js +12 -4
- package/lib/dependencies/ImportWeakDependency.js +4 -2
- package/lib/dependencies/LoaderDependency.js +2 -1
- package/lib/dependencies/LoaderImportDependency.js +2 -1
- package/lib/dependencies/ModuleDependency.js +4 -5
- package/lib/dependencies/PureExpressionDependency.js +4 -1
- package/lib/dependencies/RequireContextPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
- package/lib/dependencies/RequireEnsureDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +7 -4
- package/lib/dependencies/WorkerDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +6 -5
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
- package/lib/hmr/LazyCompilationPlugin.js +2 -1
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/JavascriptParser.js +169 -57
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/StartupHelpers.js +22 -5
- package/lib/logging/Logger.js +27 -2
- package/lib/logging/createConsoleLogger.js +11 -7
- package/lib/node/NodeEnvironmentPlugin.js +13 -7
- package/lib/node/NodeWatchFileSystem.js +37 -26
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/nodeConsole.js +24 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +140 -55
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/InnerGraph.js +7 -2
- package/lib/optimize/InnerGraphPlugin.js +36 -13
- package/lib/optimize/ModuleConcatenationPlugin.js +12 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/RuntimeChunkPlugin.js +6 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +46 -15
- package/lib/optimize/SplitChunksPlugin.js +2 -2
- package/lib/performance/SizeLimitsPlugin.js +11 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +4 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/serialization/FileMiddleware.js +1 -0
- package/lib/serialization/ObjectMiddleware.js +2 -0
- package/lib/serialization/Serializer.js +19 -0
- package/lib/sharing/ConsumeSharedModule.js +3 -2
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedModule.js +2 -1
- package/lib/sharing/ProvideSharedPlugin.js +12 -5
- package/lib/sharing/resolveMatchedConfigs.js +2 -2
- package/lib/sharing/utils.js +13 -6
- package/lib/util/StackedCacheMap.js +26 -0
- package/lib/util/WeakTupleMap.js +57 -13
- package/lib/util/cleverMerge.js +24 -11
- package/lib/util/comparators.js +34 -14
- package/lib/util/conventions.js +129 -0
- package/lib/util/fs.js +379 -65
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/memoize.js +2 -0
- package/lib/util/runtime.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +15 -6
- package/lib/wasm-sync/WebAssemblyGenerator.js +27 -6
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -1
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
- package/lib/webpack.js +11 -5
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
- package/package.json +25 -26
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +69 -8
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +5 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/types.d.ts +1772 -673
@@ -87,13 +87,18 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
87
87
|
/** @typedef {import("estree").Super} Super */
|
88
88
|
/** @typedef {import("estree").TaggedTemplateExpression} TaggedTemplateExpression */
|
89
89
|
/** @typedef {import("estree").TemplateLiteral} TemplateLiteral */
|
90
|
-
/** @typedef {
|
91
|
-
/** @
|
90
|
+
/** @typedef {import("estree").AssignmentProperty} AssignmentProperty */
|
91
|
+
/** @typedef {Record<string, any>} Attributes */
|
92
|
+
/**
|
93
|
+
* @template T
|
94
|
+
* @typedef {import("tapable").AsArray<T>} AsArray<T>
|
95
|
+
*/
|
92
96
|
/** @typedef {import("../Parser").ParserState} ParserState */
|
93
97
|
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
94
98
|
/** @typedef {{declaredScope: ScopeInfo, freeName: string | true, tagInfo: TagInfo | undefined}} VariableInfoInterface */
|
95
99
|
/** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRanges: () => Range[] }} GetInfoResult */
|
96
100
|
/** @typedef {Statement | ModuleDeclaration | Expression} StatementPathItem */
|
101
|
+
/** @typedef {TODO} OnIdent */
|
97
102
|
|
98
103
|
/** @type {string[]} */
|
99
104
|
const EMPTY_ARRAY = [];
|
@@ -257,7 +262,7 @@ class JavascriptParser extends Parser {
|
|
257
262
|
evaluateCallExpression: new HookMap(
|
258
263
|
() => new SyncBailHook(["expression"])
|
259
264
|
),
|
260
|
-
/** @type {HookMap<SyncBailHook<[CallExpression, BasicEvaluatedExpression
|
265
|
+
/** @type {HookMap<SyncBailHook<[CallExpression, BasicEvaluatedExpression], BasicEvaluatedExpression | undefined | null>>} */
|
261
266
|
evaluateCallExpressionMember: new HookMap(
|
262
267
|
() => new SyncBailHook(["expression", "param"])
|
263
268
|
),
|
@@ -298,15 +303,15 @@ class JavascriptParser extends Parser {
|
|
298
303
|
"exportName",
|
299
304
|
"identifierName"
|
300
305
|
]),
|
301
|
-
/** @type {SyncBailHook<[
|
306
|
+
/** @type {SyncBailHook<[ExportDefaultDeclaration | ExportNamedDeclaration], boolean | void>} */
|
302
307
|
export: new SyncBailHook(["statement"]),
|
303
308
|
/** @type {SyncBailHook<[ExportNamedDeclaration | ExportAllDeclaration, ImportSource], boolean | void>} */
|
304
309
|
exportImport: new SyncBailHook(["statement", "source"]),
|
305
|
-
/** @type {SyncBailHook<[ExportNamedDeclaration | ExportAllDeclaration, Declaration], boolean | void>} */
|
310
|
+
/** @type {SyncBailHook<[ExportDefaultDeclaration | ExportNamedDeclaration | ExportAllDeclaration, Declaration], boolean | void>} */
|
306
311
|
exportDeclaration: new SyncBailHook(["statement", "declaration"]),
|
307
|
-
/** @type {SyncBailHook<[ExportDefaultDeclaration,
|
312
|
+
/** @type {SyncBailHook<[ExportDefaultDeclaration, FunctionDeclaration | ClassDeclaration], boolean | void>} */
|
308
313
|
exportExpression: new SyncBailHook(["statement", "declaration"]),
|
309
|
-
/** @type {SyncBailHook<[ExportNamedDeclaration | ExportAllDeclaration, string, string, number | undefined], boolean | void>} */
|
314
|
+
/** @type {SyncBailHook<[ExportDefaultDeclaration | ExportNamedDeclaration | ExportAllDeclaration, string, string, number | undefined], boolean | void>} */
|
310
315
|
exportSpecifier: new SyncBailHook([
|
311
316
|
"statement",
|
312
317
|
"identifierName",
|
@@ -349,7 +354,7 @@ class JavascriptParser extends Parser {
|
|
349
354
|
typeof: new HookMap(() => new SyncBailHook(["expression"])),
|
350
355
|
/** @type {SyncBailHook<[ImportExpression], boolean | void>} */
|
351
356
|
importCall: new SyncBailHook(["expression"]),
|
352
|
-
/** @type {SyncBailHook<[Expression], boolean | void>} */
|
357
|
+
/** @type {SyncBailHook<[Expression | ForOfStatement], boolean | void>} */
|
353
358
|
topLevelAwait: new SyncBailHook(["expression"]),
|
354
359
|
/** @type {HookMap<SyncBailHook<[CallExpression], boolean | void>>} */
|
355
360
|
call: new HookMap(() => new SyncBailHook(["expression"])),
|
@@ -880,7 +885,12 @@ class JavascriptParser extends Parser {
|
|
880
885
|
/** @type {string} */ (left.string) +
|
881
886
|
/** @type {string} */ (right.prefix.string)
|
882
887
|
)
|
883
|
-
.setRange(
|
888
|
+
.setRange(
|
889
|
+
joinRanges(
|
890
|
+
/** @type {Range} */ (left.range),
|
891
|
+
/** @type {Range} */ (right.prefix.range)
|
892
|
+
)
|
893
|
+
),
|
884
894
|
right.postfix,
|
885
895
|
right.wrappedInnerExpressions
|
886
896
|
);
|
@@ -901,7 +911,10 @@ class JavascriptParser extends Parser {
|
|
901
911
|
if (right.isString()) {
|
902
912
|
res.setString(left.number + /** @type {string} */ (right.string));
|
903
913
|
} else if (right.isNumber()) {
|
904
|
-
res.setNumber(
|
914
|
+
res.setNumber(
|
915
|
+
/** @type {number} */ (left.number) +
|
916
|
+
/** @type {number} */ (right.number)
|
917
|
+
);
|
905
918
|
} else {
|
906
919
|
return;
|
907
920
|
}
|
@@ -1328,7 +1341,7 @@ class JavascriptParser extends Parser {
|
|
1328
1341
|
if (arg1.type === "SpreadElement") return;
|
1329
1342
|
const arg1Eval = this.evaluateExpression(arg1);
|
1330
1343
|
if (!arg1Eval.isString()) return;
|
1331
|
-
const arg1Value = arg1Eval.string;
|
1344
|
+
const arg1Value = /** @type {string} */ (arg1Eval.string);
|
1332
1345
|
|
1333
1346
|
let result;
|
1334
1347
|
if (arg2) {
|
@@ -1357,9 +1370,11 @@ class JavascriptParser extends Parser {
|
|
1357
1370
|
let arg1 = this.evaluateExpression(expr.arguments[0]);
|
1358
1371
|
let arg2 = this.evaluateExpression(expr.arguments[1]);
|
1359
1372
|
if (!arg1.isString() && !arg1.isRegExp()) return;
|
1360
|
-
const arg1Value =
|
1373
|
+
const arg1Value = /** @type {string | RegExp} */ (
|
1374
|
+
arg1.regExp || arg1.string
|
1375
|
+
);
|
1361
1376
|
if (!arg2.isString()) return;
|
1362
|
-
const arg2Value = arg2.string;
|
1377
|
+
const arg2Value = /** @type {string} */ (arg2.string);
|
1363
1378
|
return new BasicEvaluatedExpression()
|
1364
1379
|
.setString(
|
1365
1380
|
/** @type {string} */ (param.string).replace(arg1Value, arg2Value)
|
@@ -1380,7 +1395,9 @@ class JavascriptParser extends Parser {
|
|
1380
1395
|
if (expr.arguments[0].type === "SpreadElement") return;
|
1381
1396
|
arg1 = this.evaluateExpression(expr.arguments[0]);
|
1382
1397
|
if (!arg1.isNumber()) return;
|
1383
|
-
result = str[
|
1398
|
+
result = str[
|
1399
|
+
/** @type {"substr" | "substring" | "slice"} */ (fn)
|
1400
|
+
](/** @type {number} */ (arg1.number));
|
1384
1401
|
break;
|
1385
1402
|
case 2: {
|
1386
1403
|
if (expr.arguments[0].type === "SpreadElement") return;
|
@@ -1389,7 +1406,12 @@ class JavascriptParser extends Parser {
|
|
1389
1406
|
const arg2 = this.evaluateExpression(expr.arguments[1]);
|
1390
1407
|
if (!arg1.isNumber()) return;
|
1391
1408
|
if (!arg2.isNumber()) return;
|
1392
|
-
result = str[
|
1409
|
+
result = str[
|
1410
|
+
/** @type {"substr" | "substring" | "slice"} */ (fn)
|
1411
|
+
](
|
1412
|
+
/** @type {number} */ (arg1.number),
|
1413
|
+
/** @type {number} */ (arg2.number)
|
1414
|
+
);
|
1393
1415
|
break;
|
1394
1416
|
}
|
1395
1417
|
default:
|
@@ -1443,7 +1465,7 @@ class JavascriptParser extends Parser {
|
|
1443
1465
|
}
|
1444
1466
|
|
1445
1467
|
const part = new BasicEvaluatedExpression()
|
1446
|
-
.setString(quasi)
|
1468
|
+
.setString(/** @type {string} */ (quasi))
|
1447
1469
|
.setRange(/** @type {Range} */ (quasiExpr.range))
|
1448
1470
|
.setExpression(quasiExpr);
|
1449
1471
|
quasis.push(part);
|
@@ -1489,7 +1511,6 @@ class JavascriptParser extends Parser {
|
|
1489
1511
|
.for("concat")
|
1490
1512
|
.tap("JavascriptParser", (expr, param) => {
|
1491
1513
|
if (!param.isString() && !param.isWrapped()) return;
|
1492
|
-
|
1493
1514
|
let stringSuffix = null;
|
1494
1515
|
let hasUnknownParams = false;
|
1495
1516
|
const innerExpressions = [];
|
@@ -1569,7 +1590,9 @@ class JavascriptParser extends Parser {
|
|
1569
1590
|
/** @type {string} */
|
1570
1591
|
(param.string).split(/** @type {string} */ (arg.string));
|
1571
1592
|
} else if (arg.isRegExp()) {
|
1572
|
-
result = /** @type {string} */ (param.string).split(
|
1593
|
+
result = /** @type {string} */ (param.string).split(
|
1594
|
+
/** @type {RegExp} */ (arg.regExp)
|
1595
|
+
);
|
1573
1596
|
} else {
|
1574
1597
|
return;
|
1575
1598
|
}
|
@@ -1627,7 +1650,7 @@ class JavascriptParser extends Parser {
|
|
1627
1650
|
});
|
1628
1651
|
if (!items.every(Boolean)) return;
|
1629
1652
|
return new BasicEvaluatedExpression()
|
1630
|
-
.setItems(items)
|
1653
|
+
.setItems(/** @type {BasicEvaluatedExpression[]} */ (items))
|
1631
1654
|
.setRange(/** @type {Range} */ (expr.range));
|
1632
1655
|
});
|
1633
1656
|
this.hooks.evaluate
|
@@ -2213,6 +2236,9 @@ class JavascriptParser extends Parser {
|
|
2213
2236
|
});
|
2214
2237
|
}
|
2215
2238
|
|
2239
|
+
/**
|
2240
|
+
* @param {ForOfStatement} statement statement
|
2241
|
+
*/
|
2216
2242
|
preWalkForOfStatement(statement) {
|
2217
2243
|
if (statement.await && this.scope.topLevelScope === true) {
|
2218
2244
|
this.hooks.topLevelAwait.call(statement);
|
@@ -2305,7 +2331,9 @@ class JavascriptParser extends Parser {
|
|
2305
2331
|
|
2306
2332
|
// check multiple assignments
|
2307
2333
|
if (this.destructuringAssignmentProperties.has(expression)) {
|
2308
|
-
const set =
|
2334
|
+
const set =
|
2335
|
+
/** @type {Set<string>} */
|
2336
|
+
(this.destructuringAssignmentProperties.get(expression));
|
2309
2337
|
this.destructuringAssignmentProperties.delete(expression);
|
2310
2338
|
for (const id of set) keys.add(id);
|
2311
2339
|
}
|
@@ -2322,8 +2350,11 @@ class JavascriptParser extends Parser {
|
|
2322
2350
|
}
|
2323
2351
|
}
|
2324
2352
|
|
2353
|
+
/**
|
2354
|
+
* @param {ImportDeclaration} statement statement
|
2355
|
+
*/
|
2325
2356
|
blockPreWalkImportDeclaration(statement) {
|
2326
|
-
const source = statement.source.value;
|
2357
|
+
const source = /** @type {ImportSource} */ (statement.source.value);
|
2327
2358
|
this.hooks.import.call(statement, source);
|
2328
2359
|
for (const specifier of statement.specifiers) {
|
2329
2360
|
const name = specifier.local.name;
|
@@ -2340,7 +2371,12 @@ class JavascriptParser extends Parser {
|
|
2340
2371
|
!this.hooks.importSpecifier.call(
|
2341
2372
|
statement,
|
2342
2373
|
source,
|
2343
|
-
specifier.imported.name ||
|
2374
|
+
specifier.imported.name ||
|
2375
|
+
// eslint-disable-next-line no-warning-comments
|
2376
|
+
// @ts-ignore
|
2377
|
+
// Old version of acorn used it
|
2378
|
+
// TODO drop it in webpack@6
|
2379
|
+
specifier.imported.value,
|
2344
2380
|
name
|
2345
2381
|
)
|
2346
2382
|
) {
|
@@ -2360,7 +2396,7 @@ class JavascriptParser extends Parser {
|
|
2360
2396
|
|
2361
2397
|
/**
|
2362
2398
|
* @param {Declaration} declaration declaration
|
2363
|
-
* @param {
|
2399
|
+
* @param {OnIdent} onIdent on ident callback
|
2364
2400
|
*/
|
2365
2401
|
enterDeclaration(declaration, onIdent) {
|
2366
2402
|
switch (declaration.type) {
|
@@ -2383,10 +2419,13 @@ class JavascriptParser extends Parser {
|
|
2383
2419
|
}
|
2384
2420
|
}
|
2385
2421
|
|
2422
|
+
/**
|
2423
|
+
* @param {ExportNamedDeclaration} statement statement
|
2424
|
+
*/
|
2386
2425
|
blockPreWalkExportNamedDeclaration(statement) {
|
2387
2426
|
let source;
|
2388
2427
|
if (statement.source) {
|
2389
|
-
source = statement.source.value;
|
2428
|
+
source = /** @type {ImportSource} */ (statement.source.value);
|
2390
2429
|
this.hooks.exportImport.call(statement, source);
|
2391
2430
|
} else {
|
2392
2431
|
this.hooks.export.call(statement);
|
@@ -2414,7 +2453,13 @@ class JavascriptParser extends Parser {
|
|
2414
2453
|
const specifier = statement.specifiers[specifierIndex];
|
2415
2454
|
switch (specifier.type) {
|
2416
2455
|
case "ExportSpecifier": {
|
2417
|
-
const name =
|
2456
|
+
const name =
|
2457
|
+
specifier.exported.name ||
|
2458
|
+
// eslint-disable-next-line no-warning-comments
|
2459
|
+
// @ts-ignore
|
2460
|
+
// Old version of acorn used it
|
2461
|
+
// TODO drop it in webpack@6
|
2462
|
+
specifier.exported.value;
|
2418
2463
|
if (source) {
|
2419
2464
|
this.hooks.exportImportSpecifier.call(
|
2420
2465
|
statement,
|
@@ -2447,36 +2492,50 @@ class JavascriptParser extends Parser {
|
|
2447
2492
|
}
|
2448
2493
|
}
|
2449
2494
|
|
2495
|
+
/**
|
2496
|
+
* @param {TODO} statement statement
|
2497
|
+
*/
|
2450
2498
|
blockPreWalkExportDefaultDeclaration(statement) {
|
2451
2499
|
const prev = this.prevStatement;
|
2452
2500
|
this.preWalkStatement(statement.declaration);
|
2453
2501
|
this.prevStatement = prev;
|
2454
2502
|
this.blockPreWalkStatement(statement.declaration);
|
2455
2503
|
if (
|
2456
|
-
|
2504
|
+
/** @type {FunctionDeclaration | ClassDeclaration} */ (
|
2505
|
+
statement.declaration
|
2506
|
+
).id &&
|
2457
2507
|
statement.declaration.type !== "FunctionExpression" &&
|
2458
2508
|
statement.declaration.type !== "ClassExpression"
|
2459
2509
|
) {
|
2510
|
+
const declaration =
|
2511
|
+
/** @type {FunctionDeclaration | ClassDeclaration} */
|
2512
|
+
(statement.declaration);
|
2460
2513
|
this.hooks.exportSpecifier.call(
|
2461
2514
|
statement,
|
2462
|
-
|
2515
|
+
declaration.id.name,
|
2463
2516
|
"default",
|
2464
2517
|
undefined
|
2465
2518
|
);
|
2466
2519
|
}
|
2467
2520
|
}
|
2468
2521
|
|
2522
|
+
/**
|
2523
|
+
* @param {ExportDefaultDeclaration} statement statement
|
2524
|
+
*/
|
2469
2525
|
walkExportDefaultDeclaration(statement) {
|
2470
2526
|
this.hooks.export.call(statement);
|
2471
2527
|
if (
|
2472
|
-
|
2528
|
+
/** @type {FunctionDeclaration | ClassDeclaration} */ (
|
2529
|
+
statement.declaration
|
2530
|
+
).id &&
|
2473
2531
|
statement.declaration.type !== "FunctionExpression" &&
|
2474
2532
|
statement.declaration.type !== "ClassExpression"
|
2475
2533
|
) {
|
2476
|
-
|
2477
|
-
|
2478
|
-
|
2479
|
-
|
2534
|
+
const declaration =
|
2535
|
+
/** @type {FunctionDeclaration | ClassDeclaration} */
|
2536
|
+
(statement.declaration);
|
2537
|
+
if (!this.hooks.exportDeclaration.call(statement, declaration)) {
|
2538
|
+
this.walkStatement(declaration);
|
2480
2539
|
}
|
2481
2540
|
} else {
|
2482
2541
|
// Acorn parses `export default function() {}` as `FunctionDeclaration` and
|
@@ -2486,14 +2545,23 @@ class JavascriptParser extends Parser {
|
|
2486
2545
|
statement.declaration.type === "FunctionDeclaration" ||
|
2487
2546
|
statement.declaration.type === "ClassDeclaration"
|
2488
2547
|
) {
|
2489
|
-
this.walkStatement(
|
2548
|
+
this.walkStatement(
|
2549
|
+
/** @type {FunctionDeclaration | ClassDeclaration} */
|
2550
|
+
(statement.declaration)
|
2551
|
+
);
|
2490
2552
|
} else {
|
2491
2553
|
this.walkExpression(statement.declaration);
|
2492
2554
|
}
|
2493
|
-
|
2555
|
+
|
2556
|
+
if (
|
2557
|
+
!this.hooks.exportExpression.call(
|
2558
|
+
statement,
|
2559
|
+
/** @type {TODO} */ (statement).declaration
|
2560
|
+
)
|
2561
|
+
) {
|
2494
2562
|
this.hooks.exportSpecifier.call(
|
2495
2563
|
statement,
|
2496
|
-
statement.declaration,
|
2564
|
+
/** @type {TODO} */ (statement.declaration),
|
2497
2565
|
"default",
|
2498
2566
|
undefined
|
2499
2567
|
);
|
@@ -2501,8 +2569,11 @@ class JavascriptParser extends Parser {
|
|
2501
2569
|
}
|
2502
2570
|
}
|
2503
2571
|
|
2572
|
+
/**
|
2573
|
+
* @param {ExportAllDeclaration} statement statement
|
2574
|
+
*/
|
2504
2575
|
blockPreWalkExportAllDeclaration(statement) {
|
2505
|
-
const source = statement.source.value;
|
2576
|
+
const source = /** @type {ImportSource} */ (statement.source.value);
|
2506
2577
|
const name = statement.exported ? statement.exported.name : null;
|
2507
2578
|
this.hooks.exportImport.call(statement, source);
|
2508
2579
|
this.hooks.exportImportSpecifier.call(statement, source, null, name, 0);
|
@@ -2568,7 +2639,7 @@ class JavascriptParser extends Parser {
|
|
2568
2639
|
if (key.type === "Identifier") {
|
2569
2640
|
ids.add(key.name);
|
2570
2641
|
} else {
|
2571
|
-
const id = this.evaluateExpression(key);
|
2642
|
+
const id = this.evaluateExpression(/** @type {TODO} */ (key));
|
2572
2643
|
const str = id.asString();
|
2573
2644
|
if (str) {
|
2574
2645
|
ids.add(str);
|
@@ -2764,10 +2835,16 @@ class JavascriptParser extends Parser {
|
|
2764
2835
|
this.walkPattern(pattern.left);
|
2765
2836
|
}
|
2766
2837
|
|
2838
|
+
/**
|
2839
|
+
* @param {ObjectPattern} pattern pattern
|
2840
|
+
*/
|
2767
2841
|
walkObjectPattern(pattern) {
|
2768
2842
|
for (let i = 0, len = pattern.properties.length; i < len; i++) {
|
2769
2843
|
const prop = pattern.properties[i];
|
2770
2844
|
if (prop) {
|
2845
|
+
if (prop.type === "RestElement") {
|
2846
|
+
continue;
|
2847
|
+
}
|
2771
2848
|
if (prop.computed) this.walkExpression(prop.key);
|
2772
2849
|
if (prop.value) this.walkPattern(prop.value);
|
2773
2850
|
}
|
@@ -3248,9 +3325,21 @@ class JavascriptParser extends Parser {
|
|
3248
3325
|
}
|
3249
3326
|
}
|
3250
3327
|
|
3328
|
+
/**
|
3329
|
+
* @private
|
3330
|
+
* @param {FunctionExpression | ArrowFunctionExpression} functionExpression function expression
|
3331
|
+
* @param {(Expression | SpreadElement)[]} options options
|
3332
|
+
* @param {Expression | SpreadElement | null} currentThis current this
|
3333
|
+
*/
|
3251
3334
|
_walkIIFE(functionExpression, options, currentThis) {
|
3335
|
+
/**
|
3336
|
+
* @param {Expression | SpreadElement} argOrThis arg or this
|
3337
|
+
* @returns {string | VariableInfoInterface | undefined} var info
|
3338
|
+
*/
|
3252
3339
|
const getVarInfo = argOrThis => {
|
3253
|
-
const renameIdentifier = this.getRenameIdentifier(
|
3340
|
+
const renameIdentifier = this.getRenameIdentifier(
|
3341
|
+
/** @type {Expression} */ (argOrThis)
|
3342
|
+
);
|
3254
3343
|
if (renameIdentifier) {
|
3255
3344
|
if (
|
3256
3345
|
this.callHooksForInfo(
|
@@ -3267,7 +3356,7 @@ class JavascriptParser extends Parser {
|
|
3267
3356
|
)
|
3268
3357
|
) {
|
3269
3358
|
return typeof renameIdentifier === "string"
|
3270
|
-
? this.getVariableInfo(renameIdentifier)
|
3359
|
+
? /** @type {string} */ (this.getVariableInfo(renameIdentifier))
|
3271
3360
|
: renameIdentifier;
|
3272
3361
|
}
|
3273
3362
|
}
|
@@ -3280,12 +3369,15 @@ class JavascriptParser extends Parser {
|
|
3280
3369
|
const varInfoForArgs = options.map(getVarInfo);
|
3281
3370
|
const wasTopLevel = this.scope.topLevelScope;
|
3282
3371
|
this.scope.topLevelScope = wasTopLevel && arrow ? "arrow" : false;
|
3283
|
-
const scopeParams =
|
3284
|
-
(
|
3285
|
-
|
3372
|
+
const scopeParams =
|
3373
|
+
/** @type {(Identifier | string)[]} */
|
3374
|
+
(params.filter((identifier, idx) => !varInfoForArgs[idx]));
|
3286
3375
|
|
3287
3376
|
// Add function name in scope for recursive calls
|
3288
|
-
if (
|
3377
|
+
if (
|
3378
|
+
functionExpression.type === "FunctionExpression" &&
|
3379
|
+
functionExpression.id
|
3380
|
+
) {
|
3289
3381
|
scopeParams.push(functionExpression.id.name);
|
3290
3382
|
}
|
3291
3383
|
|
@@ -3297,7 +3389,7 @@ class JavascriptParser extends Parser {
|
|
3297
3389
|
const varInfo = varInfoForArgs[i];
|
3298
3390
|
if (!varInfo) continue;
|
3299
3391
|
if (!params[i] || params[i].type !== "Identifier") continue;
|
3300
|
-
this.setVariable(params[i].name, varInfo);
|
3392
|
+
this.setVariable(/** @type {Identifier} */ (params[i]).name, varInfo);
|
3301
3393
|
}
|
3302
3394
|
if (functionExpression.body.type === "BlockStatement") {
|
3303
3395
|
this.detectMode(functionExpression.body.body);
|
@@ -3322,6 +3414,9 @@ class JavascriptParser extends Parser {
|
|
3322
3414
|
this.walkExpression(expression.source);
|
3323
3415
|
}
|
3324
3416
|
|
3417
|
+
/**
|
3418
|
+
* @param {CallExpression} expression expression
|
3419
|
+
*/
|
3325
3420
|
walkCallExpression(expression) {
|
3326
3421
|
const isSimpleFunction = fn => {
|
3327
3422
|
return fn.params.every(p => p.type === "Identifier");
|
@@ -3330,14 +3425,20 @@ class JavascriptParser extends Parser {
|
|
3330
3425
|
expression.callee.type === "MemberExpression" &&
|
3331
3426
|
expression.callee.object.type.endsWith("FunctionExpression") &&
|
3332
3427
|
!expression.callee.computed &&
|
3428
|
+
// eslint-disable-next-line no-warning-comments
|
3429
|
+
// @ts-ignore
|
3430
|
+
// TODO check me and handle more cases
|
3333
3431
|
(expression.callee.property.name === "call" ||
|
3432
|
+
// eslint-disable-next-line no-warning-comments
|
3433
|
+
// @ts-ignore
|
3334
3434
|
expression.callee.property.name === "bind") &&
|
3335
3435
|
expression.arguments.length > 0 &&
|
3336
3436
|
isSimpleFunction(expression.callee.object)
|
3337
3437
|
) {
|
3338
3438
|
// (function(…) { }.call/bind(?, …))
|
3339
3439
|
this._walkIIFE(
|
3340
|
-
|
3440
|
+
/** @type {FunctionExpression | ArrowFunctionExpression} */
|
3441
|
+
(expression.callee.object),
|
3341
3442
|
expression.arguments.slice(1),
|
3342
3443
|
expression.arguments[0]
|
3343
3444
|
);
|
@@ -3346,7 +3447,12 @@ class JavascriptParser extends Parser {
|
|
3346
3447
|
isSimpleFunction(expression.callee)
|
3347
3448
|
) {
|
3348
3449
|
// (function(…) { }(…))
|
3349
|
-
this._walkIIFE(
|
3450
|
+
this._walkIIFE(
|
3451
|
+
/** @type {FunctionExpression | ArrowFunctionExpression} */
|
3452
|
+
(expression.callee),
|
3453
|
+
expression.arguments,
|
3454
|
+
null
|
3455
|
+
);
|
3350
3456
|
} else {
|
3351
3457
|
if (expression.callee.type === "MemberExpression") {
|
3352
3458
|
const exprInfo = this.getMemberExpressionInfo(
|
@@ -3366,7 +3472,9 @@ class JavascriptParser extends Parser {
|
|
3366
3472
|
if (result === true) return;
|
3367
3473
|
}
|
3368
3474
|
}
|
3369
|
-
const callee = this.evaluateExpression(
|
3475
|
+
const callee = this.evaluateExpression(
|
3476
|
+
/** @type {TODO} */ (expression.callee)
|
3477
|
+
);
|
3370
3478
|
if (callee.isIdentifier()) {
|
3371
3479
|
const result1 = this.callHooksForInfo(
|
3372
3480
|
this.hooks.callMemberChain,
|
@@ -3824,8 +3932,8 @@ class JavascriptParser extends Parser {
|
|
3824
3932
|
}
|
3825
3933
|
|
3826
3934
|
/**
|
3827
|
-
* @param {(Pattern | Property)[]} patterns patterns
|
3828
|
-
* @param {
|
3935
|
+
* @param {(string | Pattern | Property)[]} patterns patterns
|
3936
|
+
* @param {OnIdent} onIdent on ident callback
|
3829
3937
|
*/
|
3830
3938
|
enterPatterns(patterns, onIdent) {
|
3831
3939
|
for (const pattern of patterns) {
|
@@ -3839,7 +3947,7 @@ class JavascriptParser extends Parser {
|
|
3839
3947
|
|
3840
3948
|
/**
|
3841
3949
|
* @param {Pattern | Property} pattern pattern
|
3842
|
-
* @param {
|
3950
|
+
* @param {OnIdent} onIdent on ident callback
|
3843
3951
|
*/
|
3844
3952
|
enterPattern(pattern, onIdent) {
|
3845
3953
|
if (!pattern) return;
|
@@ -3873,7 +3981,7 @@ class JavascriptParser extends Parser {
|
|
3873
3981
|
|
3874
3982
|
/**
|
3875
3983
|
* @param {Identifier} pattern identifier pattern
|
3876
|
-
* @param {
|
3984
|
+
* @param {OnIdent} onIdent callback
|
3877
3985
|
*/
|
3878
3986
|
enterIdentifier(pattern, onIdent) {
|
3879
3987
|
if (!this.callHooksForName(this.hooks.pattern, pattern.name, pattern)) {
|
@@ -3883,7 +3991,7 @@ class JavascriptParser extends Parser {
|
|
3883
3991
|
|
3884
3992
|
/**
|
3885
3993
|
* @param {ObjectPattern} pattern object pattern
|
3886
|
-
* @param {
|
3994
|
+
* @param {OnIdent} onIdent callback
|
3887
3995
|
*/
|
3888
3996
|
enterObjectPattern(pattern, onIdent) {
|
3889
3997
|
for (
|
@@ -3898,7 +4006,7 @@ class JavascriptParser extends Parser {
|
|
3898
4006
|
|
3899
4007
|
/**
|
3900
4008
|
* @param {ArrayPattern} pattern object pattern
|
3901
|
-
* @param {
|
4009
|
+
* @param {OnIdent} onIdent callback
|
3902
4010
|
*/
|
3903
4011
|
enterArrayPattern(pattern, onIdent) {
|
3904
4012
|
for (
|
@@ -3916,7 +4024,7 @@ class JavascriptParser extends Parser {
|
|
3916
4024
|
|
3917
4025
|
/**
|
3918
4026
|
* @param {RestElement} pattern object pattern
|
3919
|
-
* @param {
|
4027
|
+
* @param {OnIdent} onIdent callback
|
3920
4028
|
*/
|
3921
4029
|
enterRestElement(pattern, onIdent) {
|
3922
4030
|
this.enterPattern(pattern.argument, onIdent);
|
@@ -3924,7 +4032,7 @@ class JavascriptParser extends Parser {
|
|
3924
4032
|
|
3925
4033
|
/**
|
3926
4034
|
* @param {AssignmentPattern} pattern object pattern
|
3927
|
-
* @param {
|
4035
|
+
* @param {OnIdent} onIdent callback
|
3928
4036
|
*/
|
3929
4037
|
enterAssignmentPattern(pattern, onIdent) {
|
3930
4038
|
this.enterPattern(pattern.left, onIdent);
|
@@ -3975,6 +4083,10 @@ class JavascriptParser extends Parser {
|
|
3975
4083
|
);
|
3976
4084
|
}
|
3977
4085
|
|
4086
|
+
/**
|
4087
|
+
* @param {Expression} expression expression
|
4088
|
+
* @returns {TODO} result
|
4089
|
+
*/
|
3978
4090
|
parseCalculatedString(expression) {
|
3979
4091
|
switch (expression.type) {
|
3980
4092
|
case "BinaryExpression":
|
@@ -4412,7 +4524,7 @@ class JavascriptParser extends Parser {
|
|
4412
4524
|
|
4413
4525
|
/**
|
4414
4526
|
* @param {string} name variable name
|
4415
|
-
* @returns {ExportedVariableInfo} info for this variable
|
4527
|
+
* @returns {string | ExportedVariableInfo} info for this variable
|
4416
4528
|
*/
|
4417
4529
|
getVariableInfo(name) {
|
4418
4530
|
const value = this.scope.definitions.get(name);
|
@@ -4425,7 +4537,7 @@ class JavascriptParser extends Parser {
|
|
4425
4537
|
|
4426
4538
|
/**
|
4427
4539
|
* @param {string} name variable name
|
4428
|
-
* @param {ExportedVariableInfo} variableInfo new info for this variable
|
4540
|
+
* @param {string | ExportedVariableInfo} variableInfo new info for this variable
|
4429
4541
|
* @returns {void}
|
4430
4542
|
*/
|
4431
4543
|
setVariable(name, variableInfo) {
|
@@ -18,7 +18,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
18
18
|
/**
|
19
19
|
* @param {JavascriptParser} parser the parser
|
20
20
|
* @param {string} value the const value
|
21
|
-
* @param {string[]=} runtimeRequirements runtime requirements
|
21
|
+
* @param {(string[] | null)=} runtimeRequirements runtime requirements
|
22
22
|
* @returns {function(Expression): true} plugin function
|
23
23
|
*/
|
24
24
|
exports.toConstantDependency = (parser, value, runtimeRequirements) => {
|
@@ -12,8 +12,10 @@ const { getAllChunks } = require("./ChunkHelpers");
|
|
12
12
|
|
13
13
|
/** @typedef {import("../util/Hash")} Hash */
|
14
14
|
/** @typedef {import("../Chunk")} Chunk */
|
15
|
+
/** @typedef {import("../Chunk").ChunkId} ChunkId */
|
15
16
|
/** @typedef {import("../Compilation")} Compilation */
|
16
17
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
18
|
+
/** @typedef {import("../Entrypoint")} Entrypoint */
|
17
19
|
/** @typedef {import("../ChunkGraph").EntryModuleWithChunkGroup} EntryModuleWithChunkGroup */
|
18
20
|
/** @typedef {import("../ChunkGroup")} ChunkGroup */
|
19
21
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
@@ -73,9 +75,15 @@ exports.generateEntryStartup = (
|
|
73
75
|
let currentModuleIds = undefined;
|
74
76
|
|
75
77
|
for (const [module, entrypoint] of entries) {
|
76
|
-
const runtimeChunk =
|
78
|
+
const runtimeChunk =
|
79
|
+
/** @type {Entrypoint} */
|
80
|
+
(entrypoint).getRuntimeChunk();
|
77
81
|
const moduleId = chunkGraph.getModuleId(module);
|
78
|
-
const chunks = getAllChunks(
|
82
|
+
const chunks = getAllChunks(
|
83
|
+
/** @type {Entrypoint} */ (entrypoint),
|
84
|
+
chunk,
|
85
|
+
runtimeChunk
|
86
|
+
);
|
79
87
|
if (
|
80
88
|
currentChunks &&
|
81
89
|
currentChunks.size === chunks.size &&
|
@@ -108,11 +116,18 @@ exports.generateEntryStartup = (
|
|
108
116
|
*/
|
109
117
|
exports.updateHashForEntryStartup = (hash, chunkGraph, entries, chunk) => {
|
110
118
|
for (const [module, entrypoint] of entries) {
|
111
|
-
const runtimeChunk =
|
119
|
+
const runtimeChunk =
|
120
|
+
/** @type {Entrypoint} */
|
121
|
+
(entrypoint).getRuntimeChunk();
|
112
122
|
const moduleId = chunkGraph.getModuleId(module);
|
113
123
|
hash.update(`${moduleId}`);
|
114
|
-
for (const c of getAllChunks(
|
124
|
+
for (const c of getAllChunks(
|
125
|
+
/** @type {Entrypoint} */ (entrypoint),
|
126
|
+
chunk,
|
127
|
+
/** @type {Chunk} */ (runtimeChunk)
|
128
|
+
)) {
|
115
129
|
hash.update(`${c.id}`);
|
130
|
+
}
|
116
131
|
}
|
117
132
|
};
|
118
133
|
|
@@ -126,7 +141,9 @@ exports.getInitialChunkIds = (chunk, chunkGraph, filterFn) => {
|
|
126
141
|
const initialChunkIds = new Set(chunk.ids);
|
127
142
|
for (const c of chunk.getAllInitialChunks()) {
|
128
143
|
if (c === chunk || filterFn(c, chunkGraph)) continue;
|
129
|
-
for (const id of c.ids)
|
144
|
+
for (const id of /** @type {ChunkId[]} */ (c.ids)) {
|
145
|
+
initialChunkIds.add(id);
|
146
|
+
}
|
130
147
|
}
|
131
148
|
return initialChunkIds;
|
132
149
|
};
|