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