webpack 5.108.4 → 5.109.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/webpack.js +12 -0
- package/lib/APIPlugin.js +48 -29
- package/lib/CacheFacade.js +8 -0
- package/lib/ChunkGraph.js +17 -15
- package/lib/ChunkGroup.js +1 -0
- package/lib/CompatibilityPlugin.js +62 -29
- package/lib/Compilation.js +58 -6
- package/lib/ConstPlugin.js +11 -11
- package/lib/ContextModule.js +239 -6
- package/lib/ContextModuleFactory.js +139 -14
- package/lib/DefinePlugin.js +433 -112
- package/lib/Entrypoint.js +1 -1
- package/lib/ExportsInfo.js +22 -5
- package/lib/ExportsInfoApiPlugin.js +2 -2
- package/lib/ExternalModule.js +107 -5
- package/lib/ExternalModuleFactoryPlugin.js +20 -1
- package/lib/FileSystemInfo.js +256 -100
- package/lib/FlagDependencyUsagePlugin.js +33 -12
- package/lib/HotModuleReplacementPlugin.js +18 -15
- package/lib/InitFragment.js +20 -32
- package/lib/Module.js +3 -0
- package/lib/ModuleFilenameHelpers.js +2 -2
- package/lib/ModuleTypeConstants.js +8 -1
- package/lib/MultiCompiler.js +13 -2
- package/lib/MultiWatching.js +1 -0
- package/lib/NodeStuffPlugin.js +51 -33
- package/lib/NormalModule.js +175 -401
- package/lib/NormalModuleFactory.js +76 -2
- package/lib/ProgressPlugin.js +211 -119
- package/lib/ProvidePlugin.js +2 -2
- package/lib/RuntimeGlobals.js +47 -0
- package/lib/RuntimePlugin.js +67 -107
- package/lib/RuntimeTemplate.js +304 -16
- package/lib/Template.js +23 -3
- package/lib/UseStrictPlugin.js +1 -1
- package/lib/WebpackIsIncludedPlugin.js +1 -1
- package/lib/WebpackOptionsApply.js +24 -19
- package/lib/asset/AssetGenerator.js +110 -28
- package/lib/asset/AssetModulesPlugin.js +92 -2
- package/lib/asset/WebManifestGenerator.js +164 -0
- package/lib/asset/WebManifestParser.js +130 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +14 -4
- package/lib/async-modules/isGeneratorLowered.js +26 -0
- package/lib/cache/PackFileCacheStrategy.js +9 -3
- package/lib/config/browserslistTargetHandler.js +40 -0
- package/lib/config/defaults.js +219 -29
- package/lib/config/normalization.js +26 -0
- package/lib/config/target.js +9 -1
- package/lib/container/HoistContainerReferencesPlugin.js +47 -55
- package/lib/css/CssGenerator.js +40 -31
- package/lib/css/CssLoadingRuntimeModule.js +5 -1
- package/lib/css/CssModulesPlugin.js +13 -0
- package/lib/css/CssParser.js +729 -313
- package/lib/css/syntax.js +1371 -861
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -6
- package/lib/dependencies/AMDPlugin.js +2 -2
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +13 -13
- package/lib/dependencies/CommonJsDependencyHelpers.js +39 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +19 -0
- package/lib/dependencies/CommonJsExportsDependency.js +47 -2
- package/lib/dependencies/CommonJsExportsParserPlugin.js +10 -10
- package/lib/dependencies/CommonJsImportsParserPlugin.js +18 -18
- package/lib/dependencies/CommonJsPlugin.js +2 -2
- package/lib/dependencies/CommonJsRequireDependency.js +26 -1
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +32 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/CreateRequireParserPlugin.js +6 -6
- package/lib/dependencies/CssIcssExportDependency.js +162 -71
- package/lib/dependencies/CssUrlDependency.js +35 -4
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +2 -2
- package/lib/dependencies/HarmonyCompatibilityDependency.js +32 -14
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +43 -13
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +2 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +7 -19
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +17 -9
- package/lib/dependencies/HarmonyImportDependency.js +13 -2
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +11 -11
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -7
- package/lib/dependencies/HarmonyModulesPlugin.js +6 -0
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -1
- package/lib/dependencies/HtmlEntryDependency.js +797 -172
- package/lib/dependencies/HtmlSourceDependency.js +26 -0
- package/lib/dependencies/ImportDependency.js +43 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +31 -18
- package/lib/dependencies/ImportMetaContextPlugin.js +38 -7
- package/lib/dependencies/ImportMetaGlobDependency.js +81 -0
- package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +78 -0
- package/lib/dependencies/ImportMetaGlobHelpers.js +660 -0
- package/lib/dependencies/ImportMetaPlugin.js +532 -180
- package/lib/dependencies/ImportMetaResolveDependency.js +90 -0
- package/lib/dependencies/ImportParserPlugin.js +80 -17
- package/lib/dependencies/ImportPhase.js +10 -8
- package/lib/dependencies/LoaderPlugin.js +5 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +3 -6
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +4 -11
- package/lib/dependencies/SystemPlugin.js +2 -4
- package/lib/dependencies/TopLevelAwaitDependency.js +93 -0
- package/lib/dependencies/URLDependency.js +141 -21
- package/lib/dependencies/{WorkerPlugin.js → WorkerAndWorkletPlugin.js} +324 -112
- package/lib/dependencies/WorkerDependency.js +86 -18
- package/lib/dependencies/WorkletDependency.js +278 -0
- package/lib/dll/DelegatedModuleFactoryPlugin.js +19 -0
- package/lib/errors/EnvironmentNotSupportAsyncWarning.js +1 -1
- package/lib/errors/LoaderLoadingError.js +20 -0
- package/lib/errors/ModuleParseError.js +39 -22
- package/lib/errors/NodeStuffInWebError.js +1 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +47 -14
- package/lib/esm/ModuleChunkLoadingPlugin.js +8 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +29 -1
- package/lib/hmr/lazyCompilationBackend.js +51 -12
- package/lib/html/HtmlGenerator.js +907 -15
- package/lib/html/HtmlModule.js +2 -2
- package/lib/html/HtmlModulesPlugin.js +610 -166
- package/lib/html/HtmlParser.js +603 -247
- package/lib/html/favicon.svg +1 -0
- package/lib/html/syntax.js +3451 -2762
- package/lib/ids/IdHelpers.js +25 -11
- package/lib/index.js +6 -0
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -5
- package/lib/javascript/BasicEvaluatedExpression.js +366 -48
- package/lib/javascript/JavascriptGenerator.js +197 -49
- package/lib/javascript/JavascriptModulesPlugin.js +178 -24
- package/lib/javascript/JavascriptParser.js +704 -355
- package/lib/javascript/JavascriptParserHelpers.js +3 -6
- package/lib/javascript/syntax.js +5037 -0
- package/lib/library/ModuleLibraryPlugin.js +38 -1
- package/lib/loaders/LoaderRunner.js +714 -0
- package/lib/loaders/loadLoader.js +100 -0
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +29 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +24 -2
- package/lib/optimize/AggressiveMergingPlugin.js +19 -15
- package/lib/optimize/ConcatenatedModule.js +139 -31
- package/lib/optimize/FlagIncludedChunksPlugin.js +13 -3
- package/lib/optimize/InnerGraphPlugin.js +50 -30
- package/lib/optimize/ModuleConcatenationPlugin.js +139 -24
- package/lib/optimize/SideEffectsFlagPlugin.js +86 -43
- package/lib/optimize/SplitChunksPlugin.js +146 -44
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +15 -0
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +24 -13
- package/lib/prefetch/ResourceHintPlugin.js +687 -0
- package/lib/prefetch/ResourceHintRuntimeModule.js +149 -0
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +210 -0
- package/lib/prefetch/parseResourceHintOptions.js +103 -0
- package/lib/rules/RuleSetCompiler.js +114 -0
- package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +56 -0
- package/lib/runtime/AsyncModuleRuntimeModule.js +24 -8
- package/lib/runtime/AutoPublicPathRuntimeModule.js +7 -1
- package/lib/runtime/CommonJsWrapRuntimeModule.js +37 -0
- package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +59 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +204 -8
- package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +4 -1
- package/lib/schemes/HttpUriPlugin.js +40 -1
- package/lib/schemes/VirtualUrlPlugin.js +1 -2
- package/lib/serialization/BinaryMiddleware.js +270 -938
- package/lib/serialization/FileMiddleware.js +29 -3
- package/lib/stats/DefaultStatsFactoryPlugin.js +229 -194
- package/lib/stats/DefaultStatsPresetPlugin.js +2 -0
- package/lib/stats/DefaultStatsPrinterPlugin.js +36 -168
- package/lib/stats/StatsFactory.js +46 -17
- package/lib/url/URLParserPlugin.js +66 -13
- package/lib/util/AsyncQueue.js +122 -72
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/StackedMap.js +122 -48
- package/lib/util/binarySearchBounds.js +2 -2
- package/lib/util/concatenate.js +40 -14
- package/lib/util/createHooksRegistry.js +13 -5
- package/lib/util/dataURL.js +2 -2
- package/lib/util/deterministicGrouping.js +7 -5
- package/lib/util/formatSize.js +6 -2
- package/lib/util/globUtils.js +710 -0
- package/lib/util/identifier.js +23 -6
- package/lib/util/implicitTypeLoaderFallback.js +62 -0
- package/lib/util/internalSerializables.js +88 -71
- package/lib/util/magicComment.js +121 -25
- package/lib/util/numberHash.js +2 -2
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +24 -18
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +33 -22
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +79 -16
- package/lib/web/FetchCompileAsyncWasmPlugin.js +19 -0
- package/lib/web/FetchCompileWasmPlugin.js +14 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -0
- package/lib/webpack.js +65 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +3 -0
- package/module.d.ts +21 -0
- package/package.json +12 -11
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +759 -36
- package/schemas/plugins/HtmlParserOptions.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.json +17 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/types.d.ts +1212 -99
|
@@ -10,10 +10,16 @@ const EnvironmentNotSupportAsyncWarning = require("../errors/EnvironmentNotSuppo
|
|
|
10
10
|
const DynamicExports = require("./DynamicExports");
|
|
11
11
|
const HarmonyCompatibilityDependency = require("./HarmonyCompatibilityDependency");
|
|
12
12
|
const HarmonyExports = require("./HarmonyExports");
|
|
13
|
-
const {
|
|
13
|
+
const {
|
|
14
|
+
IMPORT_META_NAMES,
|
|
15
|
+
IMPORT_META_STAGE_ESM_DETECTION
|
|
16
|
+
} = require("./ImportMetaPlugin");
|
|
17
|
+
const TopLevelAwaitDependency = require("./TopLevelAwaitDependency");
|
|
14
18
|
|
|
19
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
|
15
20
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
|
16
21
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
|
22
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
17
23
|
|
|
18
24
|
const PLUGIN_NAME = "HarmonyDetectionParserPlugin";
|
|
19
25
|
|
|
@@ -68,34 +74,58 @@ module.exports = class HarmonyDetectionParserPlugin {
|
|
|
68
74
|
}
|
|
69
75
|
});
|
|
70
76
|
|
|
71
|
-
parser.hooks.topLevelAwait.tap(PLUGIN_NAME, () => {
|
|
77
|
+
parser.hooks.topLevelAwait.tap(PLUGIN_NAME, (node) => {
|
|
72
78
|
const module = parser.state.module;
|
|
73
79
|
enableHarmony(false);
|
|
74
80
|
/** @type {BuildMeta} */
|
|
75
81
|
(module.buildMeta).async = true;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
const buildInfo = /** @type {BuildInfo} */ (module.buildInfo);
|
|
83
|
+
if (node.type === "AwaitExpression") {
|
|
84
|
+
// Record for a possible `await` -> `(yield …)` rewrite when the module
|
|
85
|
+
// is lowered to a generator (target without `async`/`await`).
|
|
86
|
+
module.addPresentationalDependency(
|
|
87
|
+
new TopLevelAwaitDependency(
|
|
88
|
+
/** @type {Range} */ (node.range),
|
|
89
|
+
/** @type {Range} */ (node.argument.range)
|
|
90
|
+
)
|
|
91
|
+
);
|
|
92
|
+
} else {
|
|
93
|
+
// `for await…of` can't be expressed as a generator; never lower it.
|
|
94
|
+
buildInfo.usesTopLevelAwaitForOf = true;
|
|
95
|
+
}
|
|
96
|
+
const { runtimeTemplate } = parser.state.compilation;
|
|
97
|
+
if (
|
|
98
|
+
!runtimeTemplate.supportsAsyncFunction() &&
|
|
99
|
+
(!runtimeTemplate.supportsGenerator() ||
|
|
100
|
+
buildInfo.usesTopLevelAwaitForOf)
|
|
101
|
+
) {
|
|
102
|
+
module.addWarning(
|
|
103
|
+
new EnvironmentNotSupportAsyncWarning(module, "topLevelAwait")
|
|
104
|
+
);
|
|
105
|
+
}
|
|
81
106
|
});
|
|
82
107
|
|
|
83
108
|
// Using `import.meta` only parses as a module, so it marks the module ESM.
|
|
84
|
-
// Non-bailing
|
|
85
|
-
// unknown members go
|
|
109
|
+
// Non-bailing; staged before the bailing DefinePlugin and ImportMetaPlugin
|
|
110
|
+
// replacement taps so it observes every access; unknown members go
|
|
111
|
+
// through `unhandledExpressionMemberChain`.
|
|
86
112
|
const onImportMeta = () => {
|
|
87
113
|
enableHarmony(false);
|
|
88
114
|
};
|
|
115
|
+
const earlyTapOptions = {
|
|
116
|
+
name: PLUGIN_NAME,
|
|
117
|
+
stage: IMPORT_META_STAGE_ESM_DETECTION
|
|
118
|
+
};
|
|
89
119
|
for (const name of IMPORT_META_NAMES) {
|
|
90
|
-
parser.hooks.expression.for(name).tap(
|
|
91
|
-
parser.hooks.typeof.for(name).tap(
|
|
120
|
+
parser.hooks.expression.for(name).tap(earlyTapOptions, onImportMeta);
|
|
121
|
+
parser.hooks.typeof.for(name).tap(earlyTapOptions, onImportMeta);
|
|
92
122
|
}
|
|
93
123
|
parser.hooks.expressionMemberChain
|
|
94
124
|
.for("import.meta")
|
|
95
|
-
.tap(
|
|
125
|
+
.tap(earlyTapOptions, onImportMeta);
|
|
96
126
|
parser.hooks.unhandledExpressionMemberChain
|
|
97
127
|
.for("import.meta")
|
|
98
|
-
.tap(
|
|
128
|
+
.tap(earlyTapOptions, onImportMeta);
|
|
99
129
|
|
|
100
130
|
/**
|
|
101
131
|
* Returns true if in harmony.
|
|
@@ -70,10 +70,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
70
70
|
),
|
|
71
71
|
/** @type {Range} */ (statement.range)
|
|
72
72
|
);
|
|
73
|
-
dep.setLocWithIndex(
|
|
74
|
-
/** @type {DependencyLocation} */ (statement.loc),
|
|
75
|
-
-1
|
|
76
|
-
);
|
|
73
|
+
dep.setLocWithIndex(parser.getLocation(statement), -1);
|
|
77
74
|
parser.state.module.addPresentationalDependency(dep);
|
|
78
75
|
return true;
|
|
79
76
|
});
|
|
@@ -84,10 +81,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
84
81
|
"",
|
|
85
82
|
/** @type {Range} */ (statement.range)
|
|
86
83
|
);
|
|
87
|
-
clearDep.setLocWithIndex(
|
|
88
|
-
/** @type {DependencyLocation} */ (statement.loc),
|
|
89
|
-
-1
|
|
90
|
-
);
|
|
84
|
+
clearDep.setLocWithIndex(parser.getLocation(statement), -1);
|
|
91
85
|
parser.state.module.addPresentationalDependency(clearDep);
|
|
92
86
|
|
|
93
87
|
const phase = getImportPhase(parser, statement);
|
|
@@ -95,7 +89,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
95
89
|
const error = new WebpackError(
|
|
96
90
|
"Deferred re-export (`export defer * as namespace from '...'`) is not a part of the Import Defer proposal.\nUse the following code instead:\n import defer * as namespace from '...';\n export { namespace };"
|
|
97
91
|
);
|
|
98
|
-
error.loc = statement
|
|
92
|
+
error.loc = parser.getLocation(statement) || undefined;
|
|
99
93
|
parser.state.current.addError(error);
|
|
100
94
|
}
|
|
101
95
|
const sideEffectDep = new HarmonyImportSideEffectDependency(
|
|
@@ -104,10 +98,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
104
98
|
phase,
|
|
105
99
|
getImportAttributes(statement)
|
|
106
100
|
);
|
|
107
|
-
sideEffectDep.setLocWithIndex(
|
|
108
|
-
/** @type {DependencyLocation} */ (statement.loc),
|
|
109
|
-
-1
|
|
110
|
-
);
|
|
101
|
+
sideEffectDep.setLocWithIndex(parser.getLocation(statement), -1);
|
|
111
102
|
// lazy barrel: defer at parse time when the importing module is side-effect-free
|
|
112
103
|
const moduleFactoryMeta = parser.state.module.factoryMeta;
|
|
113
104
|
if (moduleFactoryMeta !== undefined && moduleFactoryMeta.sideEffectFree) {
|
|
@@ -168,10 +159,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
168
159
|
node.type === "ClassDeclaration" ||
|
|
169
160
|
node.type === "ClassExpression") &&
|
|
170
161
|
!node.id));
|
|
171
|
-
dep.setLocWithIndex(
|
|
172
|
-
/** @type {DependencyLocation} */ (statement.loc),
|
|
173
|
-
-1
|
|
174
|
-
);
|
|
162
|
+
dep.setLocWithIndex(parser.getLocation(statement), -1);
|
|
175
163
|
parser.state.current.addDependency(dep);
|
|
176
164
|
getInnerGraphUtils(parser.state.compilation).addVariableUsage(
|
|
177
165
|
parser,
|
|
@@ -241,7 +229,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
241
229
|
dep.setLazy(true);
|
|
242
230
|
}
|
|
243
231
|
dep.setLocWithIndex(
|
|
244
|
-
|
|
232
|
+
parser.getLocation(statement),
|
|
245
233
|
/** @type {number} */ (idx)
|
|
246
234
|
);
|
|
247
235
|
const isAsiSafe = !parser.isAsiPosition(
|
|
@@ -296,7 +284,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
296
284
|
dep.setLazy(true);
|
|
297
285
|
}
|
|
298
286
|
dep.setLocWithIndex(
|
|
299
|
-
|
|
287
|
+
parser.getLocation(statement),
|
|
300
288
|
/** @type {number} */ (idx)
|
|
301
289
|
);
|
|
302
290
|
const isAsiSafe = !parser.isAsiPosition(
|
|
@@ -191,8 +191,11 @@ const isStarReexportBackToParent = (moduleGraph, exportInfo, parentModule) => {
|
|
|
191
191
|
let current = moduleGraph
|
|
192
192
|
.getExportsInfo(firstTarget.module)
|
|
193
193
|
.getReadOnlyExportInfo(firstTarget.export[0]);
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
// Allocated lazily: a single-extra-hop chain that terminates (the common
|
|
195
|
+
// `barrel -> leaf local binding` case) returns before `next` is ever
|
|
196
|
+
// computed, so the visited set is pure waste there.
|
|
197
|
+
/** @type {Set<ExportInfo> | undefined} */
|
|
198
|
+
let visited;
|
|
196
199
|
for (;;) {
|
|
197
200
|
const target = current.findTarget(moduleGraph, RETURNS_TRUE);
|
|
198
201
|
if (!target || typeof target !== "object") return false;
|
|
@@ -210,6 +213,7 @@ const isStarReexportBackToParent = (moduleGraph, exportInfo, parentModule) => {
|
|
|
210
213
|
const next = moduleGraph
|
|
211
214
|
.getExportsInfo(target.module)
|
|
212
215
|
.getReadOnlyExportInfo(target.export[0]);
|
|
216
|
+
if (visited === undefined) visited = new Set([exportInfo, current]);
|
|
213
217
|
if (visited.has(next)) return false;
|
|
214
218
|
visited.add(next);
|
|
215
219
|
current = next;
|
|
@@ -635,7 +639,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
|
635
639
|
exportsInfo.otherExportsInfo.getUsed(runtime) === UsageState.Unused;
|
|
636
640
|
|
|
637
641
|
/** @type {IgnoredExports} */
|
|
638
|
-
const ignoredExports = new Set(
|
|
642
|
+
const ignoredExports = new Set(this.activeExports);
|
|
643
|
+
ignoredExports.add("default");
|
|
639
644
|
|
|
640
645
|
/** @type {Hidden | undefined} */
|
|
641
646
|
let hiddenExports;
|
|
@@ -1387,7 +1392,12 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
|
1387
1392
|
);
|
|
1388
1393
|
break;
|
|
1389
1394
|
|
|
1390
|
-
case "normal-reexport":
|
|
1395
|
+
case "normal-reexport": {
|
|
1396
|
+
// loop-invariants hoisted out of the per-item loop below (a barrel
|
|
1397
|
+
// re-exporting N names otherwise repeats these lookups N times)
|
|
1398
|
+
const connection = moduleGraph.getConnection(dep);
|
|
1399
|
+
const selfExportsInfo = moduleGraph.getExportsInfo(module);
|
|
1400
|
+
const importedExportsInfo = moduleGraph.getExportsInfo(importedModule);
|
|
1391
1401
|
for (const {
|
|
1392
1402
|
name,
|
|
1393
1403
|
ids,
|
|
@@ -1396,7 +1406,6 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
|
1396
1406
|
} of /** @type {NormalReexportItem[]} */ (mode.items)) {
|
|
1397
1407
|
if (hidden) continue;
|
|
1398
1408
|
if (checked) {
|
|
1399
|
-
const connection = moduleGraph.getConnection(dep);
|
|
1400
1409
|
const key = `harmony reexport (checked) ${importVar} ${name}`;
|
|
1401
1410
|
const runtimeCondition = dep.weak
|
|
1402
1411
|
? false
|
|
@@ -1425,11 +1434,9 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
|
1425
1434
|
this.getReexportFragment(
|
|
1426
1435
|
module,
|
|
1427
1436
|
"reexport safe",
|
|
1428
|
-
|
|
1437
|
+
selfExportsInfo.getUsedName(name, runtime),
|
|
1429
1438
|
importVar,
|
|
1430
|
-
|
|
1431
|
-
.getExportsInfo(importedModule)
|
|
1432
|
-
.getUsedName(ids, runtime),
|
|
1439
|
+
importedExportsInfo.getUsedName(ids, runtime),
|
|
1433
1440
|
runtimeRequirements,
|
|
1434
1441
|
ids
|
|
1435
1442
|
)
|
|
@@ -1437,6 +1444,7 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
|
1437
1444
|
}
|
|
1438
1445
|
}
|
|
1439
1446
|
break;
|
|
1447
|
+
}
|
|
1440
1448
|
|
|
1441
1449
|
case "dynamic-reexport": {
|
|
1442
1450
|
const ignored = mode.hidden
|
|
@@ -10,6 +10,7 @@ const Dependency = require("../Dependency");
|
|
|
10
10
|
const InitFragment = require("../InitFragment");
|
|
11
11
|
const Template = require("../Template");
|
|
12
12
|
const AwaitDependenciesInitFragment = require("../async-modules/AwaitDependenciesInitFragment");
|
|
13
|
+
const isGeneratorLowered = require("../async-modules/isGeneratorLowered");
|
|
13
14
|
const { filterRuntime, mergeRuntime } = require("../util/runtime");
|
|
14
15
|
const HarmonyLinkingError = require("./HarmonyLinkingError");
|
|
15
16
|
const { ImportPhase, ImportPhaseUtils } = require("./ImportPhase");
|
|
@@ -190,7 +191,7 @@ class HarmonyImportDependency extends ModuleDependency {
|
|
|
190
191
|
|
|
191
192
|
let importVar = importVarMap.get(importedModule);
|
|
192
193
|
if (importVar) return importVar;
|
|
193
|
-
importVar = `${Template.toIdentifier(
|
|
194
|
+
importVar = `${Template.toIdentifier(this.userRequest)}__WEBPACK_${
|
|
194
195
|
isDeferred ? "DEFERRED_" : ""
|
|
195
196
|
}IMPORTED_MODULE_${importVarMap.size}__`;
|
|
196
197
|
importVarMap.set(importedModule, importVar);
|
|
@@ -475,8 +476,18 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends
|
|
|
475
476
|
)
|
|
476
477
|
);
|
|
477
478
|
const importVar = dep.getImportVar(templateContext.moduleGraph);
|
|
479
|
+
// When the consuming module is emitted as a generator (target without
|
|
480
|
+
// `async`/`await`), the dependency `await` must become `yield`.
|
|
481
|
+
const generatorLowered = isGeneratorLowered(
|
|
482
|
+
/** @type {Module} */ (module),
|
|
483
|
+
moduleGraph,
|
|
484
|
+
templateContext.runtimeTemplate
|
|
485
|
+
);
|
|
478
486
|
templateContext.initFragments.push(
|
|
479
|
-
new AwaitDependenciesInitFragment(
|
|
487
|
+
new AwaitDependenciesInitFragment(
|
|
488
|
+
new Map([[importVar, importVar]]),
|
|
489
|
+
generatorLowered
|
|
490
|
+
)
|
|
480
491
|
);
|
|
481
492
|
templateContext.initFragments.push(
|
|
482
493
|
new ConditionalInitFragment(
|
|
@@ -237,7 +237,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
237
237
|
: "",
|
|
238
238
|
/** @type {Range} */ (statement.range)
|
|
239
239
|
);
|
|
240
|
-
clearDep.loc =
|
|
240
|
+
clearDep.loc = parser.getLocation(statement);
|
|
241
241
|
parser.state.module.addPresentationalDependency(clearDep);
|
|
242
242
|
parser.unsetAsiPosition(/** @type {Range} */ (statement.range)[1]);
|
|
243
243
|
const attributes = getImportAttributes(statement);
|
|
@@ -250,7 +250,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
250
250
|
const error = new WebpackError(
|
|
251
251
|
"Deferred import can only be used with `import * as namespace from '...'` syntax."
|
|
252
252
|
);
|
|
253
|
-
error.loc = statement
|
|
253
|
+
error.loc = parser.getLocation(statement) || undefined;
|
|
254
254
|
parser.state.current.addError(error);
|
|
255
255
|
}
|
|
256
256
|
|
|
@@ -260,7 +260,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
260
260
|
phase,
|
|
261
261
|
attributes
|
|
262
262
|
);
|
|
263
|
-
sideEffectDep.loc =
|
|
263
|
+
sideEffectDep.loc = parser.getLocation(statement);
|
|
264
264
|
parser.state.module.addDependency(sideEffectDep);
|
|
265
265
|
return true;
|
|
266
266
|
});
|
|
@@ -307,7 +307,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
307
307
|
dep.asiSafe = !parser.isAsiPosition(
|
|
308
308
|
/** @type {Range} */ (expression.range)[0]
|
|
309
309
|
);
|
|
310
|
-
dep.loc =
|
|
310
|
+
dep.loc = parser.getLocation(expression);
|
|
311
311
|
parser.state.module.addDependency(dep);
|
|
312
312
|
getInnerGraphUtils(parser.state.compilation).onUsage(
|
|
313
313
|
parser.state,
|
|
@@ -353,7 +353,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
353
353
|
dep.asiSafe = !parser.isAsiPosition(
|
|
354
354
|
/** @type {Range} */ (expr.range)[0]
|
|
355
355
|
);
|
|
356
|
-
dep.loc =
|
|
356
|
+
dep.loc = parser.getLocation(expr);
|
|
357
357
|
dep.call = parser.scope.inTaggedTemplateTag;
|
|
358
358
|
parser.state.module.addDependency(dep);
|
|
359
359
|
attachDependencyGuards(parser, dep);
|
|
@@ -406,7 +406,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
406
406
|
/** @type {Range} */
|
|
407
407
|
(expr.range)[0]
|
|
408
408
|
);
|
|
409
|
-
dep.loc =
|
|
409
|
+
dep.loc = parser.getLocation(expr);
|
|
410
410
|
parser.state.module.addDependency(dep);
|
|
411
411
|
attachDependencyGuards(parser, dep);
|
|
412
412
|
getInnerGraphUtils(parser.state.compilation).onUsage(
|
|
@@ -463,7 +463,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
463
463
|
dep.namespaceObjectAsContext =
|
|
464
464
|
members.length > 0 &&
|
|
465
465
|
/** @type {boolean} */ (this.strictThisContextOnImports);
|
|
466
|
-
dep.loc =
|
|
466
|
+
dep.loc = parser.getLocation(expr);
|
|
467
467
|
parser.state.module.addDependency(dep);
|
|
468
468
|
attachDependencyGuards(parser, dep);
|
|
469
469
|
if (args) parser.walkExpressions(args);
|
|
@@ -504,7 +504,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
504
504
|
}
|
|
505
505
|
const dependencies = requests.map((request) => {
|
|
506
506
|
const dep = new HarmonyAcceptImportDependency(request);
|
|
507
|
-
dep.loc =
|
|
507
|
+
dep.loc = parser.getLocation(expr);
|
|
508
508
|
parser.state.module.addDependency(dep);
|
|
509
509
|
return dep;
|
|
510
510
|
});
|
|
@@ -515,7 +515,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
515
515
|
dependencies,
|
|
516
516
|
true
|
|
517
517
|
);
|
|
518
|
-
dep.loc =
|
|
518
|
+
dep.loc = parser.getLocation(expr);
|
|
519
519
|
parser.state.module.addDependency(dep);
|
|
520
520
|
}
|
|
521
521
|
});
|
|
@@ -526,7 +526,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
526
526
|
}
|
|
527
527
|
const dependencies = requests.map((request) => {
|
|
528
528
|
const dep = new HarmonyAcceptImportDependency(request);
|
|
529
|
-
dep.loc =
|
|
529
|
+
dep.loc = parser.getLocation(expr);
|
|
530
530
|
parser.state.module.addDependency(dep);
|
|
531
531
|
return dep;
|
|
532
532
|
});
|
|
@@ -537,7 +537,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
537
537
|
dependencies,
|
|
538
538
|
false
|
|
539
539
|
);
|
|
540
|
-
dep.loc =
|
|
540
|
+
dep.loc = parser.getLocation(expr);
|
|
541
541
|
parser.state.module.addDependency(dep);
|
|
542
542
|
}
|
|
543
543
|
});
|
|
@@ -32,6 +32,7 @@ const { ImportPhaseUtils } = require("./ImportPhase");
|
|
|
32
32
|
/** @typedef {import("../Module")} Module */
|
|
33
33
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
|
34
34
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
35
|
+
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
|
35
36
|
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
|
36
37
|
/** @typedef {import("../errors/WebpackError")} WebpackError */
|
|
37
38
|
/** @typedef {import("../javascript/JavascriptParser").DestructuringAssignmentProperties} DestructuringAssignmentProperties */
|
|
@@ -475,7 +476,8 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
|
|
475
476
|
dep,
|
|
476
477
|
source,
|
|
477
478
|
templateContext,
|
|
478
|
-
trimmedIds
|
|
479
|
+
trimmedIds,
|
|
480
|
+
connection
|
|
479
481
|
);
|
|
480
482
|
if (dep.shorthand) {
|
|
481
483
|
source.insert(trimmedRangeEnd, `: ${exportExpr}`);
|
|
@@ -521,13 +523,14 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
|
|
521
523
|
});
|
|
522
524
|
}
|
|
523
525
|
);
|
|
526
|
+
// loop-invariant: resolve the imported module's exports info once
|
|
527
|
+
const destructuredExportsInfo = moduleGraph.getExportsInfo(
|
|
528
|
+
/** @type {Module} */ (moduleGraph.getModule(dep))
|
|
529
|
+
);
|
|
524
530
|
for (const { ids, shorthand, range } of replacementsInDestructuring) {
|
|
525
531
|
/** @type {Ids} */
|
|
526
532
|
const concatedIds = [...prefixedIds, ...ids];
|
|
527
|
-
const
|
|
528
|
-
const used = moduleGraph
|
|
529
|
-
.getExportsInfo(module)
|
|
530
|
-
.getUsedName(concatedIds, runtime);
|
|
533
|
+
const used = destructuredExportsInfo.getUsedName(concatedIds, runtime);
|
|
531
534
|
if (!used) {
|
|
532
535
|
return;
|
|
533
536
|
} else if (used instanceof InlinedUsedName) {
|
|
@@ -559,12 +562,12 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
|
|
559
562
|
* @param {ReplaceSource} source source
|
|
560
563
|
* @param {DependencyTemplateContext} templateContext context
|
|
561
564
|
* @param {Ids} ids ids
|
|
565
|
+
* @param {ModuleGraphConnection | undefined} connection the resolved connection for dep
|
|
562
566
|
* @returns {string} generated code
|
|
563
567
|
*/
|
|
564
|
-
_getCodeForIds(dep, source, templateContext, ids) {
|
|
568
|
+
_getCodeForIds(dep, source, templateContext, ids, connection) {
|
|
565
569
|
const { moduleGraph, module, runtime, concatenationScope } =
|
|
566
570
|
templateContext;
|
|
567
|
-
const connection = moduleGraph.getConnection(dep);
|
|
568
571
|
/** @type {string} */
|
|
569
572
|
let exportExpr;
|
|
570
573
|
|
|
@@ -25,6 +25,7 @@ const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDepe
|
|
|
25
25
|
const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
|
|
26
26
|
|
|
27
27
|
const HarmonyTopLevelThisParserPlugin = require("./HarmonyTopLevelThisParserPlugin");
|
|
28
|
+
const TopLevelAwaitDependency = require("./TopLevelAwaitDependency");
|
|
28
29
|
|
|
29
30
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
|
30
31
|
/** @typedef {import("../Compiler")} Compiler */
|
|
@@ -62,6 +63,11 @@ class HarmonyModulesPlugin {
|
|
|
62
63
|
new HarmonyCompatibilityDependency.Template()
|
|
63
64
|
);
|
|
64
65
|
|
|
66
|
+
compilation.dependencyTemplates.set(
|
|
67
|
+
TopLevelAwaitDependency,
|
|
68
|
+
new TopLevelAwaitDependency.Template()
|
|
69
|
+
);
|
|
70
|
+
|
|
65
71
|
compilation.dependencyFactories.set(
|
|
66
72
|
HarmonyImportSideEffectDependency,
|
|
67
73
|
normalModuleFactory
|
|
@@ -29,7 +29,7 @@ class HarmonyTopLevelThisParserPlugin {
|
|
|
29
29
|
/** @type {Range} */ (node.range),
|
|
30
30
|
null
|
|
31
31
|
);
|
|
32
|
-
dep.loc =
|
|
32
|
+
dep.loc = parser.getLocation(node);
|
|
33
33
|
parser.state.module.addPresentationalDependency(dep);
|
|
34
34
|
return true;
|
|
35
35
|
}
|