webpack 5.106.2 → 5.107.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/README.md +2 -2
- package/lib/APIPlugin.js +1 -1
- package/lib/Cache.js +3 -6
- package/lib/CompatibilityPlugin.js +8 -7
- package/lib/Compilation.js +34 -26
- package/lib/Compiler.js +4 -13
- package/lib/ContextModule.js +2 -2
- package/lib/DefinePlugin.js +2 -2
- package/lib/Dependency.js +22 -1
- package/lib/DependencyTemplate.js +2 -1
- package/lib/EnvironmentPlugin.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +8 -9
- package/lib/ExternalModule.js +76 -15
- package/lib/ExternalModuleFactoryPlugin.js +5 -0
- package/lib/FileSystemInfo.js +187 -72
- package/lib/Generator.js +3 -3
- package/lib/HotModuleReplacementPlugin.js +26 -8
- package/lib/IgnorePlugin.js +2 -1
- package/lib/Module.js +19 -18
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleSourceTypeConstants.js +31 -1
- package/lib/ModuleTypeConstants.js +12 -3
- package/lib/MultiCompiler.js +2 -2
- package/lib/NodeStuffPlugin.js +1 -1
- package/lib/NormalModule.js +13 -31
- package/lib/NormalModuleFactory.js +10 -2
- package/lib/Parser.js +1 -1
- package/lib/ProgressPlugin.js +129 -56
- package/lib/RuntimeGlobals.js +5 -5
- package/lib/RuntimeModule.js +9 -7
- package/lib/RuntimePlugin.js +11 -0
- package/lib/WarnCaseSensitiveModulesPlugin.js +70 -2
- package/lib/WarnDeprecatedOptionPlugin.js +1 -1
- package/lib/WarnNoModeSetPlugin.js +16 -1
- package/lib/Watching.js +2 -3
- package/lib/WebpackError.js +3 -77
- package/lib/WebpackIsIncludedPlugin.js +1 -1
- package/lib/WebpackOptionsApply.js +13 -1
- package/lib/asset/AssetBytesGenerator.js +6 -2
- package/lib/asset/AssetGenerator.js +22 -8
- package/lib/asset/AssetModulesPlugin.js +3 -1
- package/lib/asset/AssetSourceGenerator.js +6 -2
- package/lib/buildChunkGraph.js +4 -6
- package/lib/cache/PackFileCacheStrategy.js +4 -4
- package/lib/cli.js +3 -1
- package/lib/config/defaults.js +197 -10
- package/lib/config/normalization.js +3 -1
- package/lib/css/CssGenerator.js +320 -105
- package/lib/css/CssInjectStyleRuntimeModule.js +44 -42
- package/lib/css/CssLoadingRuntimeModule.js +22 -4
- package/lib/{CssModule.js → css/CssModule.js} +15 -15
- package/lib/css/CssModulesPlugin.js +166 -86
- package/lib/css/CssParser.js +566 -269
- package/lib/css/walkCssTokens.js +148 -2
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +63 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +54 -10
- package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -1
- package/lib/dependencies/CommonJsFullRequireDependency.js +32 -9
- package/lib/dependencies/CommonJsImportsParserPlugin.js +4 -3
- package/lib/dependencies/CommonJsRequireDependency.js +67 -4
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +1 -1
- package/lib/dependencies/CreateRequireParserPlugin.js +1 -1
- package/lib/dependencies/CriticalDependencyWarning.js +1 -1
- package/lib/dependencies/CssIcssExportDependency.js +332 -67
- package/lib/dependencies/CssIcssImportDependency.js +49 -7
- package/lib/dependencies/CssIcssSymbolDependency.js +11 -3
- package/lib/dependencies/CssImportDependency.js +8 -0
- package/lib/dependencies/CssUrlDependency.js +25 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +8 -7
- package/lib/dependencies/HarmonyExportExpressionDependency.js +22 -14
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +110 -3
- package/lib/dependencies/HarmonyImportDependency.js +10 -2
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +22 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +1 -1
- package/lib/{HarmonyLinkingError.js → dependencies/HarmonyLinkingError.js} +5 -3
- package/lib/dependencies/HtmlInlineScriptDependency.js +133 -0
- package/lib/dependencies/HtmlInlineStyleDependency.js +101 -0
- package/lib/dependencies/HtmlScriptSrcDependency.js +318 -0
- package/lib/dependencies/HtmlSourceDependency.js +127 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +2 -2
- package/lib/dependencies/ImportPhase.js +1 -1
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +1 -1
- package/lib/{RequireJsStuffPlugin.js → dependencies/RequireJsStuffPlugin.js} +7 -7
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/{DelegatedModule.js → dll/DelegatedModule.js} +31 -31
- package/lib/{DelegatedModuleFactoryPlugin.js → dll/DelegatedModuleFactoryPlugin.js} +4 -4
- package/lib/{DelegatedPlugin.js → dll/DelegatedPlugin.js} +2 -2
- package/lib/{DllEntryPlugin.js → dll/DllEntryPlugin.js} +4 -4
- package/lib/{DllModule.js → dll/DllModule.js} +24 -24
- package/lib/{DllModuleFactory.js → dll/DllModuleFactory.js} +4 -4
- package/lib/{DllPlugin.js → dll/DllPlugin.js} +6 -5
- package/lib/{DllReferencePlugin.js → dll/DllReferencePlugin.js} +14 -14
- package/lib/{LibManifestPlugin.js → dll/LibManifestPlugin.js} +9 -9
- package/lib/{AsyncDependencyToInitialChunkError.js → errors/AsyncDependencyToInitialChunkError.js} +2 -2
- package/lib/errors/BuildCycleError.js +1 -1
- package/lib/{ChunkRenderError.js → errors/ChunkRenderError.js} +1 -1
- package/lib/{CodeGenerationError.js → errors/CodeGenerationError.js} +1 -1
- package/lib/{CommentCompilationWarning.js → errors/CommentCompilationWarning.js} +3 -3
- package/lib/{ConcurrentCompilationError.js → errors/ConcurrentCompilationError.js} +4 -2
- package/lib/{EnvironmentNotSupportAsyncWarning.js → errors/EnvironmentNotSupportAsyncWarning.js} +4 -4
- package/lib/{HookWebpackError.js → errors/HookWebpackError.js} +5 -5
- package/lib/{IgnoreErrorModuleFactory.js → errors/IgnoreErrorModuleFactory.js} +4 -4
- package/lib/{InvalidDependenciesModuleWarning.js → errors/InvalidDependenciesModuleWarning.js} +3 -3
- package/lib/errors/JSONParseError.js +114 -0
- package/lib/{ModuleBuildError.js → errors/ModuleBuildError.js} +5 -5
- package/lib/{ModuleDependencyError.js → errors/ModuleDependencyError.js} +2 -2
- package/lib/{ModuleDependencyWarning.js → errors/ModuleDependencyWarning.js} +4 -4
- package/lib/{ModuleError.js → errors/ModuleError.js} +5 -5
- package/lib/{ModuleHashingError.js → errors/ModuleHashingError.js} +1 -1
- package/lib/{ModuleNotFoundError.js → errors/ModuleNotFoundError.js} +2 -2
- package/lib/{ModuleParseError.js → errors/ModuleParseError.js} +8 -6
- package/lib/{ModuleRestoreError.js → errors/ModuleRestoreError.js} +1 -1
- package/lib/{ModuleStoreError.js → errors/ModuleStoreError.js} +1 -1
- package/lib/{ModuleWarning.js → errors/ModuleWarning.js} +5 -5
- package/lib/{NodeStuffInWebError.js → errors/NodeStuffInWebError.js} +4 -4
- package/lib/errors/NonErrorEmittedError.js +28 -0
- package/lib/{UnhandledSchemeError.js → errors/UnhandledSchemeError.js} +2 -2
- package/lib/{UnsupportedFeatureWarning.js → errors/UnsupportedFeatureWarning.js} +3 -3
- package/lib/errors/WebpackError.js +84 -0
- package/lib/html/HtmlGenerator.js +379 -0
- package/lib/html/HtmlModulesPlugin.js +433 -0
- package/lib/html/HtmlParser.js +1489 -0
- package/lib/html/walkHtmlTokens.js +2733 -0
- package/lib/ids/IdHelpers.js +2 -1
- package/lib/index.js +34 -15
- package/lib/javascript/JavascriptModulesPlugin.js +89 -8
- package/lib/javascript/JavascriptParser.js +197 -16
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/json/JsonParser.js +7 -16
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/EnableLibraryPlugin.js +1 -1
- package/lib/{FalseIIFEUmdWarning.js → library/FalseIIFEUmdWarning.js} +1 -1
- package/lib/library/ModuleLibraryPlugin.js +74 -0
- package/lib/node/NodeEnvironmentPlugin.js +4 -2
- package/lib/node/nodeConsole.js +113 -64
- package/lib/optimize/ConcatenatedModule.js +51 -6
- package/lib/optimize/InnerGraph.js +1 -1
- package/lib/optimize/InnerGraphPlugin.js +11 -1
- package/lib/optimize/MinMaxSizeWarning.js +4 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +15 -7
- package/lib/optimize/RealContentHashPlugin.js +89 -26
- package/lib/optimize/SideEffectsFlagPlugin.js +111 -3
- package/lib/optimize/SplitChunksPlugin.js +1 -1
- package/lib/performance/AssetsOverSizeLimitWarning.js +2 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
- package/lib/performance/NoAsyncChunksWarning.js +5 -3
- package/lib/performance/SizeLimitsPlugin.js +1 -1
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -1
- package/lib/rules/UseEffectRulePlugin.js +4 -3
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +119 -13
- package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +35 -0
- package/lib/schemes/DataUriPlugin.js +13 -1
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/sharing/ConsumeSharedPlugin.js +2 -2
- package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +2 -2
- package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +1 -1
- package/lib/typescript/TypeScriptPlugin.js +210 -0
- package/lib/url/URLParserPlugin.js +2 -2
- package/lib/util/AsyncQueue.js +2 -2
- package/lib/util/Hash.js +2 -2
- package/lib/util/LocConverter.js +53 -0
- package/lib/util/SortableSet.js +1 -1
- package/lib/util/cleverMerge.js +2 -2
- package/lib/util/comparators.js +3 -3
- package/lib/util/concatenate.js +3 -3
- package/lib/util/conventions.js +42 -1
- package/lib/util/createMappings.js +118 -0
- package/lib/{formatLocation.js → util/formatLocation.js} +2 -2
- package/lib/{SizeFormatHelpers.js → util/formatSize.js} +3 -1
- package/lib/util/fs.js +8 -8
- package/lib/util/hash/md4.js +1 -1
- package/lib/util/hash/xxhash64.js +1 -1
- package/lib/util/identifier.js +48 -0
- package/lib/util/internalSerializables.js +35 -19
- package/lib/util/magicComment.js +10 -7
- package/lib/util/parseJson.js +2 -73
- package/lib/util/source.js +21 -0
- package/lib/util/topologicalSort.js +69 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -3
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +5 -3
- package/lib/webpack.js +3 -1
- package/package.json +22 -20
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +118 -3
- package/schemas/plugins/{DllPlugin.check.d.ts → HtmlGeneratorOptions.check.d.ts} +1 -1
- package/schemas/plugins/HtmlGeneratorOptions.check.js +6 -0
- package/schemas/plugins/HtmlGeneratorOptions.json +3 -0
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.json +22 -0
- package/schemas/plugins/{DllReferencePlugin.check.d.ts → css/CssAutoOrModuleParserOptions.check.d.ts} +1 -1
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.json +3 -0
- package/schemas/plugins/dll/DllPlugin.check.d.ts +7 -0
- package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +7 -0
- package/types.d.ts +810 -101
- package/lib/CaseSensitiveModulesWarning.js +0 -80
- package/lib/GraphHelpers.js +0 -49
- package/lib/NoModeWarning.js +0 -23
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +0 -57
- /package/lib/{AbstractMethodError.js → errors/AbstractMethodError.js} +0 -0
- /package/schemas/plugins/{DllPlugin.check.js → dll/DllPlugin.check.js} +0 -0
- /package/schemas/plugins/{DllPlugin.json → dll/DllPlugin.json} +0 -0
- /package/schemas/plugins/{DllReferencePlugin.check.js → dll/DllReferencePlugin.check.js} +0 -0
- /package/schemas/plugins/{DllReferencePlugin.json → dll/DllReferencePlugin.json} +0 -0
|
@@ -30,13 +30,15 @@ class CssIcssSymbolDependency extends NullDependency {
|
|
|
30
30
|
* @param {Range} range range
|
|
31
31
|
* @param {string=} value value when it was defined in this module
|
|
32
32
|
* @param {string=} importName import name when it was imported from other module
|
|
33
|
+
* @param {string=} request request of the `@value` import that was active when this reference was parsed — used to disambiguate when the same local name is imported from multiple modules
|
|
33
34
|
*/
|
|
34
|
-
constructor(localName, range, value, importName) {
|
|
35
|
+
constructor(localName, range, value, importName, request) {
|
|
35
36
|
super();
|
|
36
37
|
this.localName = localName;
|
|
37
38
|
this.range = range;
|
|
38
39
|
this.value = value;
|
|
39
40
|
this.importName = importName;
|
|
41
|
+
this.request = request;
|
|
40
42
|
/** @type {undefined | string} */
|
|
41
43
|
this._hashUpdate = undefined;
|
|
42
44
|
}
|
|
@@ -53,7 +55,10 @@ class CssIcssSymbolDependency extends NullDependency {
|
|
|
53
55
|
*/
|
|
54
56
|
updateHash(hash, context) {
|
|
55
57
|
if (this._hashUpdate === undefined) {
|
|
56
|
-
|
|
58
|
+
// Concatenate with explicit field separators so adjacent fields
|
|
59
|
+
// can't alias each other (e.g. range `[1,11]` + localName `"foo"`
|
|
60
|
+
// vs range `[1,1]` + localName `"1foo"`).
|
|
61
|
+
this._hashUpdate = `range|${JSON.stringify(this.range)}|localName|${this.localName}|value|${this.value || ""}|importName|${this.importName || ""}|request|${this.request || ""}`;
|
|
57
62
|
}
|
|
58
63
|
hash.update(this._hashUpdate);
|
|
59
64
|
}
|
|
@@ -68,6 +73,7 @@ class CssIcssSymbolDependency extends NullDependency {
|
|
|
68
73
|
write(this.range);
|
|
69
74
|
write(this.value);
|
|
70
75
|
write(this.importName);
|
|
76
|
+
write(this.request);
|
|
71
77
|
super.serialize(context);
|
|
72
78
|
}
|
|
73
79
|
|
|
@@ -81,6 +87,7 @@ class CssIcssSymbolDependency extends NullDependency {
|
|
|
81
87
|
this.range = read();
|
|
82
88
|
this.value = read();
|
|
83
89
|
this.importName = read();
|
|
90
|
+
this.request = read();
|
|
84
91
|
super.deserialize(context);
|
|
85
92
|
}
|
|
86
93
|
}
|
|
@@ -103,7 +110,8 @@ CssIcssSymbolDependency.Template = class CssIcssSymbolDependencyTemplate extends
|
|
|
103
110
|
? CssIcssExportDependency.Template.resolve(
|
|
104
111
|
dep.localName,
|
|
105
112
|
dep.importName,
|
|
106
|
-
templateContext
|
|
113
|
+
templateContext,
|
|
114
|
+
dep.request
|
|
107
115
|
)
|
|
108
116
|
: dep.value;
|
|
109
117
|
|
|
@@ -43,6 +43,14 @@ class CssImportDependency extends ModuleDependency {
|
|
|
43
43
|
return `css-import${this.mode ? `-${this.mode}-module` : ""}`;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Returns true if this dependency can be concatenated
|
|
48
|
+
* @returns {boolean} true if this dependency can be concatenated
|
|
49
|
+
*/
|
|
50
|
+
canConcatenate() {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
46
54
|
/**
|
|
47
55
|
* Returns an identifier to merge equal requests.
|
|
48
56
|
* @returns {string | null} an identifier to merge equal requests
|
|
@@ -12,14 +12,17 @@ const ModuleDependency = require("./ModuleDependency");
|
|
|
12
12
|
|
|
13
13
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
14
14
|
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
|
|
15
|
+
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
|
15
16
|
/** @typedef {import("../Dependency")} Dependency */
|
|
16
17
|
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
|
17
18
|
/** @typedef {import("../Module")} Module */
|
|
19
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
|
18
20
|
/** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
|
|
19
21
|
/** @typedef {import("../Module").CodeGenerationResultData} CodeGenerationResultData */
|
|
20
22
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
21
23
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
22
24
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
25
|
+
/** @typedef {import("../util/Hash")} Hash */
|
|
23
26
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
24
27
|
|
|
25
28
|
const getIgnoredRawDataUrlModule = memoize(
|
|
@@ -56,6 +59,27 @@ class CssUrlDependency extends ModuleDependency {
|
|
|
56
59
|
return getIgnoredRawDataUrlModule();
|
|
57
60
|
}
|
|
58
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Updates the hash with the data contributed by this instance.
|
|
64
|
+
* @param {Hash} hash hash to be updated
|
|
65
|
+
* @param {UpdateHashContext} context context
|
|
66
|
+
* @returns {void}
|
|
67
|
+
*/
|
|
68
|
+
updateHash(hash, context) {
|
|
69
|
+
// The dependency template substitutes the referenced asset's hashed
|
|
70
|
+
// filename into the rendered CSS at code-generation time. Folding the
|
|
71
|
+
// asset module's content hash into the dependency hash ensures the
|
|
72
|
+
// CSS module's hash invalidates — and the CSS chunk's contenthash
|
|
73
|
+
// updates — whenever the referenced asset's content changes.
|
|
74
|
+
const { chunkGraph } = context;
|
|
75
|
+
const module = chunkGraph.moduleGraph.getModule(this);
|
|
76
|
+
if (!module) return;
|
|
77
|
+
const buildInfo = /** @type {BuildInfo | undefined} */ (module.buildInfo);
|
|
78
|
+
if (buildInfo && buildInfo.hash) {
|
|
79
|
+
hash.update(/** @type {string} */ (buildInfo.hash));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
59
83
|
/**
|
|
60
84
|
* Serializes this instance into the provided serializer context.
|
|
61
85
|
* @param {ObjectSerializerContext} context context
|
|
@@ -192,5 +216,6 @@ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
|
|
|
192
216
|
makeSerializable(CssUrlDependency, "webpack/lib/dependencies/CssUrlDependency");
|
|
193
217
|
|
|
194
218
|
CssUrlDependency.PUBLIC_PATH_AUTO = "__WEBPACK_CSS_PUBLIC_PATH_AUTO__";
|
|
219
|
+
CssUrlDependency.PUBLIC_PATH_FULL_HASH = "__WEBPACK_CSS_PUBLIC_PATH_FULL_HASH_";
|
|
195
220
|
|
|
196
221
|
module.exports = CssUrlDependency;
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
-
const EnvironmentNotSupportAsyncWarning = require("../EnvironmentNotSupportAsyncWarning");
|
|
9
8
|
const { JAVASCRIPT_MODULE_TYPE_ESM } = require("../ModuleTypeConstants");
|
|
9
|
+
const EnvironmentNotSupportAsyncWarning = require("../errors/EnvironmentNotSupportAsyncWarning");
|
|
10
10
|
const DynamicExports = require("./DynamicExports");
|
|
11
11
|
const HarmonyCompatibilityDependency = require("./HarmonyCompatibilityDependency");
|
|
12
12
|
const HarmonyExports = require("./HarmonyExports");
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const CompatibilityPlugin = require("../CompatibilityPlugin");
|
|
9
|
-
const WebpackError = require("../WebpackError");
|
|
9
|
+
const WebpackError = require("../errors/WebpackError");
|
|
10
10
|
const { getImportAttributes } = require("../javascript/JavascriptParser");
|
|
11
11
|
const InnerGraph = require("../optimize/InnerGraph");
|
|
12
12
|
const ConstDependency = require("./ConstDependency");
|
|
@@ -144,12 +144,13 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
144
144
|
: undefined
|
|
145
145
|
);
|
|
146
146
|
dep.isAnonymousDefault =
|
|
147
|
-
|
|
148
|
-
(
|
|
149
|
-
node.type === "
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
147
|
+
this.options.anonymousDefaultExportName !== false &&
|
|
148
|
+
(node.type === "ArrowFunctionExpression" ||
|
|
149
|
+
((node.type === "FunctionDeclaration" ||
|
|
150
|
+
node.type === "FunctionExpression" ||
|
|
151
|
+
node.type === "ClassDeclaration" ||
|
|
152
|
+
node.type === "ClassExpression") &&
|
|
153
|
+
!node.id));
|
|
153
154
|
dep.loc = Object.create(
|
|
154
155
|
/** @type {DependencyLocation} */ (statement.loc)
|
|
155
156
|
);
|
|
@@ -143,18 +143,17 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
|
|
|
143
143
|
);
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
+
const used = concatenationScope
|
|
147
|
+
? undefined
|
|
148
|
+
: moduleGraph.getExportsInfo(module).getUsedName("default", runtime);
|
|
149
|
+
|
|
146
150
|
if (concatenationScope) {
|
|
147
151
|
concatenationScope.registerExport("default", name);
|
|
148
|
-
} else {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
/** @type {ExportMap} */
|
|
154
|
-
const map = new Map();
|
|
155
|
-
map.set(used, `/* export default binding */ ${name}`);
|
|
156
|
-
initFragments.push(new HarmonyExportInitFragment(exportsName, map));
|
|
157
|
-
}
|
|
152
|
+
} else if (used) {
|
|
153
|
+
/** @type {ExportMap} */
|
|
154
|
+
const map = new Map();
|
|
155
|
+
map.set(used, `/* export default binding */ ${name}`);
|
|
156
|
+
initFragments.push(new HarmonyExportInitFragment(exportsName, map));
|
|
158
157
|
}
|
|
159
158
|
|
|
160
159
|
source.replace(
|
|
@@ -163,12 +162,17 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
|
|
|
163
162
|
`/* harmony default export */ ${dep.prefix}`
|
|
164
163
|
);
|
|
165
164
|
|
|
166
|
-
if (
|
|
165
|
+
if (
|
|
166
|
+
typeof declarationId !== "string" &&
|
|
167
|
+
dep.isAnonymousDefault &&
|
|
168
|
+
(concatenationScope || used)
|
|
169
|
+
) {
|
|
167
170
|
// Fix .name for anonymous default export function declarations
|
|
168
171
|
// see test/test262-cases/test/language/module-code/instn-named-bndng-dflt-fun-anon.js cspell:disable-line
|
|
172
|
+
runtimeRequirements.add(RuntimeGlobals.setAnonymousDefaultName);
|
|
169
173
|
initFragments.push(
|
|
170
174
|
new InitFragment(
|
|
171
|
-
|
|
175
|
+
`${RuntimeGlobals.setAnonymousDefaultName}(${name});\n`,
|
|
172
176
|
InitFragment.STAGE_HARMONY_EXPORTS,
|
|
173
177
|
2
|
|
174
178
|
)
|
|
@@ -178,6 +182,7 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
|
|
|
178
182
|
/** @type {string} */
|
|
179
183
|
let content;
|
|
180
184
|
let name = ConcatenationScope.DEFAULT_EXPORT;
|
|
185
|
+
let defaultIsUsed = Boolean(concatenationScope);
|
|
181
186
|
if (runtimeTemplate.supportsConst()) {
|
|
182
187
|
content = `/* harmony default export */ const ${name} = `;
|
|
183
188
|
if (concatenationScope) {
|
|
@@ -187,6 +192,7 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
|
|
|
187
192
|
.getExportsInfo(module)
|
|
188
193
|
.getUsedName("default", runtime);
|
|
189
194
|
if (used) {
|
|
195
|
+
defaultIsUsed = true;
|
|
190
196
|
runtimeRequirements.add(RuntimeGlobals.exports);
|
|
191
197
|
/** @type {ExportMap} */
|
|
192
198
|
const map = new Map();
|
|
@@ -204,6 +210,7 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
|
|
|
204
210
|
.getExportsInfo(module)
|
|
205
211
|
.getUsedName("default", runtime);
|
|
206
212
|
if (used) {
|
|
213
|
+
defaultIsUsed = true;
|
|
207
214
|
runtimeRequirements.add(RuntimeGlobals.exports);
|
|
208
215
|
// This is a little bit incorrect as TDZ is not correct, but we can't use const.
|
|
209
216
|
// No local `__WEBPACK_DEFAULT_EXPORT__` binding is created in this path,
|
|
@@ -224,13 +231,14 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
|
|
|
224
231
|
dep.range[0] - 1,
|
|
225
232
|
`${content}(${dep.prefix}`
|
|
226
233
|
);
|
|
227
|
-
if (dep.isAnonymousDefault) {
|
|
234
|
+
if (dep.isAnonymousDefault && defaultIsUsed) {
|
|
228
235
|
// Fix .name for anonymous default export expressions
|
|
229
236
|
// see test/test262-cases/test/language/module-code/eval-export-dflt-cls-anon.js cspell:disable-line
|
|
237
|
+
runtimeRequirements.add(RuntimeGlobals.setAnonymousDefaultName);
|
|
230
238
|
source.replace(
|
|
231
239
|
dep.range[1],
|
|
232
240
|
dep.rangeStatement[1] - 0.5,
|
|
233
|
-
`);\n
|
|
241
|
+
`);\n${RuntimeGlobals.setAnonymousDefaultName}(${name});`
|
|
234
242
|
);
|
|
235
243
|
} else {
|
|
236
244
|
source.replace(dep.range[1], dep.rangeStatement[1] - 0.5, ");");
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
const ConditionalInitFragment = require("../ConditionalInitFragment");
|
|
9
9
|
const Dependency = require("../Dependency");
|
|
10
10
|
const { UsageState } = require("../ExportsInfo");
|
|
11
|
-
const HarmonyLinkingError = require("../HarmonyLinkingError");
|
|
12
11
|
const InitFragment = require("../InitFragment");
|
|
13
12
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
14
13
|
const Template = require("../Template");
|
|
@@ -26,6 +25,7 @@ const {
|
|
|
26
25
|
} = require("../util/runtime");
|
|
27
26
|
const HarmonyExportInitFragment = require("./HarmonyExportInitFragment");
|
|
28
27
|
const HarmonyImportDependency = require("./HarmonyImportDependency");
|
|
28
|
+
const HarmonyLinkingError = require("./HarmonyLinkingError");
|
|
29
29
|
const { ImportPhaseUtils } = require("./ImportPhase");
|
|
30
30
|
const processExportInfo = require("./processExportInfo");
|
|
31
31
|
|
|
@@ -50,7 +50,7 @@ const processExportInfo = require("./processExportInfo");
|
|
|
50
50
|
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
|
51
51
|
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
|
52
52
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
|
53
|
-
/** @typedef {import("../WebpackError")} WebpackError */
|
|
53
|
+
/** @typedef {import("../errors/WebpackError")} WebpackError */
|
|
54
54
|
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
|
55
55
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
56
56
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
@@ -128,6 +128,79 @@ class ExportMode {
|
|
|
128
128
|
|
|
129
129
|
/** @typedef {number[]} DependencyIndices */
|
|
130
130
|
|
|
131
|
+
const RETURNS_TRUE = () => true;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Detect a per-name cycle when collecting `export *` contributions from
|
|
135
|
+
* `exportInfo`'s module into `parentModule`. The TC39 `ResolveExport`
|
|
136
|
+
* algorithm tracks a `resolveSet` of `(module, exportName)` pairs and
|
|
137
|
+
* returns null when an entry is revisited — letting the `StarExportEntries`
|
|
138
|
+
* loop fall through to a non-cyclic source. Webpack's static export graph
|
|
139
|
+
* does not run that resolution algorithm, so we approximate it: if the
|
|
140
|
+
* imported module's same-named export ultimately re-exports from
|
|
141
|
+
* `parentModule` under the same name, the star contribution is cyclic and
|
|
142
|
+
* must be skipped. The non-cyclic alternative (a sibling `export *` that
|
|
143
|
+
* provides a real binding) then wins.
|
|
144
|
+
*
|
|
145
|
+
* We walk the target chain one hop at a time using `findTarget` with a
|
|
146
|
+
* "match anything" filter so we can guard against namespace targets
|
|
147
|
+
* (`export * as ns from`, where `target.export` is undefined) and against
|
|
148
|
+
* unrelated cycles in the graph that would otherwise loop forever inside
|
|
149
|
+
* `_findTarget`.
|
|
150
|
+
* @param {ModuleGraph} moduleGraph the module graph
|
|
151
|
+
* @param {ExportInfo} exportInfo export info on the imported module
|
|
152
|
+
* @param {Module} parentModule the module that contains the star reexport
|
|
153
|
+
* @returns {boolean} true when this export reexports back to the parent module under the same name
|
|
154
|
+
*/
|
|
155
|
+
const isStarReexportBackToParent = (moduleGraph, exportInfo, parentModule) => {
|
|
156
|
+
// Fast path: probe the first hop directly. The overwhelmingly common case
|
|
157
|
+
// in real builds is a terminal local binding (no `_target`) — `findTarget`
|
|
158
|
+
// returns `undefined` and we exit without allocating a `visited` set.
|
|
159
|
+
const firstTarget = exportInfo.findTarget(moduleGraph, RETURNS_TRUE);
|
|
160
|
+
if (!firstTarget || typeof firstTarget !== "object") return false;
|
|
161
|
+
const name = exportInfo.name;
|
|
162
|
+
if (
|
|
163
|
+
firstTarget.module === parentModule &&
|
|
164
|
+
Array.isArray(firstTarget.export) &&
|
|
165
|
+
firstTarget.export.length === 1 &&
|
|
166
|
+
firstTarget.export[0] === name
|
|
167
|
+
) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
if (!Array.isArray(firstTarget.export) || firstTarget.export.length === 0) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
// Multi-hop chain — allocate visited tracking now. The set protects against
|
|
174
|
+
// unrelated cycles in the graph that would otherwise spin inside
|
|
175
|
+
// `_findTarget` (its `alreadyVisited` is only seeded for the entry node).
|
|
176
|
+
let current = moduleGraph
|
|
177
|
+
.getExportsInfo(firstTarget.module)
|
|
178
|
+
.getReadOnlyExportInfo(firstTarget.export[0]);
|
|
179
|
+
/** @type {Set<ExportInfo>} */
|
|
180
|
+
const visited = new Set([exportInfo, current]);
|
|
181
|
+
for (;;) {
|
|
182
|
+
const target = current.findTarget(moduleGraph, RETURNS_TRUE);
|
|
183
|
+
if (!target || typeof target !== "object") return false;
|
|
184
|
+
if (
|
|
185
|
+
target.module === parentModule &&
|
|
186
|
+
Array.isArray(target.export) &&
|
|
187
|
+
target.export.length === 1 &&
|
|
188
|
+
target.export[0] === name
|
|
189
|
+
) {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
if (!Array.isArray(target.export) || target.export.length === 0) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
const next = moduleGraph
|
|
196
|
+
.getExportsInfo(target.module)
|
|
197
|
+
.getReadOnlyExportInfo(target.export[0]);
|
|
198
|
+
if (visited.has(next)) return false;
|
|
199
|
+
visited.add(next);
|
|
200
|
+
current = next;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
131
204
|
/**
|
|
132
205
|
* Determine export assignments.
|
|
133
206
|
* @param {ModuleGraph} moduleGraph module graph
|
|
@@ -149,6 +222,11 @@ const determineExportAssignments = (
|
|
|
149
222
|
dependencies = [...dependencies, additionalDependency];
|
|
150
223
|
}
|
|
151
224
|
|
|
225
|
+
const referenceDep = dependencies[0] || additionalDependency;
|
|
226
|
+
const parentModule = referenceDep
|
|
227
|
+
? moduleGraph.getParentModule(referenceDep)
|
|
228
|
+
: null;
|
|
229
|
+
|
|
152
230
|
for (const dep of dependencies) {
|
|
153
231
|
const i = dependencyIndices.length;
|
|
154
232
|
dependencyIndices[i] = names.size;
|
|
@@ -159,7 +237,11 @@ const determineExportAssignments = (
|
|
|
159
237
|
if (
|
|
160
238
|
exportInfo.provided === true &&
|
|
161
239
|
exportInfo.name !== "default" &&
|
|
162
|
-
!names.has(exportInfo.name)
|
|
240
|
+
!names.has(exportInfo.name) &&
|
|
241
|
+
!(
|
|
242
|
+
parentModule &&
|
|
243
|
+
isStarReexportBackToParent(moduleGraph, exportInfo, parentModule)
|
|
244
|
+
)
|
|
163
245
|
) {
|
|
164
246
|
names.add(exportInfo.name);
|
|
165
247
|
dependencyIndices[i] = names.size;
|
|
@@ -535,6 +617,10 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
|
535
617
|
/** @type {Hidden | undefined} */
|
|
536
618
|
const hidden = hiddenExports !== undefined ? new Set() : undefined;
|
|
537
619
|
|
|
620
|
+
const parentModule = /** @type {Module} */ (
|
|
621
|
+
moduleGraph.getParentModule(this)
|
|
622
|
+
);
|
|
623
|
+
|
|
538
624
|
if (noExtraImports) {
|
|
539
625
|
for (const exportInfo of exportsInfo.orderedExports) {
|
|
540
626
|
const name = exportInfo.name;
|
|
@@ -544,10 +630,22 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
|
544
630
|
importedExportsInfo.getReadOnlyExportInfo(name);
|
|
545
631
|
if (importedExportInfo.provided === false) continue;
|
|
546
632
|
if (hiddenExports !== undefined && hiddenExports.has(name)) {
|
|
633
|
+
// Earlier star deps already provided this name non-cyclically
|
|
634
|
+
// (`determineExportAssignments` filters cyclic candidates), so
|
|
635
|
+
// the cycle check below would be wasted work.
|
|
547
636
|
/** @type {Hidden} */
|
|
548
637
|
(hidden).add(name);
|
|
549
638
|
continue;
|
|
550
639
|
}
|
|
640
|
+
if (
|
|
641
|
+
isStarReexportBackToParent(
|
|
642
|
+
moduleGraph,
|
|
643
|
+
importedExportInfo,
|
|
644
|
+
parentModule
|
|
645
|
+
)
|
|
646
|
+
) {
|
|
647
|
+
continue;
|
|
648
|
+
}
|
|
551
649
|
exports.add(name);
|
|
552
650
|
if (importedExportInfo.provided === true) continue;
|
|
553
651
|
checked.add(name);
|
|
@@ -564,6 +662,15 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
|
564
662
|
(hidden).add(name);
|
|
565
663
|
continue;
|
|
566
664
|
}
|
|
665
|
+
if (
|
|
666
|
+
isStarReexportBackToParent(
|
|
667
|
+
moduleGraph,
|
|
668
|
+
importedExportInfo,
|
|
669
|
+
parentModule
|
|
670
|
+
)
|
|
671
|
+
) {
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
567
674
|
exports.add(name);
|
|
568
675
|
if (importedExportInfo.provided === true) continue;
|
|
569
676
|
checked.add(name);
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
const ConditionalInitFragment = require("../ConditionalInitFragment");
|
|
9
9
|
const Dependency = require("../Dependency");
|
|
10
|
-
const HarmonyLinkingError = require("../HarmonyLinkingError");
|
|
11
10
|
const InitFragment = require("../InitFragment");
|
|
12
11
|
const Template = require("../Template");
|
|
13
12
|
const AwaitDependenciesInitFragment = require("../async-modules/AwaitDependenciesInitFragment");
|
|
14
13
|
const { filterRuntime, mergeRuntime } = require("../util/runtime");
|
|
14
|
+
const HarmonyLinkingError = require("./HarmonyLinkingError");
|
|
15
15
|
const { ImportPhase, ImportPhaseUtils } = require("./ImportPhase");
|
|
16
16
|
const ModuleDependency = require("./ModuleDependency");
|
|
17
17
|
|
|
@@ -23,7 +23,7 @@ const ModuleDependency = require("./ModuleDependency");
|
|
|
23
23
|
/** @typedef {import("../Module")} Module */
|
|
24
24
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
|
25
25
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
26
|
-
/** @typedef {import("../WebpackError")} WebpackError */
|
|
26
|
+
/** @typedef {import("../errors/WebpackError")} WebpackError */
|
|
27
27
|
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
|
28
28
|
/** @typedef {import("./ImportPhase").ImportPhaseType} ImportPhaseType */
|
|
29
29
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
@@ -112,6 +112,14 @@ class HarmonyImportDependency extends ModuleDependency {
|
|
|
112
112
|
return "esm";
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Returns true if this dependency can be concatenated
|
|
117
|
+
* @returns {boolean} true if this dependency can be concatenated
|
|
118
|
+
*/
|
|
119
|
+
canConcatenate() {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
|
|
115
123
|
/**
|
|
116
124
|
* Returns an identifier to merge equal requests.
|
|
117
125
|
* @returns {string | null} an identifier to merge equal requests
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const HotModuleReplacementPlugin = require("../HotModuleReplacementPlugin");
|
|
9
|
-
const WebpackError = require("../WebpackError");
|
|
9
|
+
const WebpackError = require("../errors/WebpackError");
|
|
10
10
|
const {
|
|
11
11
|
VariableInfo,
|
|
12
12
|
getImportAttributes
|
|
@@ -413,6 +413,27 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
413
413
|
return true;
|
|
414
414
|
}
|
|
415
415
|
);
|
|
416
|
+
// Per the TC39 import-defer spec, [[Set]] on a Module Namespace
|
|
417
|
+
// Exotic Object returns false without triggering evaluation. The
|
|
418
|
+
// default expressionMemberChain path produces `<importVar>.a.foo`
|
|
419
|
+
// whose `.a` getter eagerly requires (and thus evaluates) the
|
|
420
|
+
// deferred module. For top-level `ns.foo = value`, walk only the
|
|
421
|
+
// bare `ns` identifier so it gets replaced with the deferred
|
|
422
|
+
// namespace proxy (whose set trap returns false), and leave the
|
|
423
|
+
// `.foo = value` part as plain code.
|
|
424
|
+
parser.hooks.assignMemberChain
|
|
425
|
+
.for(harmonySpecifierTag)
|
|
426
|
+
.tap(PLUGIN_NAME, (expression, members) => {
|
|
427
|
+
const settings = /** @type {HarmonySettings} */ (parser.currentTagData);
|
|
428
|
+
if (!ImportPhaseUtils.isDefer(settings.phase)) return;
|
|
429
|
+
if (expression.operator !== "=") return;
|
|
430
|
+
if (members.length !== 1) return;
|
|
431
|
+
const left = /** @type {MemberExpression} */ (expression.left);
|
|
432
|
+
if (left.object.type !== "Identifier") return;
|
|
433
|
+
parser.walkExpression(expression.right);
|
|
434
|
+
parser.walkExpression(left.object);
|
|
435
|
+
return true;
|
|
436
|
+
});
|
|
416
437
|
const { hotAcceptCallback, hotAcceptWithoutCallback } =
|
|
417
438
|
HotModuleReplacementPlugin.getParserHooks(parser);
|
|
418
439
|
hotAcceptCallback.tap(PLUGIN_NAME, (expr, requests) => {
|
|
@@ -27,7 +27,7 @@ const { ImportPhaseUtils } = require("./ImportPhase");
|
|
|
27
27
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
|
28
28
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
29
29
|
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
|
30
|
-
/** @typedef {import("../WebpackError")} WebpackError */
|
|
30
|
+
/** @typedef {import("../errors/WebpackError")} WebpackError */
|
|
31
31
|
/** @typedef {import("../javascript/JavascriptParser").DestructuringAssignmentProperties} DestructuringAssignmentProperties */
|
|
32
32
|
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
|
33
33
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
"use strict";
|
|
6
6
|
|
|
7
|
-
const WebpackError = require("
|
|
7
|
+
const WebpackError = require("../errors/WebpackError");
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
class HarmonyLinkingError extends WebpackError {
|
|
10
10
|
/** @param {string} message Error message */
|
|
11
11
|
constructor(message) {
|
|
12
12
|
super(message);
|
|
@@ -14,4 +14,6 @@ module.exports = class HarmonyLinkingError extends WebpackError {
|
|
|
14
14
|
this.name = "HarmonyLinkingError";
|
|
15
15
|
this.hideStack = true;
|
|
16
16
|
}
|
|
17
|
-
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = HarmonyLinkingError;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
const makeSerializable = require("../util/makeSerializable");
|
|
8
|
+
const CssUrlDependency = require("./CssUrlDependency");
|
|
9
|
+
const ModuleDependency = require("./ModuleDependency");
|
|
10
|
+
|
|
11
|
+
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
12
|
+
/** @typedef {import("../Chunk")} Chunk */
|
|
13
|
+
/** @typedef {import("../Dependency")} Dependency */
|
|
14
|
+
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
|
15
|
+
/** @typedef {import("../Entrypoint")} Entrypoint */
|
|
16
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
17
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
18
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Represents an inline `<script>...</script>` block in an HTML module. The
|
|
22
|
+
* tag's body is bundled as its own entry chunk — the same pipeline that
|
|
23
|
+
* processes `<script src>` — and the inline body is replaced with a
|
|
24
|
+
* `src` attribute pointing at the emitted chunk URL.
|
|
25
|
+
*/
|
|
26
|
+
class HtmlInlineScriptDependency extends ModuleDependency {
|
|
27
|
+
/**
|
|
28
|
+
* Creates an instance of HtmlInlineScriptDependency.
|
|
29
|
+
* @param {string} request virtual request resolving to the inline JS (data URI)
|
|
30
|
+
* @param {number} insertPos position right after `<script` where ` src="…"` is inserted
|
|
31
|
+
* @param {Range} contentRange range of the inline JS body (between `<script>` and `</script>`)
|
|
32
|
+
* @param {string} entryName name of the entry the inline JS is bundled into
|
|
33
|
+
* @param {string=} category dependency category used for resolving and grouping
|
|
34
|
+
*/
|
|
35
|
+
constructor(request, insertPos, contentRange, entryName, category) {
|
|
36
|
+
super(request);
|
|
37
|
+
this.insertPos = insertPos;
|
|
38
|
+
this.contentRange = contentRange;
|
|
39
|
+
this.range = contentRange;
|
|
40
|
+
this.entryName = entryName;
|
|
41
|
+
/** @type {string} */
|
|
42
|
+
this._category = category || "commonjs";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get type() {
|
|
46
|
+
return "html inline script";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get category() {
|
|
50
|
+
return this._category;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Serializes this instance into the provided serializer context.
|
|
55
|
+
* @param {ObjectSerializerContext} context context
|
|
56
|
+
*/
|
|
57
|
+
serialize(context) {
|
|
58
|
+
const { write } = context;
|
|
59
|
+
write(this.insertPos);
|
|
60
|
+
write(this.contentRange);
|
|
61
|
+
write(this.entryName);
|
|
62
|
+
write(this._category);
|
|
63
|
+
super.serialize(context);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Restores this instance from the provided deserializer context.
|
|
68
|
+
* @param {ObjectDeserializerContext} context context
|
|
69
|
+
*/
|
|
70
|
+
deserialize(context) {
|
|
71
|
+
const { read } = context;
|
|
72
|
+
this.insertPos = read();
|
|
73
|
+
this.contentRange = read();
|
|
74
|
+
this.range = this.contentRange;
|
|
75
|
+
this.entryName = read();
|
|
76
|
+
this._category = read();
|
|
77
|
+
super.deserialize(context);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
HtmlInlineScriptDependency.Template = class HtmlInlineScriptDependencyTemplate extends (
|
|
82
|
+
ModuleDependency.Template
|
|
83
|
+
) {
|
|
84
|
+
/**
|
|
85
|
+
* Applies the plugin by registering its hooks on the compiler.
|
|
86
|
+
* @param {Dependency} dependency the dependency for which the template should be applied
|
|
87
|
+
* @param {ReplaceSource} source the current replace source which can be modified
|
|
88
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
|
89
|
+
* @returns {void}
|
|
90
|
+
*/
|
|
91
|
+
apply(dependency, source, templateContext) {
|
|
92
|
+
const { runtimeTemplate } = templateContext;
|
|
93
|
+
const dep = /** @type {HtmlInlineScriptDependency} */ (dependency);
|
|
94
|
+
const compilation = runtimeTemplate.compilation;
|
|
95
|
+
const entrypoint = /** @type {Entrypoint | undefined} */ (
|
|
96
|
+
compilation.entrypoints.get(dep.entryName)
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
/** @type {string} */
|
|
100
|
+
let url = "data:,";
|
|
101
|
+
|
|
102
|
+
if (entrypoint) {
|
|
103
|
+
const chunk = /** @type {Chunk} */ (entrypoint.getEntrypointChunk());
|
|
104
|
+
const outputOptions = runtimeTemplate.outputOptions;
|
|
105
|
+
const filenameTemplate =
|
|
106
|
+
chunk.filenameTemplate ||
|
|
107
|
+
(chunk.canBeInitial()
|
|
108
|
+
? outputOptions.filename
|
|
109
|
+
: outputOptions.chunkFilename);
|
|
110
|
+
|
|
111
|
+
const filename = compilation.getPath(filenameTemplate, {
|
|
112
|
+
chunk,
|
|
113
|
+
contentHashType: "javascript"
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
url = `${CssUrlDependency.PUBLIC_PATH_AUTO}${filename}`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Insert ` src="…"` right after `<script` so the inline body is
|
|
120
|
+
// served from the emitted chunk instead. The browser ignores the
|
|
121
|
+
// remaining inline body once `src` is present, but we still clear
|
|
122
|
+
// it below so the unprocessed JS doesn't ride along.
|
|
123
|
+
source.insert(dep.insertPos, ` src="${url}"`);
|
|
124
|
+
source.replace(dep.contentRange[0], dep.contentRange[1] - 1, "");
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
makeSerializable(
|
|
129
|
+
HtmlInlineScriptDependency,
|
|
130
|
+
"webpack/lib/dependencies/HtmlInlineScriptDependency"
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
module.exports = HtmlInlineScriptDependency;
|