webpack 5.99.9 → 5.100.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.
- package/bin/webpack.js +8 -2
- package/hot/log.js +15 -15
- package/hot/poll.js +1 -0
- package/lib/APIPlugin.js +3 -3
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -0
- package/lib/BannerPlugin.js +1 -1
- package/lib/CaseSensitiveModulesWarning.js +4 -4
- package/lib/Chunk.js +6 -6
- package/lib/ChunkGraph.js +37 -31
- package/lib/ChunkGroup.js +4 -4
- package/lib/ChunkTemplate.js +1 -1
- package/lib/CleanPlugin.js +94 -17
- package/lib/CodeGenerationResults.js +1 -1
- package/lib/CompatibilityPlugin.js +5 -2
- package/lib/Compilation.js +67 -45
- package/lib/Compiler.js +46 -16
- package/lib/ConcatenationScope.js +15 -6
- package/lib/ConstPlugin.js +5 -3
- package/lib/ContextModule.js +16 -12
- package/lib/ContextModuleFactory.js +4 -3
- package/lib/ContextReplacementPlugin.js +4 -2
- package/lib/CssModule.js +2 -2
- package/lib/DefinePlugin.js +111 -3
- package/lib/DelegatedModuleFactoryPlugin.js +18 -18
- package/lib/Dependency.js +6 -1
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DllEntryPlugin.js +3 -1
- package/lib/DllPlugin.js +4 -3
- package/lib/DllReferencePlugin.js +2 -2
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EntryOptionPlugin.js +5 -0
- package/lib/ErrorHelpers.js +4 -4
- package/lib/EvalDevToolModulePlugin.js +3 -3
- package/lib/EvalSourceMapDevToolPlugin.js +7 -7
- package/lib/ExportsInfo.js +48 -39
- package/lib/ExternalModule.js +15 -11
- package/lib/ExternalModuleFactoryPlugin.js +5 -2
- package/lib/FileSystemInfo.js +51 -36
- package/lib/FlagDependencyExportsPlugin.js +14 -7
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +14 -1
- package/lib/HookWebpackError.js +1 -0
- package/lib/HotModuleReplacementPlugin.js +77 -50
- package/lib/IgnorePlugin.js +1 -1
- package/lib/InvalidDependenciesModuleWarning.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +0 -1
- package/lib/LibManifestPlugin.js +4 -2
- package/lib/LoaderOptionsPlugin.js +6 -4
- package/lib/MainTemplate.js +2 -2
- package/lib/Module.js +21 -6
- package/lib/ModuleFactory.js +1 -0
- package/lib/ModuleGraph.js +24 -2
- package/lib/ModuleGraphConnection.js +5 -5
- package/lib/ModuleInfoHeaderPlugin.js +2 -1
- package/lib/ModuleParseError.js +1 -0
- package/lib/ModuleSourceTypesConstants.js +12 -12
- package/lib/ModuleTemplate.js +1 -1
- package/lib/ModuleTypeConstants.js +21 -21
- package/lib/MultiCompiler.js +6 -6
- package/lib/NormalModule.js +31 -44
- package/lib/NormalModuleFactory.js +29 -19
- package/lib/NormalModuleReplacementPlugin.js +1 -1
- package/lib/NullFactory.js +1 -0
- package/lib/OptimizationStages.js +1 -1
- package/lib/Parser.js +1 -0
- package/lib/ProgressPlugin.js +12 -5
- package/lib/ProvidePlugin.js +5 -1
- package/lib/RecordIdsPlugin.js +3 -3
- package/lib/RuntimeGlobals.js +175 -155
- package/lib/RuntimeModule.js +1 -0
- package/lib/RuntimePlugin.js +33 -7
- package/lib/RuntimeTemplate.js +111 -11
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +15 -25
- package/lib/SourceMapDevToolPlugin.js +19 -17
- package/lib/Template.js +2 -2
- package/lib/TemplatedPathPlugin.js +1 -1
- package/lib/WarnDeprecatedOptionPlugin.js +7 -8
- package/lib/WatchIgnorePlugin.js +4 -3
- package/lib/WebpackIsIncludedPlugin.js +2 -1
- package/lib/WebpackOptionsApply.js +115 -27
- package/lib/asset/AssetGenerator.js +15 -11
- package/lib/asset/AssetModulesPlugin.js +19 -17
- package/lib/asset/AssetSourceGenerator.js +4 -4
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +1 -1
- package/lib/buildChunkGraph.js +6 -3
- package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
- package/lib/cache/IdleFileCachePlugin.js +7 -4
- package/lib/cache/MemoryCachePlugin.js +1 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +26 -20
- package/lib/cache/ResolverCachePlugin.js +16 -8
- package/lib/cli.js +15 -10
- package/lib/config/browserslistTargetHandler.js +3 -3
- package/lib/config/defaults.js +25 -17
- package/lib/config/normalization.js +2 -1
- package/lib/config/target.js +6 -5
- package/lib/container/ContainerPlugin.js +1 -1
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackModule.js +2 -1
- package/lib/container/HoistContainerReferencesPlugin.js +1 -1
- package/lib/container/ModuleFederationPlugin.js +2 -2
- package/lib/container/RemoteModule.js +1 -1
- package/lib/css/CssGenerator.js +9 -6
- package/lib/css/CssModulesPlugin.js +44 -31
- package/lib/css/CssParser.js +6 -4
- package/lib/css/walkCssTokens.js +33 -37
- package/lib/debug/ProfilingPlugin.js +6 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -8
- package/lib/dependencies/AMDPlugin.js +12 -8
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -26
- package/lib/dependencies/CachedConstDependency.js +1 -5
- package/lib/dependencies/CommonJsExportRequireDependency.js +6 -4
- package/lib/dependencies/CommonJsExportsParserPlugin.js +22 -25
- package/lib/dependencies/CommonJsFullRequireDependency.js +1 -9
- package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -114
- package/lib/dependencies/CommonJsPlugin.js +15 -16
- package/lib/dependencies/ContextDependencyHelpers.js +2 -1
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/DynamicExports.js +9 -9
- package/lib/dependencies/ExportsInfoDependency.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +122 -101
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +95 -19
- package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
- package/lib/dependencies/HarmonyImportDependency.js +11 -5
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +238 -162
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +20 -9
- package/lib/dependencies/HarmonyModulesPlugin.js +23 -12
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
- package/lib/dependencies/ImportMetaPlugin.js +2 -2
- package/lib/dependencies/ImportParserPlugin.js +40 -9
- package/lib/dependencies/ImportPlugin.js +3 -1
- package/lib/dependencies/LoaderPlugin.js +1 -0
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +3 -1
- package/lib/dependencies/RequireEnsurePlugin.js +6 -6
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
- package/lib/dependencies/RequireIncludePlugin.js +1 -0
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/URLContextDependency.js +65 -0
- package/lib/dependencies/URLPlugin.js +17 -157
- package/lib/dependencies/WorkerPlugin.js +23 -10
- package/lib/dependencies/processExportInfo.js +2 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +269 -185
- package/lib/esm/ModuleChunkLoadingPlugin.js +39 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +70 -3
- package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
- package/lib/hmr/LazyCompilationPlugin.js +4 -2
- package/lib/hmr/lazyCompilationBackend.js +4 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +6 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +30 -35
- package/lib/ids/DeterministicModuleIdsPlugin.js +4 -3
- package/lib/ids/HashedModuleIdsPlugin.js +5 -4
- package/lib/ids/IdHelpers.js +21 -17
- package/lib/ids/NamedChunkIdsPlugin.js +5 -5
- package/lib/ids/NamedModuleIdsPlugin.js +4 -4
- package/lib/ids/NaturalChunkIdsPlugin.js +2 -1
- package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +3 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +1 -1
- package/lib/index.js +13 -3
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +113 -119
- package/lib/javascript/BasicEvaluatedExpression.js +2 -1
- package/lib/javascript/ChunkHelpers.js +1 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +121 -136
- package/lib/javascript/EnableChunkLoadingPlugin.js +6 -3
- package/lib/javascript/JavascriptGenerator.js +14 -2
- package/lib/javascript/JavascriptModulesPlugin.js +68 -27
- package/lib/javascript/JavascriptParser.js +117 -76
- package/lib/javascript/JavascriptParserHelpers.js +41 -41
- package/lib/javascript/StartupHelpers.js +17 -17
- package/lib/json/JsonGenerator.js +4 -2
- package/lib/json/JsonModulesPlugin.js +2 -2
- package/lib/json/JsonParser.js +1 -1
- package/lib/library/AbstractLibraryPlugin.js +6 -2
- package/lib/library/AssignLibraryPlugin.js +21 -6
- package/lib/library/EnableLibraryPlugin.js +23 -3
- package/lib/library/UmdLibraryPlugin.js +15 -6
- package/lib/logging/createConsoleLogger.js +3 -3
- package/lib/logging/runtime.js +9 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/nodeConsole.js +4 -2
- package/lib/optimize/AggressiveMergingPlugin.js +45 -46
- package/lib/optimize/AggressiveSplittingPlugin.js +13 -12
- package/lib/optimize/ConcatenatedModule.js +227 -57
- package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -1
- package/lib/optimize/InnerGraph.js +115 -112
- package/lib/optimize/InnerGraphPlugin.js +2 -2
- package/lib/optimize/LimitChunkCountPlugin.js +4 -2
- package/lib/optimize/MangleExportsPlugin.js +4 -3
- package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
- package/lib/optimize/MinChunkSizePlugin.js +6 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +31 -22
- package/lib/optimize/RealContentHashPlugin.js +26 -20
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +16 -13
- package/lib/rules/BasicEffectRulePlugin.js +4 -2
- package/lib/rules/BasicMatcherRulePlugin.js +3 -1
- package/lib/rules/ObjectMatcherRulePlugin.js +3 -1
- package/lib/rules/RuleSetCompiler.js +6 -3
- package/lib/rules/UseEffectRulePlugin.js +3 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +64 -9
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +214 -0
- package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -7
- package/lib/schemes/FileUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +27 -19
- package/lib/schemes/VirtualUrlPlugin.js +222 -0
- package/lib/serialization/AggregateErrorSerializer.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +5 -4
- package/lib/serialization/FileMiddleware.js +7 -4
- package/lib/serialization/ObjectMiddleware.js +14 -8
- package/lib/serialization/Serializer.js +5 -3
- package/lib/serialization/SerializerMiddleware.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +3 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -2
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +3 -2
- package/lib/sharing/SharePlugin.js +2 -1
- package/lib/sharing/ShareRuntimeModule.js +3 -5
- package/lib/sharing/utils.js +34 -34
- package/lib/stats/DefaultStatsFactoryPlugin.js +49 -46
- package/lib/stats/DefaultStatsPresetPlugin.js +4 -2
- package/lib/stats/DefaultStatsPrinterPlugin.js +15 -9
- package/lib/stats/StatsFactory.js +4 -2
- package/lib/stats/StatsPrinter.js +3 -2
- package/lib/url/URLParserPlugin.js +266 -0
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Hash.js +2 -0
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +2 -1
- package/lib/util/LazySet.js +11 -6
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/SetHelpers.js +3 -3
- package/lib/util/SortableSet.js +2 -2
- package/lib/util/StackedCacheMap.js +3 -1
- package/lib/util/StackedMap.js +2 -2
- package/lib/util/StringXor.js +1 -0
- package/lib/util/TupleSet.js +1 -0
- package/lib/util/URLAbsoluteSpecifier.js +1 -1
- package/lib/util/cleverMerge.js +12 -8
- package/lib/util/comparators.js +154 -127
- package/lib/util/compileBooleanMatcher.js +8 -3
- package/lib/util/concatenate.js +8 -7
- package/lib/util/conventions.js +72 -73
- package/lib/util/create-schema-validation.js +2 -1
- package/lib/util/createHash.js +10 -4
- package/lib/util/deprecation.js +69 -66
- package/lib/util/deterministicGrouping.js +4 -2
- package/lib/util/extractUrlAndGlobal.js +1 -1
- package/lib/util/findGraphRoots.js +2 -2
- package/lib/util/fs.js +30 -23
- package/lib/util/hash/md4.js +2 -2
- package/lib/util/hash/wasm-hash.js +4 -2
- package/lib/util/identifier.js +13 -12
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/magicComment.js +5 -5
- package/lib/util/processAsyncTree.js +1 -1
- package/lib/util/propertyAccess.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -2
- package/lib/util/removeBOM.js +1 -1
- package/lib/util/runtime.js +29 -21
- package/lib/util/semver.js +1 -1
- package/lib/util/serialization.js +3 -0
- package/lib/util/source.js +3 -2
- package/lib/validateSchema.js +1 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +6 -3
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +46 -49
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +3 -2
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -0
- package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -22
- package/lib/webpack.js +4 -5
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -24
- package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
- package/package.json +119 -113
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +17 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
- package/types.d.ts +1230 -360
|
@@ -5,29 +5,19 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
-
const { pathToFileURL } = require("url");
|
|
9
|
-
const CommentCompilationWarning = require("../CommentCompilationWarning");
|
|
10
8
|
const {
|
|
11
9
|
JAVASCRIPT_MODULE_TYPE_AUTO,
|
|
12
10
|
JAVASCRIPT_MODULE_TYPE_ESM
|
|
13
11
|
} = require("../ModuleTypeConstants");
|
|
14
|
-
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
15
|
-
const UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning");
|
|
16
|
-
const BasicEvaluatedExpression = require("../javascript/BasicEvaluatedExpression");
|
|
17
|
-
const { approve } = require("../javascript/JavascriptParserHelpers");
|
|
18
|
-
const InnerGraph = require("../optimize/InnerGraph");
|
|
19
|
-
const ConstDependency = require("./ConstDependency");
|
|
20
|
-
const URLDependency = require("./URLDependency");
|
|
21
12
|
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
const URLContextDependency = require("../dependencies/URLContextDependency");
|
|
14
|
+
const URLDependency = require("../dependencies/URLDependency");
|
|
15
|
+
const URLParserPlugin = require("../url/URLParserPlugin");
|
|
16
|
+
|
|
24
17
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
|
25
18
|
/** @typedef {import("../Compiler")} Compiler */
|
|
26
|
-
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
|
27
|
-
/** @typedef {import("../NormalModule")} NormalModule */
|
|
28
19
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
|
29
20
|
/** @typedef {import("../javascript/JavascriptParser")} Parser */
|
|
30
|
-
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
31
21
|
|
|
32
22
|
const PLUGIN_NAME = "URLPlugin";
|
|
33
23
|
|
|
@@ -38,168 +28,38 @@ class URLPlugin {
|
|
|
38
28
|
apply(compiler) {
|
|
39
29
|
compiler.hooks.compilation.tap(
|
|
40
30
|
PLUGIN_NAME,
|
|
41
|
-
(compilation, { normalModuleFactory }) => {
|
|
31
|
+
(compilation, { normalModuleFactory, contextModuleFactory }) => {
|
|
42
32
|
compilation.dependencyFactories.set(URLDependency, normalModuleFactory);
|
|
43
33
|
compilation.dependencyTemplates.set(
|
|
44
34
|
URLDependency,
|
|
45
35
|
new URLDependency.Template()
|
|
46
36
|
);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
* @param {Parser} parser parser parser
|
|
56
|
-
* @param {MemberExpression} arg arg
|
|
57
|
-
* @returns {boolean} true when it is `meta.url`, otherwise false
|
|
58
|
-
*/
|
|
59
|
-
const isMetaUrl = (parser, arg) => {
|
|
60
|
-
const chain = parser.extractMemberExpressionChain(arg);
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
chain.members.length !== 1 ||
|
|
64
|
-
chain.object.type !== "MetaProperty" ||
|
|
65
|
-
chain.object.meta.name !== "import" ||
|
|
66
|
-
chain.object.property.name !== "meta" ||
|
|
67
|
-
chain.members[0] !== "url"
|
|
68
|
-
)
|
|
69
|
-
return false;
|
|
70
|
-
|
|
71
|
-
return true;
|
|
72
|
-
};
|
|
37
|
+
compilation.dependencyFactories.set(
|
|
38
|
+
URLContextDependency,
|
|
39
|
+
contextModuleFactory
|
|
40
|
+
);
|
|
41
|
+
compilation.dependencyTemplates.set(
|
|
42
|
+
URLContextDependency,
|
|
43
|
+
new URLContextDependency.Template()
|
|
44
|
+
);
|
|
73
45
|
|
|
74
46
|
/**
|
|
75
47
|
* @param {Parser} parser parser parser
|
|
76
48
|
* @param {JavascriptParserOptions} parserOptions parserOptions
|
|
77
49
|
* @returns {void}
|
|
78
50
|
*/
|
|
79
|
-
const
|
|
51
|
+
const handler = (parser, parserOptions) => {
|
|
80
52
|
if (parserOptions.url === false) return;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @param {NewExpressionNode} expr expression
|
|
85
|
-
* @returns {undefined | string} request
|
|
86
|
-
*/
|
|
87
|
-
const getUrlRequest = expr => {
|
|
88
|
-
if (expr.arguments.length !== 2) return;
|
|
89
|
-
|
|
90
|
-
const [arg1, arg2] = expr.arguments;
|
|
91
|
-
|
|
92
|
-
if (
|
|
93
|
-
arg2.type !== "MemberExpression" ||
|
|
94
|
-
arg1.type === "SpreadElement"
|
|
95
|
-
)
|
|
96
|
-
return;
|
|
97
|
-
|
|
98
|
-
if (!isMetaUrl(parser, arg2)) return;
|
|
99
|
-
|
|
100
|
-
return parser.evaluateExpression(arg1).asString();
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
parser.hooks.canRename.for("URL").tap(PLUGIN_NAME, approve);
|
|
104
|
-
parser.hooks.evaluateNewExpression
|
|
105
|
-
.for("URL")
|
|
106
|
-
.tap(PLUGIN_NAME, expr => {
|
|
107
|
-
const request = getUrlRequest(expr);
|
|
108
|
-
if (!request) return;
|
|
109
|
-
const url = new URL(request, getUrl(parser.state.module));
|
|
110
|
-
|
|
111
|
-
return new BasicEvaluatedExpression()
|
|
112
|
-
.setString(url.toString())
|
|
113
|
-
.setRange(/** @type {Range} */ (expr.range));
|
|
114
|
-
});
|
|
115
|
-
parser.hooks.new.for("URL").tap(PLUGIN_NAME, _expr => {
|
|
116
|
-
const expr = /** @type {NewExpressionNode} */ (_expr);
|
|
117
|
-
const { options: importOptions, errors: commentErrors } =
|
|
118
|
-
parser.parseCommentOptions(/** @type {Range} */ (expr.range));
|
|
119
|
-
|
|
120
|
-
if (commentErrors) {
|
|
121
|
-
for (const e of commentErrors) {
|
|
122
|
-
const { comment } = e;
|
|
123
|
-
parser.state.module.addWarning(
|
|
124
|
-
new CommentCompilationWarning(
|
|
125
|
-
`Compilation error while processing magic comment(-s): /*${comment.value}*/: ${e.message}`,
|
|
126
|
-
/** @type {DependencyLocation} */ (comment.loc)
|
|
127
|
-
)
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (importOptions && importOptions.webpackIgnore !== undefined) {
|
|
133
|
-
if (typeof importOptions.webpackIgnore !== "boolean") {
|
|
134
|
-
parser.state.module.addWarning(
|
|
135
|
-
new UnsupportedFeatureWarning(
|
|
136
|
-
`\`webpackIgnore\` expected a boolean, but received: ${importOptions.webpackIgnore}.`,
|
|
137
|
-
/** @type {DependencyLocation} */ (expr.loc)
|
|
138
|
-
)
|
|
139
|
-
);
|
|
140
|
-
return;
|
|
141
|
-
} else if (importOptions.webpackIgnore) {
|
|
142
|
-
if (expr.arguments.length !== 2) return;
|
|
143
|
-
|
|
144
|
-
const [, arg2] = expr.arguments;
|
|
145
|
-
|
|
146
|
-
if (
|
|
147
|
-
arg2.type !== "MemberExpression" ||
|
|
148
|
-
!isMetaUrl(parser, arg2)
|
|
149
|
-
)
|
|
150
|
-
return;
|
|
151
|
-
|
|
152
|
-
const dep = new ConstDependency(
|
|
153
|
-
RuntimeGlobals.baseURI,
|
|
154
|
-
/** @type {Range} */ (arg2.range),
|
|
155
|
-
[RuntimeGlobals.baseURI]
|
|
156
|
-
);
|
|
157
|
-
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
|
158
|
-
parser.state.module.addPresentationalDependency(dep);
|
|
159
|
-
|
|
160
|
-
return true;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const request = getUrlRequest(expr);
|
|
165
|
-
|
|
166
|
-
if (!request) return;
|
|
167
|
-
|
|
168
|
-
const [arg1, arg2] = expr.arguments;
|
|
169
|
-
const dep = new URLDependency(
|
|
170
|
-
request,
|
|
171
|
-
[
|
|
172
|
-
/** @type {Range} */ (arg1.range)[0],
|
|
173
|
-
/** @type {Range} */ (arg2.range)[1]
|
|
174
|
-
],
|
|
175
|
-
/** @type {Range} */ (expr.range),
|
|
176
|
-
relative
|
|
177
|
-
);
|
|
178
|
-
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
|
179
|
-
parser.state.current.addDependency(dep);
|
|
180
|
-
InnerGraph.onUsage(parser.state, e => (dep.usedByExports = e));
|
|
181
|
-
return true;
|
|
182
|
-
});
|
|
183
|
-
parser.hooks.isPure.for("NewExpression").tap(PLUGIN_NAME, _expr => {
|
|
184
|
-
const expr = /** @type {NewExpressionNode} */ (_expr);
|
|
185
|
-
const { callee } = expr;
|
|
186
|
-
if (callee.type !== "Identifier") return;
|
|
187
|
-
const calleeInfo = parser.getFreeInfoFromVariable(callee.name);
|
|
188
|
-
if (!calleeInfo || calleeInfo.name !== "URL") return;
|
|
189
|
-
|
|
190
|
-
const request = getUrlRequest(expr);
|
|
191
|
-
|
|
192
|
-
if (request) return true;
|
|
193
|
-
});
|
|
53
|
+
new URLParserPlugin(parserOptions).apply(parser);
|
|
194
54
|
};
|
|
195
55
|
|
|
196
56
|
normalModuleFactory.hooks.parser
|
|
197
57
|
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
|
|
198
|
-
.tap(PLUGIN_NAME,
|
|
58
|
+
.tap(PLUGIN_NAME, handler);
|
|
199
59
|
|
|
200
60
|
normalModuleFactory.hooks.parser
|
|
201
61
|
.for(JAVASCRIPT_MODULE_TYPE_ESM)
|
|
202
|
-
.tap(PLUGIN_NAME,
|
|
62
|
+
.tap(PLUGIN_NAME, handler);
|
|
203
63
|
}
|
|
204
64
|
);
|
|
205
65
|
}
|
|
@@ -122,8 +122,9 @@ class WorkerPlugin {
|
|
|
122
122
|
* @returns {[string, Range] | void} parsed
|
|
123
123
|
*/
|
|
124
124
|
const parseModuleUrl = (parser, expr) => {
|
|
125
|
-
if (expr.type !== "NewExpression" || expr.callee.type === "Super")
|
|
125
|
+
if (expr.type !== "NewExpression" || expr.callee.type === "Super") {
|
|
126
126
|
return;
|
|
127
|
+
}
|
|
127
128
|
if (
|
|
128
129
|
expr.arguments.length === 1 &&
|
|
129
130
|
expr.arguments[0].type === "MemberExpression" &&
|
|
@@ -179,8 +180,9 @@ class WorkerPlugin {
|
|
|
179
180
|
chain.object.meta.name !== "import" ||
|
|
180
181
|
chain.object.property.name !== "meta" ||
|
|
181
182
|
chain.members[0] !== "url"
|
|
182
|
-
)
|
|
183
|
+
) {
|
|
183
184
|
return false;
|
|
185
|
+
}
|
|
184
186
|
|
|
185
187
|
return true;
|
|
186
188
|
};
|
|
@@ -215,8 +217,9 @@ class WorkerPlugin {
|
|
|
215
217
|
/** @type {Expression} */
|
|
216
218
|
(prop.value)
|
|
217
219
|
);
|
|
218
|
-
if (value.isCompileTimeValue())
|
|
220
|
+
if (value.isCompileTimeValue()) {
|
|
219
221
|
values[prop.key.name] = value.asCompileTimeValue();
|
|
222
|
+
}
|
|
220
223
|
}
|
|
221
224
|
} else {
|
|
222
225
|
otherElements.push(prop);
|
|
@@ -251,8 +254,9 @@ class WorkerPlugin {
|
|
|
251
254
|
* @returns {boolean | void} true when handled
|
|
252
255
|
*/
|
|
253
256
|
const handleNewWorker = expr => {
|
|
254
|
-
if (expr.arguments.length === 0 || expr.arguments.length > 2)
|
|
257
|
+
if (expr.arguments.length === 0 || expr.arguments.length > 2) {
|
|
255
258
|
return;
|
|
259
|
+
}
|
|
256
260
|
const [arg1, arg2] = expr.arguments;
|
|
257
261
|
if (arg1.type === "SpreadElement") return;
|
|
258
262
|
if (arg2 && arg2.type === "SpreadElement") return;
|
|
@@ -489,12 +493,18 @@ class WorkerPlugin {
|
|
|
489
493
|
const pattern = item.slice(1, firstDot);
|
|
490
494
|
const itemMembers = item.slice(firstDot + 1, -2);
|
|
491
495
|
|
|
492
|
-
parser.hooks.preDeclarator.tap(
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
+
parser.hooks.preDeclarator.tap(
|
|
497
|
+
PLUGIN_NAME,
|
|
498
|
+
(decl, _statement) => {
|
|
499
|
+
if (
|
|
500
|
+
decl.id.type === "Identifier" &&
|
|
501
|
+
decl.id.name === pattern
|
|
502
|
+
) {
|
|
503
|
+
parser.tagVariable(decl.id.name, WorkerSpecifierTag);
|
|
504
|
+
return true;
|
|
505
|
+
}
|
|
496
506
|
}
|
|
497
|
-
|
|
507
|
+
);
|
|
498
508
|
parser.hooks.pattern.for(pattern).tap(PLUGIN_NAME, pattern => {
|
|
499
509
|
parser.tagVariable(pattern.name, WorkerSpecifierTag);
|
|
500
510
|
return true;
|
|
@@ -543,7 +553,9 @@ class WorkerPlugin {
|
|
|
543
553
|
for (const itemFromDefault of DEFAULT_SYNTAX) {
|
|
544
554
|
processItem(itemFromDefault);
|
|
545
555
|
}
|
|
546
|
-
} else
|
|
556
|
+
} else {
|
|
557
|
+
processItem(item);
|
|
558
|
+
}
|
|
547
559
|
}
|
|
548
560
|
};
|
|
549
561
|
normalModuleFactory.hooks.parser
|
|
@@ -556,4 +568,5 @@ class WorkerPlugin {
|
|
|
556
568
|
);
|
|
557
569
|
}
|
|
558
570
|
}
|
|
571
|
+
|
|
559
572
|
module.exports = WorkerPlugin;
|
|
@@ -56,7 +56,7 @@ const processExportInfo = (
|
|
|
56
56
|
referencedExports,
|
|
57
57
|
defaultPointsToSelf && exportInfo.name === "default"
|
|
58
58
|
? prefix
|
|
59
|
-
: prefix
|
|
59
|
+
: [...prefix, exportInfo.name],
|
|
60
60
|
exportInfo,
|
|
61
61
|
false,
|
|
62
62
|
alreadyVisited
|
|
@@ -64,4 +64,5 @@ const processExportInfo = (
|
|
|
64
64
|
}
|
|
65
65
|
alreadyVisited.delete(exportInfo);
|
|
66
66
|
};
|
|
67
|
+
|
|
67
68
|
module.exports = processExportInfo;
|