webpack 5.89.0 → 5.90.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +3 -0
- package/bin/webpack.js +1 -3
- package/hot/log.js +0 -2
- package/lib/APIPlugin.js +17 -13
- package/lib/ChunkGraph.js +1 -1
- package/lib/CleanPlugin.js +12 -12
- package/lib/Compilation.js +26 -17
- package/lib/Compiler.js +13 -0
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ConditionalInitFragment.js +3 -3
- package/lib/ContextModule.js +4 -4
- package/lib/ContextModuleFactory.js +1 -1
- package/lib/DefinePlugin.js +47 -26
- package/lib/DependencyTemplate.js +3 -1
- package/lib/EnvironmentNotSupportAsyncWarning.js +52 -0
- package/lib/EvalDevToolModulePlugin.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +2 -2
- package/lib/ExportsInfoApiPlugin.js +2 -2
- package/lib/ExternalModule.js +47 -12
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/FileSystemInfo.js +20 -3
- package/lib/FlagDependencyExportsPlugin.js +1 -1
- package/lib/Generator.js +1 -0
- package/lib/HotModuleReplacementPlugin.js +3 -3
- package/lib/InitFragment.js +7 -7
- package/lib/LibManifestPlugin.js +4 -1
- package/lib/Module.js +2 -1
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleInfoHeaderPlugin.js +1 -1
- package/lib/MultiStats.js +2 -2
- package/lib/NodeStuffPlugin.js +48 -0
- package/lib/NormalModule.js +13 -11
- package/lib/NormalModuleFactory.js +7 -7
- package/lib/RuntimeTemplate.js +15 -11
- package/lib/SourceMapDevToolPlugin.js +2 -2
- package/lib/Stats.js +4 -0
- package/lib/WebpackOptionsApply.js +4 -3
- package/lib/asset/AssetModulesPlugin.js +2 -3
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +53 -0
- package/lib/cache/AddManagedPathsPlugin.js +6 -1
- package/lib/cache/IdleFileCachePlugin.js +12 -5
- package/lib/cache/PackFileCacheStrategy.js +3 -3
- package/lib/cache/ResolverCachePlugin.js +2 -2
- package/lib/config/browserslistTargetHandler.js +35 -14
- package/lib/config/defaults.js +88 -52
- package/lib/config/normalization.js +17 -18
- package/lib/config/target.js +5 -0
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/css/CssExportsGenerator.js +14 -1
- package/lib/css/CssGenerator.js +14 -1
- package/lib/css/CssLoadingRuntimeModule.js +23 -23
- package/lib/css/CssModulesPlugin.js +68 -32
- package/lib/css/CssParser.js +8 -3
- package/lib/debug/ProfilingPlugin.js +2 -2
- package/lib/dependencies/AMDDefineDependency.js +4 -4
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +126 -34
- package/lib/dependencies/AMDPlugin.js +11 -4
- package/lib/dependencies/AMDRequireArrayDependency.js +13 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +159 -43
- package/lib/dependencies/AMDRequireDependency.js +2 -2
- package/lib/dependencies/AMDRequireItemDependency.js +1 -1
- package/lib/dependencies/CachedConstDependency.js +8 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/ExternalModuleDependency.js +107 -0
- package/lib/dependencies/ExternalModuleInitFragment.js +131 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +7 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +18 -18
- package/lib/dependencies/HarmonyExportInitFragment.js +6 -6
- package/lib/dependencies/HarmonyImportDependency.js +4 -4
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -6
- package/lib/dependencies/ImportDependency.js +26 -6
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/dependencies/LoaderPlugin.js +2 -1
- package/lib/dependencies/LocalModuleDependency.js +1 -1
- package/lib/dependencies/PureExpressionDependency.js +12 -4
- package/lib/dependencies/RequireIncludeDependency.js +1 -1
- package/lib/dependencies/WebpackIsIncludedDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +10 -3
- package/lib/dependencies/getFunctionExpression.js +2 -2
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +6 -6
- package/lib/hmr/HotModuleReplacement.runtime.js +3 -5
- package/lib/hmr/lazyCompilationBackend.js +4 -4
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/index.js +4 -0
- package/lib/javascript/JavascriptGenerator.js +16 -1
- package/lib/javascript/JavascriptModulesPlugin.js +33 -33
- package/lib/javascript/JavascriptParser.js +220 -74
- package/lib/json/JsonGenerator.js +1 -1
- package/lib/library/AmdLibraryPlugin.js +5 -1
- package/lib/library/AssignLibraryPlugin.js +1 -1
- package/lib/library/SystemLibraryPlugin.js +1 -1
- package/lib/library/UmdLibraryPlugin.js +39 -39
- package/lib/logging/createConsoleLogger.js +1 -19
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +8 -8
- package/lib/node/RequireChunkLoadingRuntimeModule.js +8 -8
- package/lib/node/nodeConsole.js +1 -5
- package/lib/optimize/ConcatenatedModule.js +7 -7
- package/lib/optimize/InnerGraphPlugin.js +9 -1
- package/lib/optimize/MangleExportsPlugin.js +5 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +2 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +123 -47
- package/lib/optimize/SideEffectsFlagPlugin.js +15 -3
- package/lib/optimize/SplitChunksPlugin.js +16 -16
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +2 -2
- package/lib/rules/RuleSetCompiler.js +1 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +2 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -4
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -4
- package/lib/runtime/LoadScriptRuntimeModule.js +2 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +23 -22
- package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -2
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/FileMiddleware.js +4 -4
- package/lib/serialization/ObjectMiddleware.js +4 -4
- package/lib/sharing/ConsumeSharedPlugin.js +5 -5
- package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
- package/lib/sharing/ProvideSharedModule.js +2 -2
- package/lib/sharing/SharePlugin.js +2 -2
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/sharing/utils.js +24 -28
- package/lib/stats/DefaultStatsFactoryPlugin.js +10 -10
- package/lib/stats/DefaultStatsPresetPlugin.js +3 -7
- package/lib/stats/DefaultStatsPrinterPlugin.js +34 -31
- package/lib/util/chainedImports.js +7 -6
- package/lib/util/cleverMerge.js +4 -4
- package/lib/util/comparators.js +59 -23
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +2 -2
- package/lib/util/internalSerializables.js +6 -0
- package/lib/util/numberHash.js +64 -52
- package/lib/util/runtime.js +18 -1
- package/lib/util/semver.js +19 -24
- package/lib/util/smartGrouping.js +1 -1
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +53 -28
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +6 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +13 -13
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -6
- package/package.json +25 -80
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +140 -32
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoParserOptions.json +3 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssGlobalParserOptions.json +3 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/types.d.ts +273 -94
@@ -33,7 +33,6 @@ const CssGenerator = require("./CssGenerator");
|
|
33
33
|
const CssParser = require("./CssParser");
|
34
34
|
|
35
35
|
/** @typedef {import("webpack-sources").Source} Source */
|
36
|
-
/** @typedef {import("../../declarations/WebpackOptions").CssExperimentOptions} CssExperimentOptions */
|
37
36
|
/** @typedef {import("../../declarations/WebpackOptions").Output} OutputOptions */
|
38
37
|
/** @typedef {import("../Chunk")} Chunk */
|
39
38
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
@@ -59,22 +58,59 @@ const getSchema = name => {
|
|
59
58
|
};
|
60
59
|
};
|
61
60
|
|
62
|
-
const
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
61
|
+
const generatorValidationOptions = {
|
62
|
+
name: "Css Modules Plugin",
|
63
|
+
baseDataPath: "generator"
|
64
|
+
};
|
65
|
+
const validateGeneratorOptions = {
|
66
|
+
css: createSchemaValidation(
|
67
|
+
require("../../schemas/plugins/css/CssGeneratorOptions.check.js"),
|
68
|
+
() => getSchema("CssGeneratorOptions"),
|
69
|
+
generatorValidationOptions
|
70
|
+
),
|
71
|
+
"css/auto": createSchemaValidation(
|
72
|
+
require("../../schemas/plugins/css/CssAutoGeneratorOptions.check.js"),
|
73
|
+
() => getSchema("CssAutoGeneratorOptions"),
|
74
|
+
generatorValidationOptions
|
75
|
+
),
|
76
|
+
"css/module": createSchemaValidation(
|
77
|
+
require("../../schemas/plugins/css/CssModuleGeneratorOptions.check.js"),
|
78
|
+
() => getSchema("CssModuleGeneratorOptions"),
|
79
|
+
generatorValidationOptions
|
80
|
+
),
|
81
|
+
"css/global": createSchemaValidation(
|
82
|
+
require("../../schemas/plugins/css/CssGlobalGeneratorOptions.check.js"),
|
83
|
+
() => getSchema("CssGlobalGeneratorOptions"),
|
84
|
+
generatorValidationOptions
|
85
|
+
)
|
86
|
+
};
|
87
|
+
|
88
|
+
const parserValidationOptions = {
|
89
|
+
name: "Css Modules Plugin",
|
90
|
+
baseDataPath: "parser"
|
91
|
+
};
|
92
|
+
const validateParserOptions = {
|
93
|
+
css: createSchemaValidation(
|
94
|
+
require("../../schemas/plugins/css/CssParserOptions.check.js"),
|
95
|
+
() => getSchema("CssParserOptions"),
|
96
|
+
parserValidationOptions
|
97
|
+
),
|
98
|
+
"css/auto": createSchemaValidation(
|
99
|
+
require("../../schemas/plugins/css/CssAutoParserOptions.check.js"),
|
100
|
+
() => getSchema("CssAutoParserOptions"),
|
101
|
+
parserValidationOptions
|
102
|
+
),
|
103
|
+
"css/module": createSchemaValidation(
|
104
|
+
require("../../schemas/plugins/css/CssModuleParserOptions.check.js"),
|
105
|
+
() => getSchema("CssModuleParserOptions"),
|
106
|
+
parserValidationOptions
|
107
|
+
),
|
108
|
+
"css/global": createSchemaValidation(
|
109
|
+
require("../../schemas/plugins/css/CssGlobalParserOptions.check.js"),
|
110
|
+
() => getSchema("CssGlobalParserOptions"),
|
111
|
+
parserValidationOptions
|
112
|
+
)
|
113
|
+
};
|
78
114
|
|
79
115
|
/**
|
80
116
|
* @param {string} str string
|
@@ -95,12 +131,6 @@ const escapeCss = (str, omitOptionalUnderscore) => {
|
|
95
131
|
const plugin = "CssModulesPlugin";
|
96
132
|
|
97
133
|
class CssModulesPlugin {
|
98
|
-
/**
|
99
|
-
* @param {CssExperimentOptions} options options
|
100
|
-
*/
|
101
|
-
constructor({ exportsOnly = false }) {
|
102
|
-
this._exportsOnly = exportsOnly;
|
103
|
-
}
|
104
134
|
/**
|
105
135
|
* Apply the plugin
|
106
136
|
* @param {Compiler} compiler the compiler instance
|
@@ -156,27 +186,33 @@ class CssModulesPlugin {
|
|
156
186
|
normalModuleFactory.hooks.createParser
|
157
187
|
.for(type)
|
158
188
|
.tap(plugin, parserOptions => {
|
159
|
-
validateParserOptions(parserOptions);
|
189
|
+
validateParserOptions[type](parserOptions);
|
190
|
+
const { namedExports } = parserOptions;
|
160
191
|
|
161
192
|
switch (type) {
|
162
193
|
case CSS_MODULE_TYPE:
|
163
194
|
case CSS_MODULE_TYPE_AUTO:
|
164
|
-
return new CssParser(
|
195
|
+
return new CssParser({
|
196
|
+
namedExports
|
197
|
+
});
|
165
198
|
case CSS_MODULE_TYPE_GLOBAL:
|
166
199
|
return new CssParser({
|
167
|
-
allowModeSwitch: false
|
200
|
+
allowModeSwitch: false,
|
201
|
+
namedExports
|
168
202
|
});
|
169
203
|
case CSS_MODULE_TYPE_MODULE:
|
170
204
|
return new CssParser({
|
171
|
-
defaultMode: "local"
|
205
|
+
defaultMode: "local",
|
206
|
+
namedExports
|
172
207
|
});
|
173
208
|
}
|
174
209
|
});
|
175
210
|
normalModuleFactory.hooks.createGenerator
|
176
211
|
.for(type)
|
177
212
|
.tap(plugin, generatorOptions => {
|
178
|
-
validateGeneratorOptions(generatorOptions);
|
179
|
-
|
213
|
+
validateGeneratorOptions[type](generatorOptions);
|
214
|
+
|
215
|
+
return generatorOptions.exportsOnly
|
180
216
|
? new CssExportsGenerator()
|
181
217
|
: new CssGenerator();
|
182
218
|
});
|
@@ -589,9 +625,9 @@ class CssModulesPlugin {
|
|
589
625
|
return v === shortcutValue
|
590
626
|
? `${escapeCss(n)}/`
|
591
627
|
: v === "--" + shortcutValue
|
592
|
-
|
593
|
-
|
594
|
-
|
628
|
+
? `${escapeCss(n)}%`
|
629
|
+
: `${escapeCss(n)}(${escapeCss(v)})`;
|
630
|
+
}).join("")
|
595
631
|
: ""
|
596
632
|
}${escapeCss(moduleId)}`
|
597
633
|
);
|
package/lib/css/CssParser.js
CHANGED
@@ -131,10 +131,15 @@ const CSS_MODE_AT_IMPORT_INVALID = 3;
|
|
131
131
|
const CSS_MODE_AT_NAMESPACE_INVALID = 4;
|
132
132
|
|
133
133
|
class CssParser extends Parser {
|
134
|
-
constructor({
|
134
|
+
constructor({
|
135
|
+
allowModeSwitch = true,
|
136
|
+
defaultMode = "global",
|
137
|
+
namedExports = true
|
138
|
+
} = {}) {
|
135
139
|
super();
|
136
140
|
this.allowModeSwitch = allowModeSwitch;
|
137
141
|
this.defaultMode = defaultMode;
|
142
|
+
this.namedExports = namedExports;
|
138
143
|
}
|
139
144
|
|
140
145
|
/**
|
@@ -911,7 +916,7 @@ class CssParser extends Parser {
|
|
911
916
|
) {
|
912
917
|
modeData = balanced[balanced.length - 1]
|
913
918
|
? /** @type {"local" | "global"} */
|
914
|
-
|
919
|
+
(balanced[balanced.length - 1][0])
|
915
920
|
: undefined;
|
916
921
|
const dep = new ConstDependency("", [start, end]);
|
917
922
|
module.addPresentationalDependency(dep);
|
@@ -1024,7 +1029,7 @@ class CssParser extends Parser {
|
|
1024
1029
|
}
|
1025
1030
|
|
1026
1031
|
module.buildInfo.strict = true;
|
1027
|
-
module.buildMeta.exportsType = "namespace";
|
1032
|
+
module.buildMeta.exportsType = this.namedExports ? "namespace" : "default";
|
1028
1033
|
module.addDependency(new StaticExportsDependency([], true));
|
1029
1034
|
return state;
|
1030
1035
|
}
|
@@ -31,7 +31,7 @@ const validate = createSchemaValidation(
|
|
31
31
|
let inspector = undefined;
|
32
32
|
|
33
33
|
try {
|
34
|
-
// eslint-disable-next-line
|
34
|
+
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
35
35
|
inspector = require("inspector");
|
36
36
|
} catch (e) {
|
37
37
|
console.log("Unable to CPU profile in < node 8.0");
|
@@ -374,7 +374,7 @@ const makeInterceptorFor = (instance, tracer) => hookName => ({
|
|
374
374
|
name,
|
375
375
|
type,
|
376
376
|
fn
|
377
|
-
|
377
|
+
});
|
378
378
|
return {
|
379
379
|
...tapInfo,
|
380
380
|
fn: newFn
|
@@ -108,10 +108,10 @@ const DEFINITIONS = {
|
|
108
108
|
class AMDDefineDependency extends NullDependency {
|
109
109
|
/**
|
110
110
|
* @param {Range} range range
|
111
|
-
* @param {Range} arrayRange array range
|
112
|
-
* @param {Range} functionRange function range
|
113
|
-
* @param {Range} objectRange object range
|
114
|
-
* @param {boolean} namedModule true, when define is called with a name
|
111
|
+
* @param {Range | null} arrayRange array range
|
112
|
+
* @param {Range | null} functionRange function range
|
113
|
+
* @param {Range | null} objectRange object range
|
114
|
+
* @param {boolean | null} namedModule true, when define is called with a name
|
115
115
|
*/
|
116
116
|
constructor(range, arrayRange, functionRange, objectRange, namedModule) {
|
117
117
|
super();
|
@@ -16,11 +16,20 @@ const DynamicExports = require("./DynamicExports");
|
|
16
16
|
const LocalModuleDependency = require("./LocalModuleDependency");
|
17
17
|
const { addLocalModule, getLocalModule } = require("./LocalModulesHelpers");
|
18
18
|
|
19
|
+
/** @typedef {import("estree").ArrowFunctionExpression} ArrowFunctionExpression */
|
19
20
|
/** @typedef {import("estree").CallExpression} CallExpression */
|
21
|
+
/** @typedef {import("estree").Expression} Expression */
|
22
|
+
/** @typedef {import("estree").FunctionExpression} FunctionExpression */
|
23
|
+
/** @typedef {import("estree").Literal} Literal */
|
24
|
+
/** @typedef {import("estree").SpreadElement} SpreadElement */
|
25
|
+
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
26
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
27
|
+
/** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
|
20
28
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
29
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
21
30
|
|
22
31
|
/**
|
23
|
-
* @param {
|
32
|
+
* @param {Expression | SpreadElement} expr expression
|
24
33
|
* @returns {boolean} true if it's a bound function expression
|
25
34
|
*/
|
26
35
|
const isBoundFunctionExpression = expr => {
|
@@ -33,12 +42,22 @@ const isBoundFunctionExpression = expr => {
|
|
33
42
|
return true;
|
34
43
|
};
|
35
44
|
|
45
|
+
/** @typedef {FunctionExpression | ArrowFunctionExpression} UnboundFunctionExpression */
|
46
|
+
|
47
|
+
/**
|
48
|
+
* @param {Expression | SpreadElement} expr expression
|
49
|
+
* @returns {boolean} true when unbound function expression
|
50
|
+
*/
|
36
51
|
const isUnboundFunctionExpression = expr => {
|
37
52
|
if (expr.type === "FunctionExpression") return true;
|
38
53
|
if (expr.type === "ArrowFunctionExpression") return true;
|
39
54
|
return false;
|
40
55
|
};
|
41
56
|
|
57
|
+
/**
|
58
|
+
* @param {Expression | SpreadElement} expr expression
|
59
|
+
* @returns {boolean} true when callable
|
60
|
+
*/
|
42
61
|
const isCallable = expr => {
|
43
62
|
if (isUnboundFunctionExpression(expr)) return true;
|
44
63
|
if (isBoundFunctionExpression(expr)) return true;
|
@@ -46,6 +65,9 @@ const isCallable = expr => {
|
|
46
65
|
};
|
47
66
|
|
48
67
|
class AMDDefineDependencyParserPlugin {
|
68
|
+
/**
|
69
|
+
* @param {JavascriptParserOptions} options parserOptions
|
70
|
+
*/
|
49
71
|
constructor(options) {
|
50
72
|
this.options = options;
|
51
73
|
}
|
@@ -63,12 +85,23 @@ class AMDDefineDependencyParserPlugin {
|
|
63
85
|
);
|
64
86
|
}
|
65
87
|
|
88
|
+
/**
|
89
|
+
* @param {JavascriptParser} parser the parser
|
90
|
+
* @param {CallExpression} expr call expression
|
91
|
+
* @param {BasicEvaluatedExpression} param param
|
92
|
+
* @param {Record<number, string>} identifiers identifiers
|
93
|
+
* @param {string=} namedModule named module
|
94
|
+
* @returns {boolean | undefined} result
|
95
|
+
*/
|
66
96
|
processArray(parser, expr, param, identifiers, namedModule) {
|
67
97
|
if (param.isArray()) {
|
68
|
-
|
98
|
+
/** @type {BasicEvaluatedExpression[]} */
|
99
|
+
(param.items).forEach((param, idx) => {
|
69
100
|
if (
|
70
101
|
param.isString() &&
|
71
|
-
["require", "module", "exports"].includes(
|
102
|
+
["require", "module", "exports"].includes(
|
103
|
+
/** @type {string} */ (param.string)
|
104
|
+
)
|
72
105
|
)
|
73
106
|
identifiers[idx] = param.string;
|
74
107
|
const result = this.processItem(parser, expr, param, namedModule);
|
@@ -78,6 +111,7 @@ class AMDDefineDependencyParserPlugin {
|
|
78
111
|
});
|
79
112
|
return true;
|
80
113
|
} else if (param.isConstArray()) {
|
114
|
+
/** @type {(string | LocalModuleDependency | AMDRequireItemDependency)[]} */
|
81
115
|
const deps = [];
|
82
116
|
param.array.forEach((request, idx) => {
|
83
117
|
let dep;
|
@@ -91,26 +125,38 @@ class AMDDefineDependencyParserPlugin {
|
|
91
125
|
} else if ((localModule = getLocalModule(parser.state, request))) {
|
92
126
|
localModule.flagUsed();
|
93
127
|
dep = new LocalModuleDependency(localModule, undefined, false);
|
94
|
-
dep.loc = expr.loc;
|
128
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
95
129
|
parser.state.module.addPresentationalDependency(dep);
|
96
130
|
} else {
|
97
131
|
dep = this.newRequireItemDependency(request);
|
98
|
-
dep.loc = expr.loc;
|
132
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
99
133
|
dep.optional = !!parser.scope.inTry;
|
100
134
|
parser.state.current.addDependency(dep);
|
101
135
|
}
|
102
136
|
deps.push(dep);
|
103
137
|
});
|
104
|
-
const dep = this.newRequireArrayDependency(
|
105
|
-
|
138
|
+
const dep = this.newRequireArrayDependency(
|
139
|
+
deps,
|
140
|
+
/** @type {Range} */ (param.range)
|
141
|
+
);
|
142
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
106
143
|
dep.optional = !!parser.scope.inTry;
|
107
144
|
parser.state.module.addPresentationalDependency(dep);
|
108
145
|
return true;
|
109
146
|
}
|
110
147
|
}
|
148
|
+
|
149
|
+
/**
|
150
|
+
* @param {JavascriptParser} parser the parser
|
151
|
+
* @param {CallExpression} expr call expression
|
152
|
+
* @param {BasicEvaluatedExpression} param param
|
153
|
+
* @param {string=} namedModule named module
|
154
|
+
* @returns {boolean} result
|
155
|
+
*/
|
111
156
|
processItem(parser, expr, param, namedModule) {
|
112
157
|
if (param.isConditional()) {
|
113
|
-
|
158
|
+
/** @type {BasicEvaluatedExpression[]} */
|
159
|
+
(param.options).forEach(param => {
|
114
160
|
const result = this.processItem(parser, expr, param);
|
115
161
|
if (result === undefined) {
|
116
162
|
this.processContext(parser, expr, param);
|
@@ -120,19 +166,29 @@ class AMDDefineDependencyParserPlugin {
|
|
120
166
|
} else if (param.isString()) {
|
121
167
|
let dep, localModule;
|
122
168
|
if (param.string === "require") {
|
123
|
-
dep = new ConstDependency(
|
124
|
-
RuntimeGlobals.require
|
125
|
-
|
169
|
+
dep = new ConstDependency(
|
170
|
+
RuntimeGlobals.require,
|
171
|
+
/** @type {Range} */ (param.range),
|
172
|
+
[RuntimeGlobals.require]
|
173
|
+
);
|
126
174
|
} else if (param.string === "exports") {
|
127
|
-
dep = new ConstDependency(
|
128
|
-
|
129
|
-
|
175
|
+
dep = new ConstDependency(
|
176
|
+
"exports",
|
177
|
+
/** @type {Range} */ (param.range),
|
178
|
+
[RuntimeGlobals.exports]
|
179
|
+
);
|
130
180
|
} else if (param.string === "module") {
|
131
|
-
dep = new ConstDependency(
|
132
|
-
|
133
|
-
|
181
|
+
dep = new ConstDependency(
|
182
|
+
"module",
|
183
|
+
/** @type {Range} */ (param.range),
|
184
|
+
[RuntimeGlobals.module]
|
185
|
+
);
|
134
186
|
} else if (
|
135
|
-
(localModule = getLocalModule(
|
187
|
+
(localModule = getLocalModule(
|
188
|
+
parser.state,
|
189
|
+
/** @type {string} */ (param.string),
|
190
|
+
namedModule
|
191
|
+
))
|
136
192
|
) {
|
137
193
|
localModule.flagUsed();
|
138
194
|
dep = new LocalModuleDependency(localModule, param.range, false);
|
@@ -142,15 +198,22 @@ class AMDDefineDependencyParserPlugin {
|
|
142
198
|
parser.state.current.addDependency(dep);
|
143
199
|
return true;
|
144
200
|
}
|
145
|
-
dep.loc = expr.loc;
|
201
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
146
202
|
parser.state.module.addPresentationalDependency(dep);
|
147
203
|
return true;
|
148
204
|
}
|
149
205
|
}
|
206
|
+
|
207
|
+
/**
|
208
|
+
* @param {JavascriptParser} parser the parser
|
209
|
+
* @param {CallExpression} expr call expression
|
210
|
+
* @param {BasicEvaluatedExpression} param param
|
211
|
+
* @returns {boolean | undefined} result
|
212
|
+
*/
|
150
213
|
processContext(parser, expr, param) {
|
151
214
|
const dep = ContextDependencyHelpers.create(
|
152
215
|
AMDRequireContextDependency,
|
153
|
-
param.range,
|
216
|
+
/** @type {Range} */ (param.range),
|
154
217
|
param,
|
155
218
|
expr,
|
156
219
|
this.options,
|
@@ -160,12 +223,17 @@ class AMDDefineDependencyParserPlugin {
|
|
160
223
|
parser
|
161
224
|
);
|
162
225
|
if (!dep) return;
|
163
|
-
dep.loc = expr.loc;
|
226
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
164
227
|
dep.optional = !!parser.scope.inTry;
|
165
228
|
parser.state.current.addDependency(dep);
|
166
229
|
return true;
|
167
230
|
}
|
168
231
|
|
232
|
+
/**
|
233
|
+
* @param {JavascriptParser} parser the parser
|
234
|
+
* @param {CallExpression} expr call expression
|
235
|
+
* @returns {boolean | undefined} result
|
236
|
+
*/
|
169
237
|
processCallDefine(parser, expr) {
|
170
238
|
let array, fn, obj, namedModule;
|
171
239
|
switch (expr.arguments.length) {
|
@@ -214,7 +282,7 @@ class AMDDefineDependencyParserPlugin {
|
|
214
282
|
break;
|
215
283
|
case 3:
|
216
284
|
// define("…", […], f() {…})
|
217
|
-
namedModule = expr.arguments[0].value;
|
285
|
+
namedModule = /** @type {TODO} */ (expr).arguments[0].value;
|
218
286
|
array = expr.arguments[1];
|
219
287
|
if (isCallable(expr.arguments[2])) {
|
220
288
|
// define("…", […], f() {})
|
@@ -236,10 +304,10 @@ class AMDDefineDependencyParserPlugin {
|
|
236
304
|
let fnParamsOffset = 0;
|
237
305
|
if (fn) {
|
238
306
|
if (isUnboundFunctionExpression(fn)) {
|
239
|
-
fnParams = fn.params;
|
307
|
+
fnParams = /** @type {UnboundFunctionExpression} */ (fn).params;
|
240
308
|
} else if (isBoundFunctionExpression(fn)) {
|
241
|
-
fnParams = fn.callee.object.params;
|
242
|
-
fnParamsOffset = fn.arguments.length - 1;
|
309
|
+
fnParams = /** @type {TODO} */ (fn).callee.object.params;
|
310
|
+
fnParamsOffset = /** @type {TODO} */ (fn).arguments.length - 1;
|
243
311
|
if (fnParamsOffset < 0) {
|
244
312
|
fnParamsOffset = 0;
|
245
313
|
}
|
@@ -247,6 +315,7 @@ class AMDDefineDependencyParserPlugin {
|
|
247
315
|
}
|
248
316
|
let fnRenames = new Map();
|
249
317
|
if (array) {
|
318
|
+
/** @type {Record<number, string>} */
|
250
319
|
const identifiers = {};
|
251
320
|
const param = parser.evaluateExpression(array);
|
252
321
|
const result = this.processArray(
|
@@ -278,6 +347,7 @@ class AMDDefineDependencyParserPlugin {
|
|
278
347
|
});
|
279
348
|
}
|
280
349
|
}
|
350
|
+
/** @type {boolean | undefined} */
|
281
351
|
let inTry;
|
282
352
|
if (fn && isUnboundFunctionExpression(fn)) {
|
283
353
|
inTry = parser.scope.inTry;
|
@@ -285,7 +355,7 @@ class AMDDefineDependencyParserPlugin {
|
|
285
355
|
for (const [name, varInfo] of fnRenames) {
|
286
356
|
parser.setVariable(name, varInfo);
|
287
357
|
}
|
288
|
-
parser.scope.inTry = inTry;
|
358
|
+
parser.scope.inTry = /** @type {boolean} */ (inTry);
|
289
359
|
if (fn.body.type === "BlockStatement") {
|
290
360
|
parser.detectMode(fn.body.body);
|
291
361
|
const prev = parser.prevStatement;
|
@@ -299,7 +369,8 @@ class AMDDefineDependencyParserPlugin {
|
|
299
369
|
} else if (fn && isBoundFunctionExpression(fn)) {
|
300
370
|
inTry = parser.scope.inTry;
|
301
371
|
parser.inScope(
|
302
|
-
|
372
|
+
/** @type {TODO} */
|
373
|
+
(fn).callee.object.params.filter(
|
303
374
|
i => !["require", "module", "exports"].includes(i.name)
|
304
375
|
),
|
305
376
|
() => {
|
@@ -318,21 +389,21 @@ class AMDDefineDependencyParserPlugin {
|
|
318
389
|
}
|
319
390
|
}
|
320
391
|
);
|
321
|
-
if (fn.arguments) {
|
322
|
-
parser.walkExpressions(fn.arguments);
|
392
|
+
if (/** @type {TODO} */ (fn).arguments) {
|
393
|
+
parser.walkExpressions(/** @type {TODO} */ (fn).arguments);
|
323
394
|
}
|
324
395
|
} else if (fn || obj) {
|
325
396
|
parser.walkExpression(fn || obj);
|
326
397
|
}
|
327
398
|
|
328
399
|
const dep = this.newDefineDependency(
|
329
|
-
expr.range,
|
330
|
-
array ? array.range : null,
|
331
|
-
fn ? fn.range : null,
|
332
|
-
obj ? obj.range : null,
|
400
|
+
/** @type {Range} */ (expr.range),
|
401
|
+
array ? /** @type {Range} */ (array.range) : null,
|
402
|
+
fn ? /** @type {Range} */ (fn.range) : null,
|
403
|
+
obj ? /** @type {Range} */ (obj.range) : null,
|
333
404
|
namedModule ? namedModule : null
|
334
405
|
);
|
335
|
-
dep.loc = expr.loc;
|
406
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
336
407
|
if (namedModule) {
|
337
408
|
dep.localModule = addLocalModule(parser.state, namedModule);
|
338
409
|
}
|
@@ -340,6 +411,14 @@ class AMDDefineDependencyParserPlugin {
|
|
340
411
|
return true;
|
341
412
|
}
|
342
413
|
|
414
|
+
/**
|
415
|
+
* @param {Range} range range
|
416
|
+
* @param {Range | null} arrayRange array range
|
417
|
+
* @param {Range | null} functionRange function range
|
418
|
+
* @param {Range | null} objectRange object range
|
419
|
+
* @param {boolean | null} namedModule true, when define is called with a name
|
420
|
+
* @returns {AMDDefineDependency} AMDDefineDependency
|
421
|
+
*/
|
343
422
|
newDefineDependency(
|
344
423
|
range,
|
345
424
|
arrayRange,
|
@@ -355,11 +434,24 @@ class AMDDefineDependencyParserPlugin {
|
|
355
434
|
namedModule
|
356
435
|
);
|
357
436
|
}
|
437
|
+
|
438
|
+
/**
|
439
|
+
* @param {TODO[]} depsArray deps array
|
440
|
+
* @param {Range} range range
|
441
|
+
* @returns {AMDRequireArrayDependency} AMDRequireArrayDependency
|
442
|
+
*/
|
358
443
|
newRequireArrayDependency(depsArray, range) {
|
359
444
|
return new AMDRequireArrayDependency(depsArray, range);
|
360
445
|
}
|
446
|
+
|
447
|
+
/**
|
448
|
+
* @param {string} request request
|
449
|
+
* @param {Range=} range range
|
450
|
+
* @returns {AMDRequireItemDependency} AMDRequireItemDependency
|
451
|
+
*/
|
361
452
|
newRequireItemDependency(request, range) {
|
362
453
|
return new AMDRequireItemDependency(request, range);
|
363
454
|
}
|
364
455
|
}
|
456
|
+
|
365
457
|
module.exports = AMDDefineDependencyParserPlugin;
|
@@ -35,7 +35,9 @@ const UnsupportedDependency = require("./UnsupportedDependency");
|
|
35
35
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
36
36
|
/** @typedef {import("../../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
|
37
37
|
/** @typedef {import("../Compiler")} Compiler */
|
38
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
38
39
|
/** @typedef {import("../javascript/JavascriptParser")} Parser */
|
40
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
39
41
|
|
40
42
|
const PLUGIN_NAME = "AMDPlugin";
|
41
43
|
|
@@ -135,6 +137,11 @@ class AMDPlugin {
|
|
135
137
|
const handler = (parser, parserOptions) => {
|
136
138
|
if (parserOptions.amd !== undefined && !parserOptions.amd) return;
|
137
139
|
|
140
|
+
/**
|
141
|
+
* @param {string} optionExpr option expression
|
142
|
+
* @param {string} rootName root name
|
143
|
+
* @param {function(): TODO} getMembers callback
|
144
|
+
*/
|
138
145
|
const tapOptionsHooks = (optionExpr, rootName, getMembers) => {
|
139
146
|
parser.hooks.expression
|
140
147
|
.for(optionExpr)
|
@@ -177,10 +184,10 @@ class AMDPlugin {
|
|
177
184
|
parser.hooks.expression.for("define").tap(PLUGIN_NAME, expr => {
|
178
185
|
const dep = new ConstDependency(
|
179
186
|
RuntimeGlobals.amdDefine,
|
180
|
-
expr.range,
|
187
|
+
/** @type {Range} */ (expr.range),
|
181
188
|
[RuntimeGlobals.amdDefine]
|
182
189
|
);
|
183
|
-
dep.loc = expr.loc;
|
190
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
184
191
|
parser.state.module.addPresentationalDependency(dep);
|
185
192
|
return true;
|
186
193
|
});
|
@@ -197,10 +204,10 @@ class AMDPlugin {
|
|
197
204
|
parser.hooks.rename.for("define").tap(PLUGIN_NAME, expr => {
|
198
205
|
const dep = new ConstDependency(
|
199
206
|
RuntimeGlobals.amdDefine,
|
200
|
-
expr.range,
|
207
|
+
/** @type {Range} */ (expr.range),
|
201
208
|
[RuntimeGlobals.amdDefine]
|
202
209
|
);
|
203
|
-
dep.loc = expr.loc;
|
210
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
204
211
|
parser.state.module.addPresentationalDependency(dep);
|
205
212
|
return false;
|
206
213
|
});
|
@@ -15,10 +15,12 @@ const NullDependency = require("./NullDependency");
|
|
15
15
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
16
16
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
17
17
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
18
|
+
/** @typedef {import("./AMDRequireItemDependency")} AMDRequireItemDependency */
|
19
|
+
/** @typedef {import("./LocalModuleDependency")} LocalModuleDependency */
|
18
20
|
|
19
21
|
class AMDRequireArrayDependency extends NullDependency {
|
20
22
|
/**
|
21
|
-
* @param {
|
23
|
+
* @param {(string | LocalModuleDependency | AMDRequireItemDependency)[]} depsArray deps array
|
22
24
|
* @param {Range} range range
|
23
25
|
*/
|
24
26
|
constructor(depsArray, range) {
|
@@ -81,6 +83,11 @@ AMDRequireArrayDependency.Template = class AMDRequireArrayDependencyTemplate ext
|
|
81
83
|
source.replace(dep.range[0], dep.range[1] - 1, content);
|
82
84
|
}
|
83
85
|
|
86
|
+
/**
|
87
|
+
* @param {AMDRequireArrayDependency} dep the dependency for which the template should be applied
|
88
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
89
|
+
* @returns {string} content
|
90
|
+
*/
|
84
91
|
getContent(dep, templateContext) {
|
85
92
|
const requires = dep.depsArray.map(dependency => {
|
86
93
|
return this.contentForDependency(dependency, templateContext);
|
@@ -88,6 +95,11 @@ AMDRequireArrayDependency.Template = class AMDRequireArrayDependencyTemplate ext
|
|
88
95
|
return `[${requires.join(", ")}]`;
|
89
96
|
}
|
90
97
|
|
98
|
+
/**
|
99
|
+
* @param {TODO} dep the dependency for which the template should be applied
|
100
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
101
|
+
* @returns {string} content
|
102
|
+
*/
|
91
103
|
contentForDependency(
|
92
104
|
dep,
|
93
105
|
{ runtimeTemplate, moduleGraph, chunkGraph, runtimeRequirements }
|