webpack 5.59.0 → 5.71.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 +1 -7
- package/hot/lazy-compilation-node.js +3 -1
- package/hot/poll.js +1 -1
- package/hot/signal.js +1 -1
- package/lib/APIPlugin.js +33 -0
- package/lib/BannerPlugin.js +10 -4
- package/lib/Cache.js +1 -1
- package/lib/CacheFacade.js +4 -11
- package/lib/Chunk.js +6 -3
- package/lib/ChunkGraph.js +1 -2
- package/lib/ChunkGroup.js +1 -1
- package/lib/CleanPlugin.js +81 -20
- package/lib/Compilation.js +179 -91
- package/lib/Compiler.js +86 -17
- package/lib/ConstPlugin.js +2 -2
- package/lib/ContextModule.js +142 -51
- package/lib/ContextModuleFactory.js +65 -25
- package/lib/DelegatedModule.js +1 -1
- package/lib/DelegatedModuleFactoryPlugin.js +1 -1
- package/lib/Dependency.js +17 -0
- package/lib/DependencyTemplate.js +9 -0
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DllModule.js +1 -1
- package/lib/EntryOptionPlugin.js +2 -0
- package/lib/ErrorHelpers.js +2 -2
- package/lib/EvalDevToolModulePlugin.js +16 -1
- package/lib/EvalSourceMapDevToolPlugin.js +18 -1
- package/lib/ExportsInfo.js +4 -4
- package/lib/ExternalModule.js +94 -54
- package/lib/ExternalModuleFactoryPlugin.js +5 -5
- package/lib/FileSystemInfo.js +89 -44
- package/lib/Generator.js +3 -0
- package/lib/HookWebpackError.js +1 -1
- package/lib/HotModuleReplacementPlugin.js +3 -1
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/Module.js +27 -4
- package/lib/ModuleFilenameHelpers.js +8 -4
- package/lib/ModuleHashingError.js +29 -0
- package/lib/MultiCompiler.js +1 -1
- package/lib/MultiWatching.js +1 -1
- package/lib/NodeStuffPlugin.js +10 -0
- package/lib/NormalModule.js +41 -26
- package/lib/NormalModuleFactory.js +42 -37
- package/lib/ProgressPlugin.js +4 -5
- package/lib/RawModule.js +1 -1
- package/lib/RuntimeGlobals.js +29 -1
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +77 -1
- package/lib/RuntimeTemplate.js +114 -2
- package/lib/Template.js +2 -1
- package/lib/TemplatedPathPlugin.js +48 -23
- package/lib/WatchIgnorePlugin.js +19 -7
- package/lib/Watching.js +33 -19
- package/lib/WebpackOptionsApply.js +57 -11
- package/lib/asset/AssetGenerator.js +193 -63
- package/lib/asset/AssetModulesPlugin.js +3 -0
- package/lib/asset/RawDataUrlModule.js +148 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
- package/lib/buildChunkGraph.js +36 -6
- package/lib/cache/PackFileCacheStrategy.js +7 -4
- package/lib/cache/ResolverCachePlugin.js +90 -29
- package/lib/cli.js +44 -3
- package/lib/config/browserslistTargetHandler.js +41 -6
- package/lib/config/defaults.js +115 -19
- package/lib/config/normalization.js +9 -0
- package/lib/config/target.js +10 -0
- package/lib/container/ContainerEntryModule.js +8 -5
- package/lib/container/FallbackModule.js +4 -4
- package/lib/container/RemoteModule.js +4 -2
- package/lib/css/CssExportsGenerator.js +139 -0
- package/lib/css/CssGenerator.js +109 -0
- package/lib/css/CssLoadingRuntimeModule.js +440 -0
- package/lib/css/CssModulesPlugin.js +462 -0
- package/lib/css/CssParser.js +618 -0
- package/lib/css/walkCssTokens.js +659 -0
- package/lib/debug/ProfilingPlugin.js +24 -21
- package/lib/dependencies/AMDRequireDependency.js +6 -6
- package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
- package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -3
- package/lib/dependencies/CommonJsRequireContextDependency.js +5 -1
- package/lib/dependencies/ContextDependency.js +1 -0
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
- package/lib/dependencies/ContextElementDependency.js +41 -3
- package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
- package/lib/dependencies/CssExportDependency.js +85 -0
- package/lib/dependencies/CssImportDependency.js +75 -0
- package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
- package/lib/dependencies/CssUrlDependency.js +132 -0
- package/lib/dependencies/ExportsInfoDependency.js +6 -0
- package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
- package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +95 -0
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
- package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
- package/lib/dependencies/HarmonyImportDependency.js +23 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
- package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
- package/lib/dependencies/ImportContextDependency.js +0 -2
- package/lib/dependencies/ImportMetaContextDependency.js +35 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
- package/lib/dependencies/ImportMetaPlugin.js +22 -3
- package/lib/dependencies/LoaderPlugin.js +4 -2
- package/lib/dependencies/RequireContextDependency.js +0 -16
- package/lib/dependencies/RequireEnsureDependency.js +2 -2
- package/lib/dependencies/URLDependency.js +3 -8
- package/lib/dependencies/URLPlugin.js +1 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
- package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
- package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
- package/lib/hmr/LazyCompilationPlugin.js +54 -26
- package/lib/hmr/lazyCompilationBackend.js +51 -12
- package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
- package/lib/ids/HashedModuleIdsPlugin.js +11 -14
- package/lib/ids/IdHelpers.js +25 -11
- package/lib/ids/NamedModuleIdsPlugin.js +6 -9
- package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
- package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
- package/lib/ids/SyncModuleIdsPlugin.js +140 -0
- package/lib/index.js +13 -0
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
- package/lib/javascript/BasicEvaluatedExpression.js +5 -2
- package/lib/javascript/ChunkHelpers.js +33 -0
- package/lib/javascript/JavascriptGenerator.js +1 -0
- package/lib/javascript/JavascriptModulesPlugin.js +27 -2
- package/lib/javascript/JavascriptParser.js +82 -48
- package/lib/javascript/StartupHelpers.js +7 -30
- package/lib/library/AssignLibraryPlugin.js +39 -15
- package/lib/library/EnableLibraryPlugin.js +11 -0
- package/lib/library/UmdLibraryPlugin.js +5 -3
- package/lib/node/NodeTargetPlugin.js +3 -0
- package/lib/node/NodeWatchFileSystem.js +85 -31
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
- package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
- package/lib/optimize/ConcatenatedModule.js +21 -9
- package/lib/optimize/ModuleConcatenationPlugin.js +5 -2
- package/lib/optimize/SplitChunksPlugin.js +8 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +27 -17
- package/lib/runtime/BaseUriRuntimeModule.js +31 -0
- package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
- package/lib/schemes/HttpUriPlugin.js +77 -14
- package/lib/serialization/FileMiddleware.js +44 -9
- package/lib/sharing/ConsumeSharedModule.js +8 -2
- package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
- package/lib/stats/DefaultStatsPrinterPlugin.js +89 -24
- package/lib/util/ArrayHelpers.js +30 -0
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/compileBooleanMatcher.js +1 -1
- package/lib/util/create-schema-validation.js +9 -2
- package/lib/util/createHash.js +12 -0
- package/lib/util/deprecation.js +10 -2
- package/lib/util/deterministicGrouping.js +1 -1
- package/lib/util/extractUrlAndGlobal.js +3 -0
- package/lib/util/fs.js +11 -0
- package/lib/util/hash/BatchedHash.js +7 -4
- package/lib/util/hash/md4.js +20 -0
- package/lib/util/hash/wasm-hash.js +163 -0
- package/lib/util/hash/xxhash64.js +5 -139
- package/lib/util/identifier.js +65 -44
- package/lib/util/internalSerializables.js +15 -0
- package/lib/util/nonNumericOnlyHash.js +22 -0
- package/lib/util/semver.js +17 -10
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +20 -9
- package/lib/webpack.js +10 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
- package/module.d.ts +215 -0
- package/package.json +23 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +254 -29
- package/schemas/plugins/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +2 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssParserOptions.json +3 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
- package/types.d.ts +628 -179
@@ -57,7 +57,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
57
57
|
/** @typedef {import("../Parser").ParserState} ParserState */
|
58
58
|
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
59
59
|
/** @typedef {{declaredScope: ScopeInfo, freeName: string | true, tagInfo: TagInfo | undefined}} VariableInfoInterface */
|
60
|
-
/** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => string[] }} GetInfoResult */
|
60
|
+
/** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => string[], getMembersOptionals: () => boolean[] }} GetInfoResult */
|
61
61
|
|
62
62
|
const EMPTY_ARRAY = [];
|
63
63
|
const ALLOWED_MEMBER_TYPES_CALL_EXPRESSION = 0b01;
|
@@ -262,9 +262,9 @@ class JavascriptParser extends Parser {
|
|
262
262
|
/** @type {HookMap<SyncBailHook<[ExpressionNode], boolean | void>>} */
|
263
263
|
call: new HookMap(() => new SyncBailHook(["expression"])),
|
264
264
|
/** Something like "a.b()" */
|
265
|
-
/** @type {HookMap<SyncBailHook<[CallExpressionNode, string[]], boolean | void>>} */
|
265
|
+
/** @type {HookMap<SyncBailHook<[CallExpressionNode, string[], boolean[]], boolean | void>>} */
|
266
266
|
callMemberChain: new HookMap(
|
267
|
-
() => new SyncBailHook(["expression", "members"])
|
267
|
+
() => new SyncBailHook(["expression", "members", "membersOptionals"])
|
268
268
|
),
|
269
269
|
/** Something like "a.b().c.d" */
|
270
270
|
/** @type {HookMap<SyncBailHook<[ExpressionNode, string[], CallExpressionNode, string[]], boolean | void>>} */
|
@@ -292,11 +292,13 @@ class JavascriptParser extends Parser {
|
|
292
292
|
optionalChaining: new SyncBailHook(["optionalChaining"]),
|
293
293
|
/** @type {HookMap<SyncBailHook<[NewExpressionNode], boolean | void>>} */
|
294
294
|
new: new HookMap(() => new SyncBailHook(["expression"])),
|
295
|
+
/** @type {SyncBailHook<[BinaryExpressionNode], boolean | void>} */
|
296
|
+
binaryExpression: new SyncBailHook(["binaryExpression"]),
|
295
297
|
/** @type {HookMap<SyncBailHook<[ExpressionNode], boolean | void>>} */
|
296
298
|
expression: new HookMap(() => new SyncBailHook(["expression"])),
|
297
|
-
/** @type {HookMap<SyncBailHook<[ExpressionNode, string[]], boolean | void>>} */
|
299
|
+
/** @type {HookMap<SyncBailHook<[ExpressionNode, string[], boolean[]], boolean | void>>} */
|
298
300
|
expressionMemberChain: new HookMap(
|
299
|
-
() => new SyncBailHook(["expression", "members"])
|
301
|
+
() => new SyncBailHook(["expression", "members", "membersOptionals"])
|
300
302
|
),
|
301
303
|
/** @type {HookMap<SyncBailHook<[ExpressionNode, string[]], boolean | void>>} */
|
302
304
|
unhandledExpressionMemberChain: new HookMap(
|
@@ -416,7 +418,6 @@ class JavascriptParser extends Parser {
|
|
416
418
|
const expr = /** @type {LogicalExpressionNode} */ (_expr);
|
417
419
|
|
418
420
|
const left = this.evaluateExpression(expr.left);
|
419
|
-
if (!left) return;
|
420
421
|
let returnRight = false;
|
421
422
|
/** @type {boolean|undefined} */
|
422
423
|
let allowedRight;
|
@@ -437,7 +438,6 @@ class JavascriptParser extends Parser {
|
|
437
438
|
returnRight = true;
|
438
439
|
} else return;
|
439
440
|
const right = this.evaluateExpression(expr.right);
|
440
|
-
if (!right) return;
|
441
441
|
if (returnRight) {
|
442
442
|
if (left.couldHaveSideEffects()) right.setSideEffects();
|
443
443
|
return right.setRange(expr.range);
|
@@ -486,10 +486,10 @@ class JavascriptParser extends Parser {
|
|
486
486
|
|
487
487
|
const handleConstOperation = fn => {
|
488
488
|
const left = this.evaluateExpression(expr.left);
|
489
|
-
if (!left
|
489
|
+
if (!left.isCompileTimeValue()) return;
|
490
490
|
|
491
491
|
const right = this.evaluateExpression(expr.right);
|
492
|
-
if (!right
|
492
|
+
if (!right.isCompileTimeValue()) return;
|
493
493
|
|
494
494
|
const result = fn(
|
495
495
|
left.asCompileTimeValue(),
|
@@ -545,9 +545,7 @@ class JavascriptParser extends Parser {
|
|
545
545
|
|
546
546
|
const handleStrictEqualityComparison = eql => {
|
547
547
|
const left = this.evaluateExpression(expr.left);
|
548
|
-
if (!left) return;
|
549
548
|
const right = this.evaluateExpression(expr.right);
|
550
|
-
if (!right) return;
|
551
549
|
const res = new BasicEvaluatedExpression();
|
552
550
|
res.setRange(expr.range);
|
553
551
|
|
@@ -600,9 +598,7 @@ class JavascriptParser extends Parser {
|
|
600
598
|
|
601
599
|
const handleAbstractEqualityComparison = eql => {
|
602
600
|
const left = this.evaluateExpression(expr.left);
|
603
|
-
if (!left) return;
|
604
601
|
const right = this.evaluateExpression(expr.right);
|
605
|
-
if (!right) return;
|
606
602
|
const res = new BasicEvaluatedExpression();
|
607
603
|
res.setRange(expr.range);
|
608
604
|
|
@@ -635,9 +631,7 @@ class JavascriptParser extends Parser {
|
|
635
631
|
|
636
632
|
if (expr.operator === "+") {
|
637
633
|
const left = this.evaluateExpression(expr.left);
|
638
|
-
if (!left) return;
|
639
634
|
const right = this.evaluateExpression(expr.right);
|
640
|
-
if (!right) return;
|
641
635
|
const res = new BasicEvaluatedExpression();
|
642
636
|
if (left.isString()) {
|
643
637
|
if (right.isString()) {
|
@@ -816,7 +810,7 @@ class JavascriptParser extends Parser {
|
|
816
810
|
|
817
811
|
const handleConstOperation = fn => {
|
818
812
|
const argument = this.evaluateExpression(expr.argument);
|
819
|
-
if (!argument
|
813
|
+
if (!argument.isCompileTimeValue()) return;
|
820
814
|
const result = fn(argument.asCompileTimeValue());
|
821
815
|
return valueAsExpression(
|
822
816
|
result,
|
@@ -915,7 +909,6 @@ class JavascriptParser extends Parser {
|
|
915
909
|
}
|
916
910
|
} else if (expr.operator === "!") {
|
917
911
|
const argument = this.evaluateExpression(expr.argument);
|
918
|
-
if (!argument) return;
|
919
912
|
const bool = argument.asBool();
|
920
913
|
if (typeof bool !== "boolean") return;
|
921
914
|
return new BasicEvaluatedExpression()
|
@@ -935,6 +928,13 @@ class JavascriptParser extends Parser {
|
|
935
928
|
.setString("undefined")
|
936
929
|
.setRange(expr.range);
|
937
930
|
});
|
931
|
+
this.hooks.evaluate.for("Identifier").tap("JavascriptParser", expr => {
|
932
|
+
if (/** @type {IdentifierNode} */ (expr).name === "undefined") {
|
933
|
+
return new BasicEvaluatedExpression()
|
934
|
+
.setUndefined()
|
935
|
+
.setRange(expr.range);
|
936
|
+
}
|
937
|
+
});
|
938
938
|
/**
|
939
939
|
* @param {string} exprType expression type name
|
940
940
|
* @param {function(ExpressionNode): GetInfoResult | undefined} getInfo get info
|
@@ -973,7 +973,12 @@ class JavascriptParser extends Parser {
|
|
973
973
|
const info = cachedExpression === expr ? cachedInfo : getInfo(expr);
|
974
974
|
if (info !== undefined) {
|
975
975
|
return new BasicEvaluatedExpression()
|
976
|
-
.setIdentifier(
|
976
|
+
.setIdentifier(
|
977
|
+
info.name,
|
978
|
+
info.rootInfo,
|
979
|
+
info.getMembers,
|
980
|
+
info.getMembersOptionals
|
981
|
+
)
|
977
982
|
.setRange(expr.range);
|
978
983
|
}
|
979
984
|
});
|
@@ -990,7 +995,12 @@ class JavascriptParser extends Parser {
|
|
990
995
|
typeof info === "string" ||
|
991
996
|
(info instanceof VariableInfo && typeof info.freeName === "string")
|
992
997
|
) {
|
993
|
-
return {
|
998
|
+
return {
|
999
|
+
name: info,
|
1000
|
+
rootInfo: info,
|
1001
|
+
getMembers: () => [],
|
1002
|
+
getMembersOptionals: () => []
|
1003
|
+
};
|
994
1004
|
}
|
995
1005
|
});
|
996
1006
|
tapEvaluateWithVariableInfo("ThisExpression", expr => {
|
@@ -999,7 +1009,12 @@ class JavascriptParser extends Parser {
|
|
999
1009
|
typeof info === "string" ||
|
1000
1010
|
(info instanceof VariableInfo && typeof info.freeName === "string")
|
1001
1011
|
) {
|
1002
|
-
return {
|
1012
|
+
return {
|
1013
|
+
name: info,
|
1014
|
+
rootInfo: info,
|
1015
|
+
getMembers: () => [],
|
1016
|
+
getMembersOptionals: () => []
|
1017
|
+
};
|
1003
1018
|
}
|
1004
1019
|
});
|
1005
1020
|
this.hooks.evaluate.for("MetaProperty").tap("JavascriptParser", expr => {
|
@@ -1032,7 +1047,6 @@ class JavascriptParser extends Parser {
|
|
1032
1047
|
const param = this.evaluateExpression(
|
1033
1048
|
/** @type {ExpressionNode} */ (expr.callee.object)
|
1034
1049
|
);
|
1035
|
-
if (!param) return;
|
1036
1050
|
const property =
|
1037
1051
|
expr.callee.property.type === "Literal"
|
1038
1052
|
? `${expr.callee.property.value}`
|
@@ -1189,14 +1203,15 @@ class JavascriptParser extends Parser {
|
|
1189
1203
|
const node = /** @type {TaggedTemplateExpressionNode} */ (_node);
|
1190
1204
|
const tag = this.evaluateExpression(node.tag);
|
1191
1205
|
|
1192
|
-
if (tag.isIdentifier() && tag.identifier
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1206
|
+
if (tag.isIdentifier() && tag.identifier === "String.raw") {
|
1207
|
+
const { quasis, parts } = getSimplifiedTemplateResult(
|
1208
|
+
"raw",
|
1209
|
+
node.quasi
|
1210
|
+
);
|
1211
|
+
return new BasicEvaluatedExpression()
|
1212
|
+
.setTemplateString(quasis, parts, "raw")
|
1213
|
+
.setRange(node.range);
|
1214
|
+
}
|
1200
1215
|
});
|
1201
1216
|
|
1202
1217
|
this.hooks.evaluateCallExpressionMember
|
@@ -1298,7 +1313,6 @@ class JavascriptParser extends Parser {
|
|
1298
1313
|
if (conditionValue === undefined) {
|
1299
1314
|
const consequent = this.evaluateExpression(expr.consequent);
|
1300
1315
|
const alternate = this.evaluateExpression(expr.alternate);
|
1301
|
-
if (!consequent || !alternate) return;
|
1302
1316
|
res = new BasicEvaluatedExpression();
|
1303
1317
|
if (consequent.isConditional()) {
|
1304
1318
|
res.setOptions(consequent.options);
|
@@ -1372,7 +1386,7 @@ class JavascriptParser extends Parser {
|
|
1372
1386
|
const expression = optionalExpressionsStack.pop();
|
1373
1387
|
const evaluated = this.evaluateExpression(expression);
|
1374
1388
|
|
1375
|
-
if (evaluated
|
1389
|
+
if (evaluated.asNullish()) {
|
1376
1390
|
return evaluated.setRange(_expr.range);
|
1377
1391
|
}
|
1378
1392
|
}
|
@@ -1382,7 +1396,7 @@ class JavascriptParser extends Parser {
|
|
1382
1396
|
|
1383
1397
|
getRenameIdentifier(expr) {
|
1384
1398
|
const result = this.evaluateExpression(expr);
|
1385
|
-
if (result
|
1399
|
+
if (result.isIdentifier()) {
|
1386
1400
|
return result.identifier;
|
1387
1401
|
}
|
1388
1402
|
}
|
@@ -2449,7 +2463,9 @@ class JavascriptParser extends Parser {
|
|
2449
2463
|
}
|
2450
2464
|
|
2451
2465
|
walkBinaryExpression(expression) {
|
2452
|
-
this.
|
2466
|
+
if (this.hooks.binaryExpression.call(expression) === undefined) {
|
2467
|
+
this.walkLeftRightExpression(expression);
|
2468
|
+
}
|
2453
2469
|
}
|
2454
2470
|
|
2455
2471
|
walkLogicalExpression(expression) {
|
@@ -2484,7 +2500,9 @@ class JavascriptParser extends Parser {
|
|
2484
2500
|
) {
|
2485
2501
|
this.setVariable(
|
2486
2502
|
expression.left.name,
|
2487
|
-
|
2503
|
+
typeof renameIdentifier === "string"
|
2504
|
+
? this.getVariableInfo(renameIdentifier)
|
2505
|
+
: renameIdentifier
|
2488
2506
|
);
|
2489
2507
|
}
|
2490
2508
|
return;
|
@@ -2619,7 +2637,9 @@ class JavascriptParser extends Parser {
|
|
2619
2637
|
argOrThis
|
2620
2638
|
)
|
2621
2639
|
) {
|
2622
|
-
return
|
2640
|
+
return typeof renameIdentifier === "string"
|
2641
|
+
? this.getVariableInfo(renameIdentifier)
|
2642
|
+
: renameIdentifier;
|
2623
2643
|
}
|
2624
2644
|
}
|
2625
2645
|
}
|
@@ -2719,7 +2739,10 @@ class JavascriptParser extends Parser {
|
|
2719
2739
|
this.hooks.callMemberChain,
|
2720
2740
|
callee.rootInfo,
|
2721
2741
|
expression,
|
2722
|
-
callee.getMembers()
|
2742
|
+
callee.getMembers(),
|
2743
|
+
callee.getMembersOptionals
|
2744
|
+
? callee.getMembersOptionals()
|
2745
|
+
: callee.getMembers().map(() => false)
|
2723
2746
|
);
|
2724
2747
|
if (result1 === true) return;
|
2725
2748
|
const result2 = this.callHooksForInfo(
|
@@ -2759,11 +2782,13 @@ class JavascriptParser extends Parser {
|
|
2759
2782
|
);
|
2760
2783
|
if (result1 === true) return;
|
2761
2784
|
const members = exprInfo.getMembers();
|
2785
|
+
const membersOptionals = exprInfo.getMembersOptionals();
|
2762
2786
|
const result2 = this.callHooksForInfo(
|
2763
2787
|
this.hooks.expressionMemberChain,
|
2764
2788
|
exprInfo.rootInfo,
|
2765
2789
|
expression,
|
2766
|
-
members
|
2790
|
+
members,
|
2791
|
+
membersOptionals
|
2767
2792
|
);
|
2768
2793
|
if (result2 === true) return;
|
2769
2794
|
this.walkMemberExpressionWithExpressionName(
|
@@ -3159,17 +3184,15 @@ class JavascriptParser extends Parser {
|
|
3159
3184
|
|
3160
3185
|
/**
|
3161
3186
|
* @param {ExpressionNode} expression expression node
|
3162
|
-
* @returns {BasicEvaluatedExpression
|
3187
|
+
* @returns {BasicEvaluatedExpression} evaluation result
|
3163
3188
|
*/
|
3164
3189
|
evaluateExpression(expression) {
|
3165
3190
|
try {
|
3166
3191
|
const hook = this.hooks.evaluate.get(expression.type);
|
3167
3192
|
if (hook !== undefined) {
|
3168
3193
|
const result = hook.call(expression);
|
3169
|
-
if (result !== undefined) {
|
3170
|
-
|
3171
|
-
result.setExpression(expression);
|
3172
|
-
}
|
3194
|
+
if (result !== undefined && result !== null) {
|
3195
|
+
result.setExpression(expression);
|
3173
3196
|
return result;
|
3174
3197
|
}
|
3175
3198
|
}
|
@@ -3340,6 +3363,10 @@ class JavascriptParser extends Parser {
|
|
3340
3363
|
return state;
|
3341
3364
|
}
|
3342
3365
|
|
3366
|
+
/**
|
3367
|
+
* @param {string} source source code
|
3368
|
+
* @returns {BasicEvaluatedExpression} evaluation result
|
3369
|
+
*/
|
3343
3370
|
evaluate(source) {
|
3344
3371
|
const ast = JavascriptParser._parse("(" + source + ")", {
|
3345
3372
|
sourceType: this.sourceType,
|
@@ -3601,12 +3628,13 @@ class JavascriptParser extends Parser {
|
|
3601
3628
|
|
3602
3629
|
/**
|
3603
3630
|
* @param {MemberExpressionNode} expression a member expression
|
3604
|
-
* @returns {{ members: string[], object: ExpressionNode | SuperNode }} member names (reverse order) and remaining object
|
3631
|
+
* @returns {{ members: string[], object: ExpressionNode | SuperNode, membersOptionals: boolean[] }} member names (reverse order) and remaining object
|
3605
3632
|
*/
|
3606
3633
|
extractMemberExpressionChain(expression) {
|
3607
3634
|
/** @type {AnyNode} */
|
3608
3635
|
let expr = expression;
|
3609
3636
|
const members = [];
|
3637
|
+
const membersOptionals = [];
|
3610
3638
|
while (expr.type === "MemberExpression") {
|
3611
3639
|
if (expr.computed) {
|
3612
3640
|
if (expr.property.type !== "Literal") break;
|
@@ -3615,10 +3643,13 @@ class JavascriptParser extends Parser {
|
|
3615
3643
|
if (expr.property.type !== "Identifier") break;
|
3616
3644
|
members.push(expr.property.name);
|
3617
3645
|
}
|
3646
|
+
membersOptionals.push(expr.optional);
|
3618
3647
|
expr = expr.object;
|
3619
3648
|
}
|
3649
|
+
|
3620
3650
|
return {
|
3621
3651
|
members,
|
3652
|
+
membersOptionals,
|
3622
3653
|
object: expr
|
3623
3654
|
};
|
3624
3655
|
}
|
@@ -3641,8 +3672,8 @@ class JavascriptParser extends Parser {
|
|
3641
3672
|
return { info, name };
|
3642
3673
|
}
|
3643
3674
|
|
3644
|
-
/** @typedef {{ type: "call", call: CallExpressionNode, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => string[], name: string, getMembers: () => string[]}} CallExpressionInfo */
|
3645
|
-
/** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => string[]}} ExpressionExpressionInfo */
|
3675
|
+
/** @typedef {{ type: "call", call: CallExpressionNode, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => string[], name: string, getMembers: () => string[], getMembersOptionals: () => boolean[]}} CallExpressionInfo */
|
3676
|
+
/** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => string[], getMembersOptionals: () => boolean[]}} ExpressionExpressionInfo */
|
3646
3677
|
|
3647
3678
|
/**
|
3648
3679
|
* @param {MemberExpressionNode} expression a member expression
|
@@ -3650,7 +3681,8 @@ class JavascriptParser extends Parser {
|
|
3650
3681
|
* @returns {CallExpressionInfo | ExpressionExpressionInfo | undefined} expression info
|
3651
3682
|
*/
|
3652
3683
|
getMemberExpressionInfo(expression, allowedTypes) {
|
3653
|
-
const { object, members } =
|
3684
|
+
const { object, members, membersOptionals } =
|
3685
|
+
this.extractMemberExpressionChain(expression);
|
3654
3686
|
switch (object.type) {
|
3655
3687
|
case "CallExpression": {
|
3656
3688
|
if ((allowedTypes & ALLOWED_MEMBER_TYPES_CALL_EXPRESSION) === 0)
|
@@ -3674,7 +3706,8 @@ class JavascriptParser extends Parser {
|
|
3674
3706
|
rootInfo,
|
3675
3707
|
getCalleeMembers: memoize(() => rootMembers.reverse()),
|
3676
3708
|
name: objectAndMembersToName(`${calleeName}()`, members),
|
3677
|
-
getMembers: memoize(() => members.reverse())
|
3709
|
+
getMembers: memoize(() => members.reverse()),
|
3710
|
+
getMembersOptionals: memoize(() => membersOptionals.reverse())
|
3678
3711
|
};
|
3679
3712
|
}
|
3680
3713
|
case "Identifier":
|
@@ -3692,7 +3725,8 @@ class JavascriptParser extends Parser {
|
|
3692
3725
|
type: "expression",
|
3693
3726
|
name: objectAndMembersToName(resolvedRoot, members),
|
3694
3727
|
rootInfo,
|
3695
|
-
getMembers: memoize(() => members.reverse())
|
3728
|
+
getMembers: memoize(() => members.reverse()),
|
3729
|
+
getMembersOptionals: memoize(() => membersOptionals.reverse())
|
3696
3730
|
};
|
3697
3731
|
}
|
3698
3732
|
}
|
@@ -5,50 +5,26 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
-
const Entrypoint = require("../Entrypoint");
|
9
8
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
10
9
|
const Template = require("../Template");
|
11
10
|
const { isSubset } = require("../util/SetHelpers");
|
12
|
-
const {
|
11
|
+
const { getAllChunks } = require("./ChunkHelpers");
|
13
12
|
|
14
13
|
/** @typedef {import("../util/Hash")} Hash */
|
15
14
|
/** @typedef {import("../Chunk")} Chunk */
|
16
15
|
/** @typedef {import("../Compilation")} Compilation */
|
17
16
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
17
|
+
/** @typedef {import("../ChunkGraph").EntryModuleWithChunkGroup} EntryModuleWithChunkGroup */
|
18
18
|
/** @typedef {import("../ChunkGroup")} ChunkGroup */
|
19
19
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
20
20
|
/** @typedef {(string|number)[]} EntryItem */
|
21
21
|
|
22
|
-
// TODO move to this file to ../javascript/ChunkHelpers.js
|
23
|
-
|
24
|
-
/**
|
25
|
-
* @param {Entrypoint} entrypoint a chunk group
|
26
|
-
* @param {Chunk} excludedChunk1 current chunk which is excluded
|
27
|
-
* @param {Chunk} excludedChunk2 runtime chunk which is excluded
|
28
|
-
* @returns {Set<Chunk>} chunks
|
29
|
-
*/
|
30
|
-
const getAllChunks = (entrypoint, excludedChunk1, excludedChunk2) => {
|
31
|
-
const queue = new Set([entrypoint]);
|
32
|
-
const chunks = new Set();
|
33
|
-
for (const entrypoint of queue) {
|
34
|
-
for (const chunk of entrypoint.chunks) {
|
35
|
-
if (chunk === excludedChunk1) continue;
|
36
|
-
if (chunk === excludedChunk2) continue;
|
37
|
-
chunks.add(chunk);
|
38
|
-
}
|
39
|
-
for (const parent of entrypoint.parentsIterable) {
|
40
|
-
if (parent instanceof Entrypoint) queue.add(parent);
|
41
|
-
}
|
42
|
-
}
|
43
|
-
return chunks;
|
44
|
-
};
|
45
|
-
|
46
22
|
const EXPORT_PREFIX = "var __webpack_exports__ = ";
|
47
23
|
|
48
24
|
/**
|
49
25
|
* @param {ChunkGraph} chunkGraph chunkGraph
|
50
26
|
* @param {RuntimeTemplate} runtimeTemplate runtimeTemplate
|
51
|
-
* @param {
|
27
|
+
* @param {EntryModuleWithChunkGroup[]} entries entries
|
52
28
|
* @param {Chunk} chunk chunk
|
53
29
|
* @param {boolean} passive true: passive startup with on chunks loaded
|
54
30
|
* @returns {string} runtime code
|
@@ -126,7 +102,7 @@ exports.generateEntryStartup = (
|
|
126
102
|
/**
|
127
103
|
* @param {Hash} hash the hash to update
|
128
104
|
* @param {ChunkGraph} chunkGraph chunkGraph
|
129
|
-
* @param {
|
105
|
+
* @param {EntryModuleWithChunkGroup[]} entries entries
|
130
106
|
* @param {Chunk} chunk chunk
|
131
107
|
* @returns {void}
|
132
108
|
*/
|
@@ -143,12 +119,13 @@ exports.updateHashForEntryStartup = (hash, chunkGraph, entries, chunk) => {
|
|
143
119
|
/**
|
144
120
|
* @param {Chunk} chunk the chunk
|
145
121
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
122
|
+
* @param {function(Chunk, ChunkGraph): boolean} filterFn filter function
|
146
123
|
* @returns {Set<number | string>} initially fulfilled chunk ids
|
147
124
|
*/
|
148
|
-
exports.getInitialChunkIds = (chunk, chunkGraph) => {
|
125
|
+
exports.getInitialChunkIds = (chunk, chunkGraph, filterFn) => {
|
149
126
|
const initialChunkIds = new Set(chunk.ids);
|
150
127
|
for (const c of chunk.getAllInitialChunks()) {
|
151
|
-
if (c === chunk ||
|
128
|
+
if (c === chunk || filterFn(c, chunkGraph)) continue;
|
152
129
|
for (const id of c.ids) initialChunkIds.add(id);
|
153
130
|
}
|
154
131
|
return initialChunkIds;
|
@@ -92,7 +92,7 @@ const accessWithInit = (accessor, existingLength, initLast = false) => {
|
|
92
92
|
* @property {LibraryType} type
|
93
93
|
* @property {string[] | "global"} prefix name prefix
|
94
94
|
* @property {string | false} declare declare name as variable
|
95
|
-
* @property {"error"|"copy"|"assign"} unnamed behavior for unnamed library name
|
95
|
+
* @property {"error"|"static"|"copy"|"assign"} unnamed behavior for unnamed library name
|
96
96
|
* @property {"copy"|"assign"=} named behavior for named library name
|
97
97
|
*/
|
98
98
|
|
@@ -174,7 +174,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
174
174
|
|
175
175
|
_getPrefix(compilation) {
|
176
176
|
return this.prefix === "global"
|
177
|
-
? [compilation.
|
177
|
+
? [compilation.runtimeTemplate.globalObject]
|
178
178
|
: this.prefix;
|
179
179
|
}
|
180
180
|
|
@@ -222,9 +222,15 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
222
222
|
* @param {LibraryContext<T>} libraryContext context
|
223
223
|
* @returns {string | undefined} bailout reason
|
224
224
|
*/
|
225
|
-
embedInRuntimeBailout(
|
225
|
+
embedInRuntimeBailout(
|
226
|
+
module,
|
227
|
+
{ chunk, codeGenerationResults },
|
228
|
+
{ options, compilation }
|
229
|
+
) {
|
230
|
+
const { data } = codeGenerationResults.get(module, chunk.runtime);
|
226
231
|
const topLevelDeclarations =
|
227
|
-
|
232
|
+
(data && data.get("topLevelDeclarations")) ||
|
233
|
+
(module.buildInfo && module.buildInfo.topLevelDeclarations);
|
228
234
|
if (!topLevelDeclarations)
|
229
235
|
return "it doesn't tell about top level declarations.";
|
230
236
|
const fullNameResolved = this._getResolvedFullName(
|
@@ -261,19 +267,42 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
261
267
|
* @param {LibraryContext<T>} libraryContext context
|
262
268
|
* @returns {Source} source with library export
|
263
269
|
*/
|
264
|
-
renderStartup(
|
270
|
+
renderStartup(
|
271
|
+
source,
|
272
|
+
module,
|
273
|
+
{ moduleGraph, chunk },
|
274
|
+
{ options, compilation }
|
275
|
+
) {
|
265
276
|
const fullNameResolved = this._getResolvedFullName(
|
266
277
|
options,
|
267
278
|
chunk,
|
268
279
|
compilation
|
269
280
|
);
|
281
|
+
const staticExports = this.unnamed === "static";
|
270
282
|
const exportAccess = options.export
|
271
283
|
? propertyAccess(
|
272
284
|
Array.isArray(options.export) ? options.export : [options.export]
|
273
285
|
)
|
274
286
|
: "";
|
275
287
|
const result = new ConcatSource(source);
|
276
|
-
if (
|
288
|
+
if (staticExports) {
|
289
|
+
const exportsInfo = moduleGraph.getExportsInfo(module);
|
290
|
+
const exportTarget = accessWithInit(
|
291
|
+
fullNameResolved,
|
292
|
+
this._getPrefix(compilation).length,
|
293
|
+
true
|
294
|
+
);
|
295
|
+
for (const exportInfo of exportsInfo.orderedExports) {
|
296
|
+
if (!exportInfo.provided) continue;
|
297
|
+
const nameAccess = propertyAccess([exportInfo.name]);
|
298
|
+
result.add(
|
299
|
+
`${exportTarget}${nameAccess} = __webpack_exports__${exportAccess}${nameAccess};\n`
|
300
|
+
);
|
301
|
+
}
|
302
|
+
result.add(
|
303
|
+
`Object.defineProperty(${exportTarget}, "__esModule", { value: true });\n`
|
304
|
+
);
|
305
|
+
} else if (options.name ? this.named === "copy" : this.unnamed === "copy") {
|
277
306
|
result.add(
|
278
307
|
`var __webpack_export_target__ = ${accessWithInit(
|
279
308
|
fullNameResolved,
|
@@ -325,15 +354,10 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
325
354
|
*/
|
326
355
|
chunkHash(chunk, hash, chunkHashContext, { options, compilation }) {
|
327
356
|
hash.update("AssignLibraryPlugin");
|
328
|
-
const
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
const fullName = options.name ? prefix.concat(options.name) : prefix;
|
333
|
-
const fullNameResolved = fullName.map(n =>
|
334
|
-
compilation.getPath(n, {
|
335
|
-
chunk
|
336
|
-
})
|
357
|
+
const fullNameResolved = this._getResolvedFullName(
|
358
|
+
options,
|
359
|
+
chunk,
|
360
|
+
compilation
|
337
361
|
);
|
338
362
|
if (options.name ? this.named === "copy" : this.unnamed === "copy") {
|
339
363
|
hash.update("copy");
|
@@ -167,6 +167,17 @@ class EnableLibraryPlugin {
|
|
167
167
|
}).apply(compiler);
|
168
168
|
break;
|
169
169
|
}
|
170
|
+
case "commonjs-static": {
|
171
|
+
//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
172
|
+
const AssignLibraryPlugin = require("./AssignLibraryPlugin");
|
173
|
+
new AssignLibraryPlugin({
|
174
|
+
type,
|
175
|
+
prefix: ["exports"],
|
176
|
+
declare: false,
|
177
|
+
unnamed: "static"
|
178
|
+
}).apply(compiler);
|
179
|
+
break;
|
180
|
+
}
|
170
181
|
case "commonjs2":
|
171
182
|
case "commonjs-module": {
|
172
183
|
//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
@@ -310,9 +310,11 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
310
310
|
: " var a = factory();\n") +
|
311
311
|
" for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n" +
|
312
312
|
" }\n") +
|
313
|
-
`})(${
|
314
|
-
runtimeTemplate.
|
315
|
-
|
313
|
+
`})(${runtimeTemplate.outputOptions.globalObject}, ${
|
314
|
+
runtimeTemplate.supportsArrowFunction()
|
315
|
+
? `(${externalsArguments(externals)}) =>`
|
316
|
+
: `function(${externalsArguments(externals)})`
|
317
|
+
} {\nreturn `,
|
316
318
|
"webpack/universalModuleDefinition"
|
317
319
|
),
|
318
320
|
source,
|
@@ -34,6 +34,8 @@ const builtins = [
|
|
34
34
|
"net",
|
35
35
|
"os",
|
36
36
|
"path",
|
37
|
+
"path/posix",
|
38
|
+
"path/win32",
|
37
39
|
"perf_hooks",
|
38
40
|
"process",
|
39
41
|
"punycode",
|
@@ -52,6 +54,7 @@ const builtins = [
|
|
52
54
|
"tty",
|
53
55
|
"url",
|
54
56
|
"util",
|
57
|
+
"util/types",
|
55
58
|
"v8",
|
56
59
|
"vm",
|
57
60
|
"wasi",
|