webpack 5.100.2 → 5.101.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/README.md +12 -10
- package/bin/webpack.js +7 -7
- package/lib/APIPlugin.js +12 -14
- package/lib/AutomaticPrefetchPlugin.js +2 -2
- package/lib/BannerPlugin.js +4 -4
- package/lib/Cache.js +1 -1
- package/lib/CacheFacade.js +7 -7
- package/lib/CaseSensitiveModulesWarning.js +2 -2
- package/lib/Chunk.js +3 -3
- package/lib/ChunkGraph.js +63 -18
- package/lib/ChunkGroup.js +4 -4
- package/lib/CleanPlugin.js +19 -53
- package/lib/CodeGenerationResults.js +3 -3
- package/lib/CompatibilityPlugin.js +6 -6
- package/lib/Compilation.js +168 -116
- package/lib/Compiler.js +37 -37
- package/lib/ConcatenationScope.js +39 -1
- package/lib/ConstPlugin.js +11 -11
- package/lib/ContextExclusionPlugin.js +3 -3
- package/lib/ContextModule.js +12 -11
- package/lib/ContextModuleFactory.js +11 -11
- package/lib/ContextReplacementPlugin.js +5 -5
- package/lib/DefinePlugin.js +24 -22
- package/lib/DelegatedModuleFactoryPlugin.js +1 -1
- package/lib/Dependency.js +2 -1
- package/lib/DllEntryPlugin.js +1 -1
- package/lib/DllReferencePlugin.js +1 -1
- package/lib/DynamicEntryPlugin.js +3 -3
- package/lib/EntryPlugin.js +1 -1
- package/lib/EnvironmentPlugin.js +1 -1
- package/lib/ErrorHelpers.js +2 -2
- package/lib/EvalDevToolModulePlugin.js +2 -2
- package/lib/EvalSourceMapDevToolPlugin.js +5 -5
- package/lib/ExportsInfo.js +9 -9
- package/lib/ExportsInfoApiPlugin.js +2 -2
- package/lib/ExternalModule.js +163 -48
- package/lib/ExternalModuleFactoryPlugin.js +2 -2
- package/lib/ExternalsPlugin.js +45 -0
- package/lib/FileSystemInfo.js +64 -61
- package/lib/FlagAllModulesAsUsedPlugin.js +2 -2
- package/lib/FlagDependencyExportsPlugin.js +7 -7
- package/lib/FlagDependencyUsagePlugin.js +4 -4
- package/lib/FlagEntryExportAsUsedPlugin.js +1 -1
- package/lib/HotModuleReplacementPlugin.js +27 -27
- package/lib/IgnorePlugin.js +3 -3
- package/lib/IgnoreWarningsPlugin.js +4 -4
- package/lib/InitFragment.js +6 -0
- package/lib/InvalidDependenciesModuleWarning.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +1 -1
- package/lib/LibManifestPlugin.js +2 -2
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/LoaderTargetPlugin.js +2 -2
- package/lib/MainTemplate.js +1 -1
- package/lib/Module.js +3 -2
- package/lib/ModuleFilenameHelpers.js +3 -3
- package/lib/ModuleGraph.js +23 -38
- package/lib/ModuleInfoHeaderPlugin.js +3 -3
- package/lib/ModuleParseError.js +5 -3
- package/lib/ModuleTemplate.js +3 -2
- package/lib/MultiCompiler.js +29 -24
- package/lib/MultiStats.js +18 -13
- package/lib/MultiWatching.js +1 -1
- package/lib/NoEmitOnErrorsPlugin.js +2 -2
- package/lib/NodeStuffPlugin.js +27 -15
- package/lib/NormalModule.js +23 -23
- package/lib/NormalModuleFactory.js +23 -21
- package/lib/NormalModuleReplacementPlugin.js +3 -3
- package/lib/PrefetchPlugin.js +1 -1
- package/lib/ProgressPlugin.js +11 -11
- package/lib/ProvidePlugin.js +2 -2
- package/lib/RecordIdsPlugin.js +3 -3
- package/lib/ResolverFactory.js +3 -3
- package/lib/RuntimeGlobals.js +20 -0
- package/lib/RuntimePlugin.js +16 -16
- package/lib/RuntimeTemplate.js +35 -26
- package/lib/SizeFormatHelpers.js +1 -1
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -4
- package/lib/SourceMapDevToolPlugin.js +9 -9
- package/lib/Stats.js +2 -2
- package/lib/Template.js +1 -1
- package/lib/TemplatedPathPlugin.js +2 -2
- package/lib/UseStrictPlugin.js +1 -1
- package/lib/WarnCaseSensitiveModulesPlugin.js +1 -1
- package/lib/WarnDeprecatedOptionPlugin.js +1 -1
- package/lib/WarnNoModeSetPlugin.js +1 -1
- package/lib/WatchIgnorePlugin.js +2 -2
- package/lib/Watching.js +12 -14
- package/lib/WebpackIsIncludedPlugin.js +2 -2
- package/lib/WebpackOptionsApply.js +3 -3
- package/lib/asset/AssetGenerator.js +1 -1
- package/lib/asset/AssetModulesPlugin.js +6 -6
- package/lib/async-modules/AsyncModuleHelpers.js +1 -1
- package/lib/async-modules/AwaitDependenciesInitFragment.js +36 -24
- package/lib/async-modules/InferAsyncModulesPlugin.js +3 -3
- package/lib/buildChunkGraph.js +5 -5
- package/lib/cache/AddBuildDependenciesPlugin.js +1 -1
- package/lib/cache/IdleFileCachePlugin.js +5 -5
- package/lib/cache/PackFileCacheStrategy.js +20 -20
- package/lib/cache/ResolverCachePlugin.js +4 -4
- package/lib/cli.js +196 -14
- package/lib/config/browserslistTargetHandler.js +6 -6
- package/lib/config/defaults.js +23 -14
- package/lib/config/normalization.js +41 -38
- package/lib/config/target.js +4 -4
- package/lib/container/ContainerEntryModule.js +3 -3
- package/lib/container/ContainerPlugin.js +3 -3
- package/lib/container/ContainerReferencePlugin.js +3 -3
- package/lib/container/FallbackModule.js +1 -1
- package/lib/container/HoistContainerReferencesPlugin.js +7 -7
- package/lib/container/options.js +4 -4
- package/lib/css/CssGenerator.js +5 -3
- package/lib/css/CssLoadingRuntimeModule.js +1 -1
- package/lib/css/CssModulesPlugin.js +25 -22
- package/lib/css/CssParser.js +5 -5
- package/lib/css/walkCssTokens.js +9 -9
- package/lib/debug/ProfilingPlugin.js +5 -5
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +4 -4
- package/lib/dependencies/AMDPlugin.js +3 -3
- package/lib/dependencies/AMDRequireArrayDependency.js +1 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +3 -3
- package/lib/dependencies/CommonJsExportRequireDependency.js +2 -2
- package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -10
- package/lib/dependencies/CommonJsImportsParserPlugin.js +21 -19
- package/lib/dependencies/CommonJsPlugin.js +2 -2
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/CssIcssExportDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssUrlDependency.js +4 -4
- package/lib/dependencies/DynamicExports.js +5 -5
- package/lib/dependencies/HarmonyAcceptDependency.js +91 -5
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +2 -2
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +17 -13
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +7 -8
- package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
- package/lib/dependencies/HarmonyExports.js +1 -1
- package/lib/dependencies/HarmonyImportDependency.js +28 -9
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +56 -48
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -5
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +3 -4
- package/lib/dependencies/HarmonyModulesPlugin.js +2 -8
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -4
- package/lib/dependencies/ImportMetaPlugin.js +7 -7
- package/lib/dependencies/ImportParserPlugin.js +4 -4
- package/lib/dependencies/JsonExportsDependency.js +7 -2
- package/lib/dependencies/LoaderPlugin.js +4 -4
- package/lib/dependencies/ModuleDependency.js +2 -1
- package/lib/dependencies/ProvidedDependency.js +2 -2
- package/lib/dependencies/PureExpressionDependency.js +1 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -1
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -3
- package/lib/dependencies/SystemPlugin.js +3 -3
- package/lib/dependencies/WorkerPlugin.js +5 -5
- package/lib/dependencies/getFunctionExpression.js +1 -1
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +8 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +35 -69
- package/lib/esm/ModuleChunkLoadingPlugin.js +3 -6
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +15 -11
- package/lib/formatLocation.js +2 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +39 -27
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +43 -32
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +1 -1
- package/lib/hmr/LazyCompilationPlugin.js +6 -6
- package/lib/hmr/lazyCompilationBackend.js +6 -6
- package/lib/ids/ChunkModuleIdRangePlugin.js +4 -4
- package/lib/ids/DeterministicChunkIdsPlugin.js +5 -4
- package/lib/ids/DeterministicModuleIdsPlugin.js +2 -2
- package/lib/ids/HashedModuleIdsPlugin.js +1 -1
- package/lib/ids/IdHelpers.js +9 -9
- package/lib/ids/NamedChunkIdsPlugin.js +5 -5
- package/lib/ids/NamedModuleIdsPlugin.js +2 -2
- package/lib/ids/NaturalChunkIdsPlugin.js +2 -2
- package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -4
- package/lib/ids/SyncModuleIdsPlugin.js +4 -4
- package/lib/index.js +18 -6
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +1 -1
- package/lib/javascript/BasicEvaluatedExpression.js +3 -3
- package/lib/javascript/ChunkFormatHelpers.js +70 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +10 -21
- package/lib/javascript/EnableChunkLoadingPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +1 -1
- package/lib/javascript/JavascriptModulesPlugin.js +108 -54
- package/lib/javascript/JavascriptParser.js +80 -78
- package/lib/javascript/JavascriptParserHelpers.js +3 -3
- package/lib/javascript/StartupHelpers.js +2 -2
- package/lib/json/JsonGenerator.js +2 -2
- package/lib/json/JsonModulesPlugin.js +2 -2
- package/lib/library/AbstractLibraryPlugin.js +30 -3
- package/lib/library/AmdLibraryPlugin.js +3 -3
- package/lib/library/AssignLibraryPlugin.js +2 -2
- package/lib/library/EnableLibraryPlugin.js +2 -2
- package/lib/library/ModuleLibraryPlugin.js +49 -31
- package/lib/library/SystemLibraryPlugin.js +6 -4
- package/lib/library/UmdLibraryPlugin.js +14 -14
- package/lib/logging/createConsoleLogger.js +4 -4
- package/lib/logging/runtime.js +3 -3
- package/lib/logging/truncateArgs.js +4 -4
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -2
- package/lib/node/NodeEnvironmentPlugin.js +1 -1
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +16 -14
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +7 -7
- package/lib/node/ReadFileCompileWasmPlugin.js +7 -7
- package/lib/node/RequireChunkLoadingRuntimeModule.js +13 -6
- package/lib/node/nodeConsole.js +2 -2
- package/lib/optimize/AggressiveMergingPlugin.js +2 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +10 -10
- package/lib/optimize/ConcatenatedModule.js +186 -77
- package/lib/optimize/EnsureChunkConditionsPlugin.js +2 -2
- package/lib/optimize/FlagIncludedChunksPlugin.js +2 -2
- package/lib/optimize/InnerGraph.js +5 -5
- package/lib/optimize/InnerGraphPlugin.js +14 -12
- package/lib/optimize/LimitChunkCountPlugin.js +5 -5
- package/lib/optimize/MangleExportsPlugin.js +5 -5
- package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
- package/lib/optimize/MinChunkSizePlugin.js +3 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +45 -38
- package/lib/optimize/RealContentHashPlugin.js +23 -23
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +3 -3
- package/lib/optimize/RuntimeChunkPlugin.js +2 -2
- package/lib/optimize/SideEffectsFlagPlugin.js +5 -5
- package/lib/optimize/SplitChunksPlugin.js +20 -20
- package/lib/performance/AssetsOverSizeLimitWarning.js +1 -1
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
- package/lib/performance/SizeLimitsPlugin.js +4 -4
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +1 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -3
- package/lib/rules/BasicMatcherRulePlugin.js +1 -1
- package/lib/rules/RuleSetCompiler.js +10 -10
- package/lib/rules/UseEffectRulePlugin.js +2 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +19 -15
- package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +1 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +3 -3
- package/lib/schemes/DataUriPlugin.js +3 -3
- package/lib/schemes/FileUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +40 -36
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +11 -11
- package/lib/serialization/FileMiddleware.js +18 -17
- package/lib/serialization/ObjectMiddleware.js +8 -8
- package/lib/serialization/Serializer.js +2 -2
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/sharing/ConsumeSharedPlugin.js +4 -4
- package/lib/sharing/ProvideSharedPlugin.js +4 -4
- package/lib/sharing/SharePlugin.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +85 -80
- package/lib/stats/DefaultStatsPresetPlugin.js +15 -15
- package/lib/stats/DefaultStatsPrinterPlugin.js +87 -87
- package/lib/stats/StatsFactory.js +7 -7
- package/lib/stats/StatsPrinter.js +9 -9
- package/lib/url/URLParserPlugin.js +5 -5
- package/lib/util/AsyncQueue.js +4 -4
- package/lib/util/IterableHelpers.js +2 -2
- package/lib/util/LazyBucketSortedSet.js +3 -3
- package/lib/util/SetHelpers.js +2 -2
- package/lib/util/StackedCacheMap.js +1 -1
- package/lib/util/StackedMap.js +1 -1
- package/lib/util/TupleSet.js +1 -1
- package/lib/util/WeakTupleMap.js +1 -1
- package/lib/util/cleverMerge.js +8 -8
- package/lib/util/comparators.js +10 -10
- package/lib/util/compileBooleanMatcher.js +20 -20
- package/lib/util/concatenate.js +3 -3
- package/lib/util/conventions.js +4 -4
- package/lib/util/create-schema-validation.js +1 -1
- package/lib/util/createHash.js +1 -1
- package/lib/util/deprecation.js +4 -4
- package/lib/util/deterministicGrouping.js +7 -7
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +4 -4
- package/lib/util/identifier.js +14 -14
- package/lib/util/magicComment.js +5 -1
- package/lib/util/memoize.js +1 -1
- package/lib/util/processAsyncTree.js +2 -2
- package/lib/util/propertyName.js +1 -1
- package/lib/util/removeBOM.js +1 -1
- package/lib/util/runtime.js +6 -6
- package/lib/util/semver.js +16 -16
- package/lib/util/serialization.js +5 -5
- package/lib/util/smartGrouping.js +1 -1
- package/lib/validateSchema.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +1 -1
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -4
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +13 -9
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +16 -17
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +4 -2
- package/lib/wasm-sync/WebAssemblyParser.js +2 -2
- package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -4
- package/lib/web/FetchCompileWasmPlugin.js +4 -4
- package/lib/web/JsonpChunkLoadingPlugin.js +2 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/webpack.js +17 -12
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +2 -2
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +16 -16
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +4 -0
- package/types.d.ts +275 -64
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const Template = require("../Template");
|
|
9
|
+
const AwaitDependenciesInitFragment = require("../async-modules/AwaitDependenciesInitFragment");
|
|
9
10
|
const makeSerializable = require("../util/makeSerializable");
|
|
10
11
|
const HarmonyImportDependency = require("./HarmonyImportDependency");
|
|
11
12
|
const NullDependency = require("./NullDependency");
|
|
@@ -17,6 +18,8 @@ const NullDependency = require("./NullDependency");
|
|
|
17
18
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
18
19
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
19
20
|
/** @typedef {import("./HarmonyAcceptImportDependency")} HarmonyAcceptImportDependency */
|
|
21
|
+
/** @typedef {import("../Module")} Module */
|
|
22
|
+
/** @typedef {import("../Module").ModuleId} ModuleId */
|
|
20
23
|
|
|
21
24
|
class HarmonyAcceptDependency extends NullDependency {
|
|
22
25
|
/**
|
|
@@ -82,8 +85,75 @@ HarmonyAcceptDependency.Template = class HarmonyAcceptDependencyTemplate extends
|
|
|
82
85
|
moduleGraph,
|
|
83
86
|
chunkGraph
|
|
84
87
|
} = templateContext;
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @param {Dependency} dependency the dependency to get module id for
|
|
91
|
+
* @returns {ModuleId | null} the module id or null if not found
|
|
92
|
+
*/
|
|
93
|
+
const getDependencyModuleId = (dependency) =>
|
|
94
|
+
chunkGraph.getModuleId(
|
|
95
|
+
/** @type {Module} */ (moduleGraph.getModule(dependency))
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @param {Dependency} a the first dependency
|
|
100
|
+
* @param {Dependency} b the second dependency
|
|
101
|
+
* @returns {boolean} true if the dependencies are related
|
|
102
|
+
*/
|
|
103
|
+
const isRelatedHarmonyImportDependency = (a, b) =>
|
|
104
|
+
a !== b &&
|
|
105
|
+
b instanceof HarmonyImportDependency &&
|
|
106
|
+
getDependencyModuleId(a) === getDependencyModuleId(b);
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* HarmonyAcceptImportDependency lacks a lot of information, such as the defer property.
|
|
110
|
+
* One HarmonyAcceptImportDependency may need to generate multiple ImportStatements.
|
|
111
|
+
* Therefore, we find its original HarmonyImportDependency for code generation.
|
|
112
|
+
* @param {HarmonyAcceptImportDependency} dependency the dependency to get harmony import dependencies for
|
|
113
|
+
* @returns {HarmonyImportDependency[]} array of related harmony import dependencies
|
|
114
|
+
*/
|
|
115
|
+
const getHarmonyImportDependencies = (dependency) => {
|
|
116
|
+
const result = [];
|
|
117
|
+
let deferDependency = null;
|
|
118
|
+
let noDeferredDependency = null;
|
|
119
|
+
|
|
120
|
+
for (const d of module.dependencies) {
|
|
121
|
+
if (deferDependency && noDeferredDependency) break;
|
|
122
|
+
if (isRelatedHarmonyImportDependency(dependency, d)) {
|
|
123
|
+
if (d.defer) {
|
|
124
|
+
deferDependency = /** @type {HarmonyImportDependency} */ (d);
|
|
125
|
+
} else {
|
|
126
|
+
noDeferredDependency = /** @type {HarmonyImportDependency} */ (d);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (deferDependency) result.push(deferDependency);
|
|
131
|
+
if (noDeferredDependency) result.push(noDeferredDependency);
|
|
132
|
+
if (result.length === 0) {
|
|
133
|
+
// fallback to the original dependency
|
|
134
|
+
result.push(dependency);
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/** @type {HarmonyImportDependency[]} */
|
|
140
|
+
const syncDeps = [];
|
|
141
|
+
|
|
142
|
+
/** @type {HarmonyAcceptImportDependency[]} */
|
|
143
|
+
const asyncDeps = [];
|
|
144
|
+
|
|
145
|
+
for (const dependency of dep.dependencies) {
|
|
146
|
+
const connection = moduleGraph.getConnection(dependency);
|
|
147
|
+
|
|
148
|
+
if (connection && moduleGraph.isAsync(connection.module)) {
|
|
149
|
+
asyncDeps.push(dependency);
|
|
150
|
+
} else {
|
|
151
|
+
syncDeps.push(...getHarmonyImportDependencies(dependency));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let content = syncDeps
|
|
156
|
+
.map((dependency) => {
|
|
87
157
|
const referencedModule = moduleGraph.getModule(dependency);
|
|
88
158
|
return {
|
|
89
159
|
dependency,
|
|
@@ -112,17 +182,33 @@ HarmonyAcceptDependency.Template = class HarmonyAcceptDependencyTemplate extends
|
|
|
112
182
|
})
|
|
113
183
|
.join("");
|
|
114
184
|
|
|
185
|
+
const promises = new Map(
|
|
186
|
+
asyncDeps.map((dependency) => [
|
|
187
|
+
dependency.getImportVar(moduleGraph),
|
|
188
|
+
dependency.getModuleExports(templateContext)
|
|
189
|
+
])
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
let optAsync = "";
|
|
193
|
+
if (promises.size !== 0) {
|
|
194
|
+
optAsync = "async ";
|
|
195
|
+
content += new AwaitDependenciesInitFragment(promises).getContent({
|
|
196
|
+
...templateContext,
|
|
197
|
+
type: "javascript"
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
115
201
|
if (dep.hasCallback) {
|
|
116
202
|
if (runtimeTemplate.supportsArrowFunction()) {
|
|
117
203
|
source.insert(
|
|
118
204
|
dep.range[0],
|
|
119
|
-
|
|
205
|
+
`${optAsync}__WEBPACK_OUTDATED_DEPENDENCIES__ => { ${content} return (`
|
|
120
206
|
);
|
|
121
207
|
source.insert(dep.range[1], ")(__WEBPACK_OUTDATED_DEPENDENCIES__); }");
|
|
122
208
|
} else {
|
|
123
209
|
source.insert(
|
|
124
210
|
dep.range[0],
|
|
125
|
-
|
|
211
|
+
`${optAsync}function(__WEBPACK_OUTDATED_DEPENDENCIES__) { ${content} return (`
|
|
126
212
|
);
|
|
127
213
|
source.insert(
|
|
128
214
|
dep.range[1],
|
|
@@ -135,7 +221,7 @@ HarmonyAcceptDependency.Template = class HarmonyAcceptDependencyTemplate extends
|
|
|
135
221
|
const arrow = runtimeTemplate.supportsArrowFunction();
|
|
136
222
|
source.insert(
|
|
137
223
|
dep.range[1] - 0.5,
|
|
138
|
-
`, ${arrow ?
|
|
224
|
+
`, ${arrow ? `${optAsync}() =>` : `${optAsync}function()`} { ${content} }`
|
|
139
225
|
);
|
|
140
226
|
}
|
|
141
227
|
};
|
|
@@ -31,13 +31,13 @@ module.exports = class HarmonyDetectionParserPlugin {
|
|
|
31
31
|
* @returns {void}
|
|
32
32
|
*/
|
|
33
33
|
apply(parser) {
|
|
34
|
-
parser.hooks.program.tap(PLUGIN_NAME, ast => {
|
|
34
|
+
parser.hooks.program.tap(PLUGIN_NAME, (ast) => {
|
|
35
35
|
const isStrictHarmony =
|
|
36
36
|
parser.state.module.type === JAVASCRIPT_MODULE_TYPE_ESM;
|
|
37
37
|
const isHarmony =
|
|
38
38
|
isStrictHarmony ||
|
|
39
39
|
ast.body.some(
|
|
40
|
-
statement =>
|
|
40
|
+
(statement) =>
|
|
41
41
|
statement.type === "ImportDeclaration" ||
|
|
42
42
|
statement.type === "ExportDefaultDeclaration" ||
|
|
43
43
|
statement.type === "ExportNamedDeclaration" ||
|
|
@@ -33,9 +33,8 @@ const PLUGIN_NAME = "HarmonyExportDependencyParserPlugin";
|
|
|
33
33
|
module.exports = class HarmonyExportDependencyParserPlugin {
|
|
34
34
|
/**
|
|
35
35
|
* @param {import("../../declarations/WebpackOptions").JavascriptParserOptions} options options
|
|
36
|
-
* @param {boolean=} deferImport defer import enabled
|
|
37
36
|
*/
|
|
38
|
-
constructor(options
|
|
37
|
+
constructor(options) {
|
|
39
38
|
this.exportPresenceMode =
|
|
40
39
|
options.reexportExportsPresence !== undefined
|
|
41
40
|
? ExportPresenceModes.fromUserOption(options.reexportExportsPresence)
|
|
@@ -44,7 +43,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
44
43
|
: options.strictExportPresence
|
|
45
44
|
? ExportPresenceModes.ERROR
|
|
46
45
|
: ExportPresenceModes.AUTO;
|
|
47
|
-
this.deferImport = deferImport;
|
|
46
|
+
this.deferImport = options.deferImport;
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
/**
|
|
@@ -53,7 +52,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
53
52
|
*/
|
|
54
53
|
apply(parser) {
|
|
55
54
|
const { exportPresenceMode } = this;
|
|
56
|
-
parser.hooks.export.tap(PLUGIN_NAME, statement => {
|
|
55
|
+
parser.hooks.export.tap(PLUGIN_NAME, (statement) => {
|
|
57
56
|
const dep = new HarmonyExportHeaderDependency(
|
|
58
57
|
/** @type {Range | false} */ (
|
|
59
58
|
statement.declaration && statement.declaration.range
|
|
@@ -77,13 +76,16 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
77
76
|
clearDep.loc = /** @type {DependencyLocation} */ (statement.loc);
|
|
78
77
|
clearDep.loc.index = -1;
|
|
79
78
|
parser.state.module.addPresentationalDependency(clearDep);
|
|
80
|
-
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
79
|
+
let defer = false;
|
|
80
|
+
if (this.deferImport) {
|
|
81
|
+
({ defer } = getImportMode(parser, statement));
|
|
82
|
+
if (defer) {
|
|
83
|
+
const error = new WebpackError(
|
|
84
|
+
"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 };"
|
|
85
|
+
);
|
|
86
|
+
error.loc = statement.loc || undefined;
|
|
87
|
+
parser.state.current.addError(error);
|
|
88
|
+
}
|
|
87
89
|
}
|
|
88
90
|
const sideEffectDep = new HarmonyImportSideEffectDependency(
|
|
89
91
|
/** @type {string} */ (source),
|
|
@@ -107,7 +109,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
107
109
|
exprRange,
|
|
108
110
|
statementRange,
|
|
109
111
|
comments
|
|
110
|
-
.map(c => {
|
|
112
|
+
.map((c) => {
|
|
111
113
|
switch (c.type) {
|
|
112
114
|
case "Block":
|
|
113
115
|
return `/*${c.value}*/`;
|
|
@@ -202,7 +204,9 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
|
202
204
|
parser.state.harmonyStarExports || new HarmonyStarExportsList();
|
|
203
205
|
}
|
|
204
206
|
const attributes = getImportAttributes(statement);
|
|
205
|
-
const
|
|
207
|
+
const defer = this.deferImport
|
|
208
|
+
? getImportMode(parser, statement).defer
|
|
209
|
+
: false;
|
|
206
210
|
const dep = new HarmonyExportImportedSpecifierDependency(
|
|
207
211
|
/** @type {string} */
|
|
208
212
|
(source),
|
|
@@ -334,7 +334,7 @@ const getMode = (moduleGraph, dep, runtimeKey) => {
|
|
|
334
334
|
|
|
335
335
|
mode.items = Array.from(
|
|
336
336
|
exports,
|
|
337
|
-
exportName =>
|
|
337
|
+
(exportName) =>
|
|
338
338
|
new NormalReexportItem(
|
|
339
339
|
exportName,
|
|
340
340
|
[exportName],
|
|
@@ -378,7 +378,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
|
378
378
|
* @param {ExportPresenceMode} exportPresenceMode mode of checking export names
|
|
379
379
|
* @param {HarmonyStarExportsList | null} allStarExports all star exports in the module
|
|
380
380
|
* @param {ImportAttributes=} attributes import attributes
|
|
381
|
-
* @param {boolean=}
|
|
381
|
+
* @param {boolean=} defer is defer phase
|
|
382
382
|
*/
|
|
383
383
|
constructor(
|
|
384
384
|
request,
|
|
@@ -390,9 +390,9 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
|
390
390
|
exportPresenceMode,
|
|
391
391
|
allStarExports,
|
|
392
392
|
attributes,
|
|
393
|
-
|
|
393
|
+
defer
|
|
394
394
|
) {
|
|
395
|
-
super(request, sourceOrder, attributes);
|
|
395
|
+
super(request, sourceOrder, attributes, defer);
|
|
396
396
|
|
|
397
397
|
this.ids = ids;
|
|
398
398
|
this.name = name;
|
|
@@ -400,7 +400,6 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
|
400
400
|
this.otherStarExports = otherStarExports;
|
|
401
401
|
this.exportPresenceMode = exportPresenceMode;
|
|
402
402
|
this.allStarExports = allStarExports;
|
|
403
|
-
this.defer = deferEvaluation;
|
|
404
403
|
}
|
|
405
404
|
|
|
406
405
|
/**
|
|
@@ -722,7 +721,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
|
722
721
|
return {
|
|
723
722
|
exports: Array.from(
|
|
724
723
|
/** @type {NormalReexportItem[]} */ (mode.items),
|
|
725
|
-
item => ({
|
|
724
|
+
(item) => ({
|
|
726
725
|
name: item.name,
|
|
727
726
|
from,
|
|
728
727
|
export: item.ids,
|
|
@@ -930,7 +929,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
|
930
929
|
}' contains conflicting star exports for the ${
|
|
931
930
|
exports.length > 1 ? "names" : "name"
|
|
932
931
|
} ${exports
|
|
933
|
-
.map(e => `'${e}'`)
|
|
932
|
+
.map((e) => `'${e}'`)
|
|
934
933
|
.join(", ")} with the previous requested module '${request}'`
|
|
935
934
|
)
|
|
936
935
|
);
|
|
@@ -1190,7 +1189,7 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
|
1190
1189
|
const runtimeCondition = dep.weak
|
|
1191
1190
|
? false
|
|
1192
1191
|
: connection
|
|
1193
|
-
? filterRuntime(runtime, r => connection.isTargetActive(r))
|
|
1192
|
+
? filterRuntime(runtime, (r) => connection.isTargetActive(r))
|
|
1194
1193
|
: true;
|
|
1195
1194
|
initFragments.push(
|
|
1196
1195
|
new ConditionalInitFragment(
|
|
@@ -17,7 +17,7 @@ const { propertyName } = require("../util/propertyName");
|
|
|
17
17
|
* @param {Iterable<string>} iterable iterable strings
|
|
18
18
|
* @returns {string} result
|
|
19
19
|
*/
|
|
20
|
-
const joinIterableWithComma = iterable => {
|
|
20
|
+
const joinIterableWithComma = (iterable) => {
|
|
21
21
|
// This is more performant than Array.from().join(", ")
|
|
22
22
|
// as it doesn't create an array
|
|
23
23
|
let str = "";
|
|
@@ -40,7 +40,7 @@ module.exports.enable = (parserState, isStrictHarmony) => {
|
|
|
40
40
|
* @param {ParserState} parserState parser state
|
|
41
41
|
* @returns {boolean} true, when enabled
|
|
42
42
|
*/
|
|
43
|
-
module.exports.isEnabled = parserState => {
|
|
43
|
+
module.exports.isEnabled = (parserState) => {
|
|
44
44
|
const value = parserStateExportsState.get(parserState);
|
|
45
45
|
return value === true;
|
|
46
46
|
};
|
|
@@ -64,11 +64,13 @@ class HarmonyImportDependency extends ModuleDependency {
|
|
|
64
64
|
* @param {string} request request string
|
|
65
65
|
* @param {number} sourceOrder source order
|
|
66
66
|
* @param {ImportAttributes=} attributes import attributes
|
|
67
|
+
* @param {boolean=} defer import attributes
|
|
67
68
|
*/
|
|
68
|
-
constructor(request, sourceOrder, attributes) {
|
|
69
|
+
constructor(request, sourceOrder, attributes, defer) {
|
|
69
70
|
super(request);
|
|
70
71
|
this.sourceOrder = sourceOrder;
|
|
71
72
|
this.assertions = attributes;
|
|
73
|
+
this.defer = defer;
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
get category() {
|
|
@@ -112,6 +114,24 @@ class HarmonyImportDependency extends ModuleDependency {
|
|
|
112
114
|
return importVar;
|
|
113
115
|
}
|
|
114
116
|
|
|
117
|
+
/**
|
|
118
|
+
* @param {DependencyTemplateContext} context the template context
|
|
119
|
+
* @returns {string} the expression
|
|
120
|
+
*/
|
|
121
|
+
getModuleExports({
|
|
122
|
+
runtimeTemplate,
|
|
123
|
+
moduleGraph,
|
|
124
|
+
chunkGraph,
|
|
125
|
+
runtimeRequirements
|
|
126
|
+
}) {
|
|
127
|
+
return runtimeTemplate.moduleExports({
|
|
128
|
+
module: moduleGraph.getModule(this),
|
|
129
|
+
chunkGraph,
|
|
130
|
+
request: this.request,
|
|
131
|
+
runtimeRequirements
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
115
135
|
/**
|
|
116
136
|
* @param {boolean} update create new variables or update existing one
|
|
117
137
|
* @param {DependencyTemplateContext} templateContext the template context
|
|
@@ -183,7 +203,7 @@ class HarmonyImportDependency extends ModuleDependency {
|
|
|
183
203
|
new HarmonyLinkingError(
|
|
184
204
|
`export ${ids
|
|
185
205
|
.slice(0, pos)
|
|
186
|
-
.map(id => `'${id}'`)
|
|
206
|
+
.map((id) => `'${id}'`)
|
|
187
207
|
.join(".")} ${additionalMessage} was not found in '${
|
|
188
208
|
this.userRequest
|
|
189
209
|
}'${moreInfo}`
|
|
@@ -199,7 +219,7 @@ class HarmonyImportDependency extends ModuleDependency {
|
|
|
199
219
|
return [
|
|
200
220
|
new HarmonyLinkingError(
|
|
201
221
|
`export ${ids
|
|
202
|
-
.map(id => `'${id}'`)
|
|
222
|
+
.map((id) => `'${id}'`)
|
|
203
223
|
.join(".")} ${additionalMessage} was not found in '${
|
|
204
224
|
this.userRequest
|
|
205
225
|
}'`
|
|
@@ -215,7 +235,7 @@ class HarmonyImportDependency extends ModuleDependency {
|
|
|
215
235
|
return [
|
|
216
236
|
new HarmonyLinkingError(
|
|
217
237
|
`Can't import the named export ${ids
|
|
218
|
-
.map(id => `'${id}'`)
|
|
238
|
+
.map((id) => `'${id}'`)
|
|
219
239
|
.join(
|
|
220
240
|
"."
|
|
221
241
|
)} ${additionalMessage} from default-exporting module (only default export is available)`
|
|
@@ -236,7 +256,7 @@ class HarmonyImportDependency extends ModuleDependency {
|
|
|
236
256
|
return [
|
|
237
257
|
new HarmonyLinkingError(
|
|
238
258
|
`Should not import the named export ${ids
|
|
239
|
-
.map(id => `'${id}'`)
|
|
259
|
+
.map((id) => `'${id}'`)
|
|
240
260
|
.join(
|
|
241
261
|
"."
|
|
242
262
|
)} ${additionalMessage} from default-exporting module (only default export is available soon)`
|
|
@@ -310,7 +330,7 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends
|
|
|
310
330
|
const runtimeCondition = dep.weak
|
|
311
331
|
? false
|
|
312
332
|
: connection
|
|
313
|
-
? filterRuntime(runtime, r => connection.isTargetActive(r))
|
|
333
|
+
? filterRuntime(runtime, (r) => connection.isTargetActive(r))
|
|
314
334
|
: true;
|
|
315
335
|
|
|
316
336
|
if (module && referencedModule) {
|
|
@@ -348,10 +368,9 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends
|
|
|
348
368
|
runtimeCondition
|
|
349
369
|
)
|
|
350
370
|
);
|
|
371
|
+
const importVar = dep.getImportVar(templateContext.moduleGraph);
|
|
351
372
|
templateContext.initFragments.push(
|
|
352
|
-
new AwaitDependenciesInitFragment(
|
|
353
|
-
new Set([dep.getImportVar(templateContext.moduleGraph)])
|
|
354
|
-
)
|
|
373
|
+
new AwaitDependenciesInitFragment(new Map([[importVar, importVar]]))
|
|
355
374
|
);
|
|
356
375
|
templateContext.initFragments.push(
|
|
357
376
|
new ConditionalInitFragment(
|
|
@@ -59,9 +59,8 @@ const PLUGIN_NAME = "HarmonyImportDependencyParserPlugin";
|
|
|
59
59
|
module.exports = class HarmonyImportDependencyParserPlugin {
|
|
60
60
|
/**
|
|
61
61
|
* @param {JavascriptParserOptions} options options
|
|
62
|
-
* @param {boolean | undefined} deferImport defer import enabled
|
|
63
62
|
*/
|
|
64
|
-
constructor(options
|
|
63
|
+
constructor(options) {
|
|
65
64
|
this.exportPresenceMode =
|
|
66
65
|
options.importExportsPresence !== undefined
|
|
67
66
|
? ExportPresenceModes.fromUserOption(options.importExportsPresence)
|
|
@@ -71,7 +70,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
71
70
|
? ExportPresenceModes.ERROR
|
|
72
71
|
: ExportPresenceModes.AUTO;
|
|
73
72
|
this.strictThisContextOnImports = options.strictThisContextOnImports;
|
|
74
|
-
this.deferImport = deferImport;
|
|
73
|
+
this.deferImport = options.deferImport;
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
/**
|
|
@@ -102,7 +101,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
102
101
|
return node;
|
|
103
102
|
}
|
|
104
103
|
|
|
105
|
-
parser.hooks.isPure.for("Identifier").tap(PLUGIN_NAME, expression => {
|
|
104
|
+
parser.hooks.isPure.for("Identifier").tap(PLUGIN_NAME, (expression) => {
|
|
106
105
|
const expr = /** @type {Identifier} */ (expression);
|
|
107
106
|
if (
|
|
108
107
|
parser.isVariableDefined(expr.name) ||
|
|
@@ -124,17 +123,20 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
124
123
|
parser.state.module.addPresentationalDependency(clearDep);
|
|
125
124
|
parser.unsetAsiPosition(/** @type {Range} */ (statement.range)[1]);
|
|
126
125
|
const attributes = getImportAttributes(statement);
|
|
127
|
-
|
|
128
|
-
if (
|
|
129
|
-
defer
|
|
130
|
-
(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
126
|
+
let defer = false;
|
|
127
|
+
if (this.deferImport) {
|
|
128
|
+
({ defer } = getImportMode(parser, statement));
|
|
129
|
+
if (
|
|
130
|
+
defer &&
|
|
131
|
+
(statement.specifiers.length !== 1 ||
|
|
132
|
+
statement.specifiers[0].type !== "ImportNamespaceSpecifier")
|
|
133
|
+
) {
|
|
134
|
+
const error = new WebpackError(
|
|
135
|
+
"Deferred import can only be used with `import * as namespace from '...'` syntax."
|
|
136
|
+
);
|
|
137
|
+
error.loc = statement.loc || undefined;
|
|
138
|
+
parser.state.current.addError(error);
|
|
139
|
+
}
|
|
138
140
|
}
|
|
139
141
|
const sideEffectDep = new HarmonyImportSideEffectDependency(
|
|
140
142
|
/** @type {string} */ (source),
|
|
@@ -150,7 +152,9 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
150
152
|
PLUGIN_NAME,
|
|
151
153
|
(statement, source, id, name) => {
|
|
152
154
|
const ids = id === null ? [] : [id];
|
|
153
|
-
const
|
|
155
|
+
const defer = this.deferImport
|
|
156
|
+
? getImportMode(parser, statement).defer
|
|
157
|
+
: false;
|
|
154
158
|
parser.tagVariable(name, harmonySpecifierTag, {
|
|
155
159
|
name,
|
|
156
160
|
source,
|
|
@@ -162,7 +166,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
162
166
|
return true;
|
|
163
167
|
}
|
|
164
168
|
);
|
|
165
|
-
parser.hooks.binaryExpression.tap(PLUGIN_NAME, expression => {
|
|
169
|
+
parser.hooks.binaryExpression.tap(PLUGIN_NAME, (expression) => {
|
|
166
170
|
if (expression.operator !== "in") return;
|
|
167
171
|
|
|
168
172
|
const leftPartEvaluated = parser.evaluateExpression(expression.left);
|
|
@@ -204,34 +208,38 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
204
208
|
);
|
|
205
209
|
dep.loc = /** @type {DependencyLocation} */ (expression.loc);
|
|
206
210
|
parser.state.module.addDependency(dep);
|
|
207
|
-
InnerGraph.onUsage(parser.state, e => (dep.usedByExports = e));
|
|
208
|
-
return true;
|
|
209
|
-
});
|
|
210
|
-
parser.hooks.expression.for(harmonySpecifierTag).tap(PLUGIN_NAME, expr => {
|
|
211
|
-
const settings = /** @type {HarmonySettings} */ (parser.currentTagData);
|
|
212
|
-
const dep = new HarmonyImportSpecifierDependency(
|
|
213
|
-
settings.source,
|
|
214
|
-
settings.sourceOrder,
|
|
215
|
-
settings.ids,
|
|
216
|
-
settings.name,
|
|
217
|
-
/** @type {Range} */
|
|
218
|
-
(expr.range),
|
|
219
|
-
exportPresenceMode,
|
|
220
|
-
settings.attributes,
|
|
221
|
-
[],
|
|
222
|
-
settings.defer
|
|
223
|
-
);
|
|
224
|
-
dep.referencedPropertiesInDestructuring =
|
|
225
|
-
parser.destructuringAssignmentPropertiesFor(expr);
|
|
226
|
-
dep.shorthand = parser.scope.inShorthand;
|
|
227
|
-
dep.directImport = true;
|
|
228
|
-
dep.asiSafe = !parser.isAsiPosition(/** @type {Range} */ (expr.range)[0]);
|
|
229
|
-
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
|
230
|
-
dep.call = parser.scope.inTaggedTemplateTag;
|
|
231
|
-
parser.state.module.addDependency(dep);
|
|
232
|
-
InnerGraph.onUsage(parser.state, e => (dep.usedByExports = e));
|
|
211
|
+
InnerGraph.onUsage(parser.state, (e) => (dep.usedByExports = e));
|
|
233
212
|
return true;
|
|
234
213
|
});
|
|
214
|
+
parser.hooks.expression
|
|
215
|
+
.for(harmonySpecifierTag)
|
|
216
|
+
.tap(PLUGIN_NAME, (expr) => {
|
|
217
|
+
const settings = /** @type {HarmonySettings} */ (parser.currentTagData);
|
|
218
|
+
const dep = new HarmonyImportSpecifierDependency(
|
|
219
|
+
settings.source,
|
|
220
|
+
settings.sourceOrder,
|
|
221
|
+
settings.ids,
|
|
222
|
+
settings.name,
|
|
223
|
+
/** @type {Range} */
|
|
224
|
+
(expr.range),
|
|
225
|
+
exportPresenceMode,
|
|
226
|
+
settings.attributes,
|
|
227
|
+
[],
|
|
228
|
+
settings.defer
|
|
229
|
+
);
|
|
230
|
+
dep.referencedPropertiesInDestructuring =
|
|
231
|
+
parser.destructuringAssignmentPropertiesFor(expr);
|
|
232
|
+
dep.shorthand = parser.scope.inShorthand;
|
|
233
|
+
dep.directImport = true;
|
|
234
|
+
dep.asiSafe = !parser.isAsiPosition(
|
|
235
|
+
/** @type {Range} */ (expr.range)[0]
|
|
236
|
+
);
|
|
237
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
|
238
|
+
dep.call = parser.scope.inTaggedTemplateTag;
|
|
239
|
+
parser.state.module.addDependency(dep);
|
|
240
|
+
InnerGraph.onUsage(parser.state, (e) => (dep.usedByExports = e));
|
|
241
|
+
return true;
|
|
242
|
+
});
|
|
235
243
|
parser.hooks.expressionMemberChain
|
|
236
244
|
.for(harmonySpecifierTag)
|
|
237
245
|
.tap(
|
|
@@ -277,7 +285,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
277
285
|
);
|
|
278
286
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
|
279
287
|
parser.state.module.addDependency(dep);
|
|
280
|
-
InnerGraph.onUsage(parser.state, e => (dep.usedByExports = e));
|
|
288
|
+
InnerGraph.onUsage(parser.state, (e) => (dep.usedByExports = e));
|
|
281
289
|
return true;
|
|
282
290
|
}
|
|
283
291
|
);
|
|
@@ -331,7 +339,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
331
339
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
|
332
340
|
parser.state.module.addDependency(dep);
|
|
333
341
|
if (args) parser.walkExpressions(args);
|
|
334
|
-
InnerGraph.onUsage(parser.state, e => (dep.usedByExports = e));
|
|
342
|
+
InnerGraph.onUsage(parser.state, (e) => (dep.usedByExports = e));
|
|
335
343
|
return true;
|
|
336
344
|
}
|
|
337
345
|
);
|
|
@@ -342,7 +350,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
342
350
|
// This is not a harmony module, skip it
|
|
343
351
|
return;
|
|
344
352
|
}
|
|
345
|
-
const dependencies = requests.map(request => {
|
|
353
|
+
const dependencies = requests.map((request) => {
|
|
346
354
|
const dep = new HarmonyAcceptImportDependency(request);
|
|
347
355
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
|
348
356
|
parser.state.module.addDependency(dep);
|
|
@@ -364,7 +372,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
364
372
|
// This is not a harmony module, skip it
|
|
365
373
|
return;
|
|
366
374
|
}
|
|
367
|
-
const dependencies = requests.map(request => {
|
|
375
|
+
const dependencies = requests.map((request) => {
|
|
368
376
|
const dep = new HarmonyAcceptImportDependency(request);
|
|
369
377
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
|
370
378
|
parser.state.module.addDependency(dep);
|
|
@@ -387,7 +395,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
387
395
|
/**
|
|
388
396
|
* @param {JavascriptParser} parser parser
|
|
389
397
|
* @param {ExportNamedDeclaration | ExportAllDeclaration | ImportDeclaration} node node
|
|
390
|
-
* @returns {{defer: boolean}} import attributes
|
|
398
|
+
* @returns {{ defer: boolean }} import attributes
|
|
391
399
|
*/
|
|
392
400
|
function getImportMode(parser, node) {
|
|
393
401
|
const result = { defer: "phase" in node && node.phase === "defer" };
|
|
@@ -26,11 +26,10 @@ class HarmonyImportSideEffectDependency extends HarmonyImportDependency {
|
|
|
26
26
|
* @param {string} request the request string
|
|
27
27
|
* @param {number} sourceOrder source order
|
|
28
28
|
* @param {ImportAttributes=} attributes import attributes
|
|
29
|
-
* @param {boolean=}
|
|
29
|
+
* @param {boolean=} defer is defer phase
|
|
30
30
|
*/
|
|
31
|
-
constructor(request, sourceOrder, attributes,
|
|
32
|
-
super(request, sourceOrder, attributes);
|
|
33
|
-
this.defer = deferred;
|
|
31
|
+
constructor(request, sourceOrder, attributes, defer) {
|
|
32
|
+
super(request, sourceOrder, attributes, defer);
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
get type() {
|
|
@@ -42,7 +41,7 @@ class HarmonyImportSideEffectDependency extends HarmonyImportDependency {
|
|
|
42
41
|
* @returns {null | false | GetConditionFn} function to determine if the connection is active
|
|
43
42
|
*/
|
|
44
43
|
getCondition(moduleGraph) {
|
|
45
|
-
return connection => {
|
|
44
|
+
return (connection) => {
|
|
46
45
|
const refModule = connection.resolvedModule;
|
|
47
46
|
if (!refModule) return true;
|
|
48
47
|
return refModule.getSideEffectsConnectionState(moduleGraph);
|
|
@@ -51,7 +51,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
|
51
51
|
* @param {ExportPresenceMode} exportPresenceMode export presence mode
|
|
52
52
|
* @param {ImportAttributes | undefined} attributes import attributes
|
|
53
53
|
* @param {Range[] | undefined} idRanges ranges for members of ids; the two arrays are right-aligned
|
|
54
|
-
* @param {boolean=}
|
|
54
|
+
* @param {boolean=} defer is defer phase
|
|
55
55
|
*/
|
|
56
56
|
constructor(
|
|
57
57
|
request,
|
|
@@ -62,9 +62,9 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
|
62
62
|
exportPresenceMode,
|
|
63
63
|
attributes,
|
|
64
64
|
idRanges, // TODO webpack 6 make this non-optional. It must always be set to properly trim ids.
|
|
65
|
-
|
|
65
|
+
defer
|
|
66
66
|
) {
|
|
67
|
-
super(request, sourceOrder, attributes);
|
|
67
|
+
super(request, sourceOrder, attributes, defer);
|
|
68
68
|
this.ids = ids;
|
|
69
69
|
this.name = name;
|
|
70
70
|
this.range = range;
|
|
@@ -79,7 +79,6 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
|
79
79
|
this.usedByExports = undefined;
|
|
80
80
|
/** @type {Set<DestructuringAssignmentProperty> | undefined} */
|
|
81
81
|
this.referencedPropertiesInDestructuring = undefined;
|
|
82
|
-
this.defer = deferred;
|
|
83
82
|
}
|
|
84
83
|
|
|
85
84
|
// TODO webpack 6 remove
|
|
@@ -135,14 +135,8 @@ class HarmonyModulesPlugin {
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
new HarmonyDetectionParserPlugin(this.options).apply(parser);
|
|
138
|
-
new HarmonyImportDependencyParserPlugin(
|
|
139
|
-
|
|
140
|
-
this.options.deferImport
|
|
141
|
-
).apply(parser);
|
|
142
|
-
new HarmonyExportDependencyParserPlugin(
|
|
143
|
-
parserOptions,
|
|
144
|
-
this.options.deferImport
|
|
145
|
-
).apply(parser);
|
|
138
|
+
new HarmonyImportDependencyParserPlugin(parserOptions).apply(parser);
|
|
139
|
+
new HarmonyExportDependencyParserPlugin(parserOptions).apply(parser);
|
|
146
140
|
new HarmonyTopLevelThisParserPlugin().apply(parser);
|
|
147
141
|
};
|
|
148
142
|
|
|
@@ -20,7 +20,7 @@ class HarmonyTopLevelThisParserPlugin {
|
|
|
20
20
|
* @returns {void}
|
|
21
21
|
*/
|
|
22
22
|
apply(parser) {
|
|
23
|
-
parser.hooks.expression.for("this").tap(PLUGIN_NAME, node => {
|
|
23
|
+
parser.hooks.expression.for("this").tap(PLUGIN_NAME, (node) => {
|
|
24
24
|
if (!parser.scope.topLevelScope) return;
|
|
25
25
|
if (HarmonyExports.isEnabled(parser.state)) {
|
|
26
26
|
const dep = new ConstDependency(
|