webpack 5.104.1 → 5.105.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 +2 -2
- package/bin/webpack.js +6 -3
- package/lib/APIPlugin.js +85 -15
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AsyncDependenciesBlock.js +17 -2
- package/lib/AsyncDependencyToInitialChunkError.js +3 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +5 -1
- package/lib/CacheFacade.js +2 -2
- package/lib/CaseSensitiveModulesWarning.js +1 -0
- package/lib/Chunk.js +9 -5
- package/lib/ChunkGraph.js +30 -9
- package/lib/ChunkGroup.js +6 -3
- package/lib/ChunkRenderError.js +9 -2
- package/lib/CleanPlugin.js +4 -1
- package/lib/CodeGenerationError.js +7 -1
- package/lib/CodeGenerationResults.js +10 -3
- package/lib/CommentCompilationWarning.js +2 -1
- package/lib/Compilation.js +284 -236
- package/lib/Compiler.js +4 -3
- package/lib/ConcatenationScope.js +2 -1
- package/lib/ConcurrentCompilationError.js +3 -3
- package/lib/ContextModule.js +248 -111
- package/lib/ContextModuleFactory.js +14 -2
- package/lib/DefinePlugin.js +15 -8
- package/lib/DelegatedModule.js +6 -0
- package/lib/DelegatedModuleFactoryPlugin.js +2 -0
- package/lib/Dependency.js +6 -1
- package/lib/DependencyTemplates.js +3 -2
- package/lib/DllModule.js +2 -0
- package/lib/DllReferencePlugin.js +1 -0
- package/lib/DotenvPlugin.js +11 -5
- package/lib/DynamicEntryPlugin.js +8 -1
- package/lib/EnvironmentNotSupportAsyncWarning.js +1 -0
- package/lib/EvalSourceMapDevToolPlugin.js +17 -13
- package/lib/ExportsInfo.js +8 -4
- package/lib/ExternalModule.js +16 -0
- package/lib/ExternalModuleFactoryPlugin.js +9 -2
- package/lib/ExternalsPlugin.js +2 -1
- package/lib/FalseIIFEUmdWarning.js +1 -0
- package/lib/FileSystemInfo.js +49 -25
- package/lib/FlagDependencyExportsPlugin.js +8 -1
- package/lib/FlagDependencyUsagePlugin.js +9 -7
- package/lib/HarmonyLinkingError.js +1 -0
- package/lib/HookWebpackError.js +2 -0
- package/lib/HotModuleReplacementPlugin.js +16 -2
- package/lib/IgnoreWarningsPlugin.js +5 -2
- package/lib/InitFragment.js +1 -0
- package/lib/InvalidDependenciesModuleWarning.js +1 -0
- package/lib/LibManifestPlugin.js +1 -0
- package/lib/ManifestPlugin.js +8 -1
- package/lib/Module.js +7 -4
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +1 -0
- package/lib/ModuleDependencyWarning.js +1 -0
- package/lib/ModuleError.js +4 -1
- package/lib/ModuleFilenameHelpers.js +4 -2
- package/lib/ModuleGraph.js +3 -0
- package/lib/ModuleGraphConnection.js +10 -1
- package/lib/ModuleHashingError.js +2 -0
- package/lib/ModuleInfoHeaderPlugin.js +6 -1
- package/lib/ModuleNotFoundError.js +1 -0
- package/lib/ModuleParseError.js +5 -1
- package/lib/ModuleProfile.js +1 -1
- package/lib/ModuleRestoreError.js +2 -0
- package/lib/ModuleSourceTypeConstants.js +1 -11
- package/lib/ModuleStoreError.js +2 -0
- package/lib/ModuleWarning.js +3 -1
- package/lib/MultiCompiler.js +11 -7
- package/lib/MultiWatching.js +2 -2
- package/lib/NoModeWarning.js +1 -0
- package/lib/NodeStuffInWebError.js +1 -0
- package/lib/NormalModule.js +28 -5
- package/lib/NormalModuleFactory.js +20 -4
- package/lib/OptionsApply.js +3 -1
- package/lib/ProgressPlugin.js +4 -0
- package/lib/RawModule.js +2 -0
- package/lib/RuntimeModule.js +10 -0
- package/lib/RuntimePlugin.js +7 -9
- package/lib/RuntimeTemplate.js +14 -7
- package/lib/SourceMapDevToolPlugin.js +30 -23
- package/lib/Template.js +10 -5
- package/lib/TemplatedPathPlugin.js +4 -2
- package/lib/UnhandledSchemeError.js +1 -0
- package/lib/UnsupportedFeatureWarning.js +3 -0
- package/lib/WarnDeprecatedOptionPlugin.js +1 -0
- package/lib/WatchIgnorePlugin.js +1 -1
- package/lib/Watching.js +5 -0
- package/lib/WebpackError.js +4 -0
- package/lib/WebpackOptionsApply.js +61 -41
- package/lib/asset/AssetBytesGenerator.js +1 -0
- package/lib/asset/AssetGenerator.js +18 -3
- package/lib/asset/AssetModulesPlugin.js +33 -2
- package/lib/asset/AssetParser.js +4 -0
- package/lib/asset/AssetSourceGenerator.js +1 -0
- package/lib/asset/RawDataUrlModule.js +4 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
- package/lib/buildChunkGraph.js +31 -2
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +41 -8
- package/lib/cache/getLazyHashedEtag.js +13 -4
- package/lib/cache/mergeEtags.js +3 -1
- package/lib/cli.js +3 -1
- package/lib/config/defaults.js +65 -44
- package/lib/config/normalization.js +96 -0
- package/lib/container/ContainerEntryDependency.js +3 -0
- package/lib/container/ContainerEntryModule.js +7 -0
- package/lib/container/ContainerExposedDependency.js +1 -0
- package/lib/container/FallbackDependency.js +1 -0
- package/lib/container/FallbackItemDependency.js +1 -0
- package/lib/container/FallbackModule.js +4 -0
- package/lib/container/HoistContainerReferencesPlugin.js +6 -0
- package/lib/container/ModuleFederationPlugin.js +1 -1
- package/lib/container/RemoteModule.js +24 -0
- package/lib/css/CssGenerator.js +31 -4
- package/lib/css/CssModulesPlugin.js +26 -30
- package/lib/css/CssParser.js +12 -9
- package/lib/debug/ProfilingPlugin.js +1 -0
- package/lib/dependencies/AMDDefineDependency.js +3 -1
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
- package/lib/dependencies/AMDPlugin.js +1 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
- package/lib/dependencies/CachedConstDependency.js +1 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +1 -0
- package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
- package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
- package/lib/dependencies/ConstDependency.js +1 -0
- package/lib/dependencies/ContextDependencyHelpers.js +11 -4
- package/lib/dependencies/ContextElementDependency.js +1 -0
- package/lib/dependencies/CriticalDependencyWarning.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +7 -4
- package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
- package/lib/dependencies/CssUrlDependency.js +2 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
- package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -1
- package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
- package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
- package/lib/dependencies/HarmonyImportDependency.js +1 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +269 -5
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
- package/lib/dependencies/ImportDependency.js +1 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaPlugin.js +53 -11
- package/lib/dependencies/ImportParserPlugin.js +7 -12
- package/lib/dependencies/LoaderPlugin.js +3 -0
- package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
- package/lib/dependencies/ModuleDependency.js +1 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
- package/lib/dependencies/ProvidedDependency.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +1 -0
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
- package/lib/dependencies/WorkerDependency.js +9 -3
- package/lib/dependencies/WorkerPlugin.js +1 -0
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/electron/ElectronTargetPlugin.js +3 -1
- package/lib/errors/BuildCycleError.js +4 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
- package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +5 -0
- package/lib/hmr/lazyCompilationBackend.js +3 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +9 -7
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -0
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -0
- package/lib/ids/HashedModuleIdsPlugin.js +3 -8
- package/lib/ids/IdHelpers.js +10 -8
- package/lib/ids/NamedChunkIdsPlugin.js +7 -5
- package/lib/ids/NamedModuleIdsPlugin.js +1 -0
- package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +18 -10
- package/lib/ids/SyncModuleIdsPlugin.js +30 -20
- package/lib/index.js +2 -2
- package/lib/javascript/BasicEvaluatedExpression.js +1 -0
- package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
- package/lib/javascript/JavascriptModulesPlugin.js +29 -8
- package/lib/javascript/JavascriptParser.js +47 -14
- package/lib/json/JsonGenerator.js +1 -0
- package/lib/json/JsonParser.js +9 -2
- package/lib/library/AbstractLibraryPlugin.js +4 -1
- package/lib/library/AmdLibraryPlugin.js +2 -1
- package/lib/library/AssignLibraryPlugin.js +6 -2
- package/lib/library/EnableLibraryPlugin.js +1 -0
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
- package/lib/library/JsonpLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +130 -13
- package/lib/library/SystemLibraryPlugin.js +4 -1
- package/lib/library/UmdLibraryPlugin.js +4 -3
- package/lib/logging/Logger.js +9 -5
- package/lib/logging/createConsoleLogger.js +4 -0
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +6 -4
- package/lib/node/NodeEnvironmentPlugin.js +1 -0
- package/lib/node/NodeTargetPlugin.js +10 -1
- package/lib/node/NodeTemplatePlugin.js +1 -0
- package/lib/node/NodeWatchFileSystem.js +6 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -0
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -0
- package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -0
- package/lib/node/nodeConsole.js +18 -1
- package/lib/optimize/AggressiveMergingPlugin.js +2 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +15 -6
- package/lib/optimize/ConcatenatedModule.js +33 -19
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
- package/lib/optimize/InnerGraph.js +5 -3
- package/lib/optimize/InnerGraphPlugin.js +25 -25
- package/lib/optimize/LimitChunkCountPlugin.js +3 -2
- package/lib/optimize/MangleExportsPlugin.js +14 -2
- package/lib/optimize/MergeDuplicateChunksPlugin.js +5 -1
- package/lib/optimize/MinChunkSizePlugin.js +5 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +19 -4
- package/lib/optimize/RealContentHashPlugin.js +37 -27
- package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
- package/lib/optimize/RuntimeChunkPlugin.js +3 -5
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
- package/lib/optimize/SplitChunksPlugin.js +23 -5
- package/lib/performance/AssetsOverSizeLimitWarning.js +6 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -2
- package/lib/performance/NoAsyncChunksWarning.js +1 -0
- package/lib/performance/SizeLimitsPlugin.js +6 -6
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +2 -0
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -1
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -0
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -0
- package/lib/rules/BasicEffectRulePlugin.js +2 -0
- package/lib/rules/BasicMatcherRulePlugin.js +3 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
- package/lib/rules/RuleSetCompiler.js +6 -0
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
- package/lib/runtime/CompatRuntimeModule.js +1 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -0
- package/lib/runtime/GetFullHashRuntimeModule.js +1 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
- package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +16 -32
- package/lib/runtime/PublicPathRuntimeModule.js +1 -0
- package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
- package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
- package/lib/schemes/HttpUriPlugin.js +39 -20
- package/lib/schemes/VirtualUrlPlugin.js +28 -2
- package/lib/serialization/BinaryMiddleware.js +4 -0
- package/lib/serialization/FileMiddleware.js +9 -4
- package/lib/serialization/ObjectMiddleware.js +34 -11
- package/lib/serialization/PlainObjectSerializer.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +60 -0
- package/lib/sharing/ConsumeSharedPlugin.js +5 -4
- package/lib/sharing/ProvideSharedModule.js +4 -0
- package/lib/sharing/ProvideSharedPlugin.js +24 -25
- package/lib/sharing/resolveMatchedConfigs.js +2 -2
- package/lib/sharing/utils.js +8 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +20 -12
- package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/url/URLParserPlugin.js +5 -3
- package/lib/util/AppendOnlyStackedSet.js +57 -0
- package/lib/util/Hash.js +1 -0
- package/lib/util/IterableHelpers.js +1 -0
- package/lib/util/LazyBucketSortedSet.js +1 -0
- package/lib/util/LazySet.js +1 -0
- package/lib/util/ParallelismFactorCalculator.js +1 -0
- package/lib/util/SortableSet.js +1 -0
- package/lib/util/StringXor.js +1 -0
- package/lib/util/binarySearchBounds.js +15 -8
- package/lib/util/chainedImports.js +1 -1
- package/lib/util/cleverMerge.js +6 -1
- package/lib/util/comparators.js +21 -1
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +3 -2
- package/lib/util/conventions.js +3 -2
- package/lib/util/deterministicGrouping.js +13 -1
- package/lib/util/extractSourceMap.js +12 -13
- package/lib/util/fs.js +15 -19
- package/lib/util/hash/BatchedHash.js +4 -0
- package/lib/util/hash/BulkUpdateHash.js +8 -1
- package/lib/util/hash/hash-digest.js +1 -0
- package/lib/util/hash/wasm-hash.js +18 -2
- package/lib/util/identifier.js +7 -2
- package/lib/util/magicComment.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -0
- package/lib/util/runtime.js +15 -1
- package/lib/util/semver.js +1 -0
- package/lib/util/serialization.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +2 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-sync/WebAssemblyParser.js +3 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -0
- package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
- package/lib/webpack.js +16 -4
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -0
- package/package.json +33 -36
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +121 -55
- package/schemas/plugins/BannerPlugin.json +2 -2
- package/schemas/plugins/IgnorePlugin.json +1 -1
- package/schemas/plugins/ManifestPlugin.json +3 -3
- package/schemas/plugins/ProgressPlugin.json +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/schemas/plugins/schemes/HttpUriPlugin.json +1 -1
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
- package/types.d.ts +440 -137
|
@@ -21,6 +21,7 @@ const NullDependency = require("./NullDependency");
|
|
|
21
21
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
22
22
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
23
23
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
24
|
+
/** @typedef {import("./HarmonyExportInitFragment").ExportMap} ExportMap */
|
|
24
25
|
|
|
25
26
|
class HarmonyExportExpressionDependency extends NullDependency {
|
|
26
27
|
/**
|
|
@@ -120,6 +121,7 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
|
|
|
120
121
|
const { declarationId } = dep;
|
|
121
122
|
const exportsName = module.exportsArgument;
|
|
122
123
|
if (declarationId) {
|
|
124
|
+
/** @type {string} */
|
|
123
125
|
let name;
|
|
124
126
|
if (typeof declarationId === "string") {
|
|
125
127
|
name = declarationId;
|
|
@@ -139,6 +141,7 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
|
|
|
139
141
|
.getExportsInfo(module)
|
|
140
142
|
.getUsedName("default", runtime);
|
|
141
143
|
if (used) {
|
|
144
|
+
/** @type {ExportMap} */
|
|
142
145
|
const map = new Map();
|
|
143
146
|
map.set(used, `/* export default binding */ ${name}`);
|
|
144
147
|
initFragments.push(new HarmonyExportInitFragment(exportsName, map));
|
|
@@ -164,6 +167,7 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
|
|
|
164
167
|
.getUsedName("default", runtime);
|
|
165
168
|
if (used) {
|
|
166
169
|
runtimeRequirements.add(RuntimeGlobals.exports);
|
|
170
|
+
/** @type {ExportMap} */
|
|
167
171
|
const map = new Map();
|
|
168
172
|
map.set(used, name);
|
|
169
173
|
initFragments.push(new HarmonyExportInitFragment(exportsName, map));
|
|
@@ -58,6 +58,7 @@ const processExportInfo = require("./processExportInfo");
|
|
|
58
58
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
59
59
|
/** @typedef {import("./HarmonyImportDependency").Ids} Ids */
|
|
60
60
|
/** @typedef {import("./HarmonyImportDependency").ExportPresenceMode} ExportPresenceMode */
|
|
61
|
+
/** @typedef {import("./HarmonyExportInitFragment").ExportMap} ExportMap */
|
|
61
62
|
/** @typedef {import("../dependencies/ImportPhase").ImportPhaseType} ImportPhaseType */
|
|
62
63
|
|
|
63
64
|
/** @typedef {"missing" | "unused" | "empty-star" | "reexport-dynamic-default" | "reexport-named-default" | "reexport-namespace-object" | "reexport-fake-namespace-object" | "reexport-undefined" | "normal-reexport" | "dynamic-reexport"} ExportModeType */
|
|
@@ -264,6 +265,7 @@ const getMode = (moduleGraph, dep, runtimeKey) => {
|
|
|
264
265
|
|
|
265
266
|
// reexporting with a fixed name
|
|
266
267
|
if (name) {
|
|
268
|
+
/** @type {ExportMode} */
|
|
267
269
|
let mode;
|
|
268
270
|
const exportInfo = exportsInfo.getReadOnlyExportInfo(name);
|
|
269
271
|
|
|
@@ -464,7 +466,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
|
464
466
|
* @param {RuntimeSpec} runtime the runtime
|
|
465
467
|
* @param {ExportsInfo} exportsInfo exports info about the current module (optional)
|
|
466
468
|
* @param {Module} importedModule the imported module (optional)
|
|
467
|
-
* @returns {{exports?: Exports, checked?: Checked, ignoredExports: IgnoredExports, hidden?: Hidden}} information
|
|
469
|
+
* @returns {{ exports?: Exports, checked?: Checked, ignoredExports: IgnoredExports, hidden?: Hidden }} information
|
|
468
470
|
*/
|
|
469
471
|
getStarReexports(
|
|
470
472
|
moduleGraph,
|
|
@@ -480,8 +482,10 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
|
480
482
|
const noExtraImports =
|
|
481
483
|
exportsInfo.otherExportsInfo.getUsed(runtime) === UsageState.Unused;
|
|
482
484
|
|
|
485
|
+
/** @type {IgnoredExports} */
|
|
483
486
|
const ignoredExports = new Set(["default", ...this.activeExports]);
|
|
484
487
|
|
|
488
|
+
/** @type {Hidden | undefined} */
|
|
485
489
|
let hiddenExports;
|
|
486
490
|
const otherStarExports =
|
|
487
491
|
this._discoverActiveExportsFromOtherStarExports(moduleGraph);
|
|
@@ -1300,6 +1304,7 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
|
1300
1304
|
runtimeRequirements.add(RuntimeGlobals.exports);
|
|
1301
1305
|
runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
|
|
1302
1306
|
|
|
1307
|
+
/** @type {ExportMap} */
|
|
1303
1308
|
const map = new Map();
|
|
1304
1309
|
map.set(key, `/* ${comment} */ ${returnValue}`);
|
|
1305
1310
|
|
|
@@ -1325,6 +1330,7 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
|
1325
1330
|
runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
|
|
1326
1331
|
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
|
1327
1332
|
|
|
1333
|
+
/** @type {ExportMap} */
|
|
1328
1334
|
const map = new Map();
|
|
1329
1335
|
map.set(
|
|
1330
1336
|
key,
|
|
@@ -1365,6 +1371,7 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
|
1365
1371
|
runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
|
|
1366
1372
|
runtimeRequirements.add(RuntimeGlobals.makeDeferredNamespaceObject);
|
|
1367
1373
|
|
|
1374
|
+
/** @type {ExportMap} */
|
|
1368
1375
|
const map = new Map();
|
|
1369
1376
|
const moduleId = JSON.stringify(chunkGraph.getModuleId(module));
|
|
1370
1377
|
const mode = getMakeDeferredNamespaceModeFromExportsType(exportsType);
|
|
@@ -12,6 +12,7 @@ const { propertyName } = require("../util/propertyName");
|
|
|
12
12
|
|
|
13
13
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
14
14
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
|
15
|
+
/** @typedef {import("../ExportsInfo").UsedName} UsedName */
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* @param {Iterable<string>} iterable iterable strings
|
|
@@ -33,7 +34,12 @@ const joinIterableWithComma = (iterable) => {
|
|
|
33
34
|
return str;
|
|
34
35
|
};
|
|
35
36
|
|
|
37
|
+
/** @typedef {Map<UsedName, string>} ExportMap */
|
|
38
|
+
/** @typedef {Set<string>} UnusedExports */
|
|
39
|
+
|
|
40
|
+
/** @type {ExportMap} */
|
|
36
41
|
const EMPTY_MAP = new Map();
|
|
42
|
+
/** @type {UnusedExports} */
|
|
37
43
|
const EMPTY_SET = new Set();
|
|
38
44
|
|
|
39
45
|
/**
|
|
@@ -42,8 +48,8 @@ const EMPTY_SET = new Set();
|
|
|
42
48
|
class HarmonyExportInitFragment extends InitFragment {
|
|
43
49
|
/**
|
|
44
50
|
* @param {string} exportsArgument the exports identifier
|
|
45
|
-
* @param {
|
|
46
|
-
* @param {
|
|
51
|
+
* @param {ExportMap} exportMap mapping from used name to exposed variable name
|
|
52
|
+
* @param {UnusedExports} unusedExports list of unused export names
|
|
47
53
|
*/
|
|
48
54
|
constructor(
|
|
49
55
|
exportsArgument,
|
|
@@ -51,8 +57,11 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
|
51
57
|
unusedExports = EMPTY_SET
|
|
52
58
|
) {
|
|
53
59
|
super(undefined, InitFragment.STAGE_HARMONY_EXPORTS, 1, "harmony-exports");
|
|
60
|
+
/** @type {string} */
|
|
54
61
|
this.exportsArgument = exportsArgument;
|
|
62
|
+
/** @type {ExportMap} */
|
|
55
63
|
this.exportMap = exportMap;
|
|
64
|
+
/** @type {UnusedExports} */
|
|
56
65
|
this.unusedExports = unusedExports;
|
|
57
66
|
}
|
|
58
67
|
|
|
@@ -61,8 +70,10 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
|
61
70
|
* @returns {HarmonyExportInitFragment} merged fragment
|
|
62
71
|
*/
|
|
63
72
|
mergeAll(fragments) {
|
|
73
|
+
/** @type {undefined | ExportMap} */
|
|
64
74
|
let exportMap;
|
|
65
75
|
let exportMapOwned = false;
|
|
76
|
+
/** @type {undefined | UnusedExports} */
|
|
66
77
|
let unusedExports;
|
|
67
78
|
let unusedExportsOwned = false;
|
|
68
79
|
|
|
@@ -108,6 +119,7 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
|
108
119
|
* @returns {HarmonyExportInitFragment} merged result
|
|
109
120
|
*/
|
|
110
121
|
merge(other) {
|
|
122
|
+
/** @type {ExportMap} */
|
|
111
123
|
let exportMap;
|
|
112
124
|
if (this.exportMap.size === 0) {
|
|
113
125
|
exportMap = other.exportMap;
|
|
@@ -119,6 +131,7 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
|
119
131
|
if (!exportMap.has(key)) exportMap.set(key, value);
|
|
120
132
|
}
|
|
121
133
|
}
|
|
134
|
+
/** @type {UnusedExports} */
|
|
122
135
|
let unusedExports;
|
|
123
136
|
if (this.unusedExports.size === 0) {
|
|
124
137
|
unusedExports = other.unusedExports;
|
|
@@ -153,6 +166,7 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
|
153
166
|
: this.unusedExports.size > 0
|
|
154
167
|
? `/* unused harmony export ${first(this.unusedExports)} */\n`
|
|
155
168
|
: "";
|
|
169
|
+
/** @type {string[]} */
|
|
156
170
|
const definitions = [];
|
|
157
171
|
const orderedExportMap = [...this.exportMap].sort(([a], [b]) =>
|
|
158
172
|
a < b ? -1 : 1
|
|
@@ -160,7 +174,7 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
|
160
174
|
for (const [key, value] of orderedExportMap) {
|
|
161
175
|
definitions.push(
|
|
162
176
|
`\n/* harmony export */ ${propertyName(
|
|
163
|
-
key
|
|
177
|
+
/** @type {string} */ (key)
|
|
164
178
|
)}: ${runtimeTemplate.returningFunction(value)}`
|
|
165
179
|
);
|
|
166
180
|
}
|
|
@@ -17,6 +17,8 @@ const NullDependency = require("./NullDependency");
|
|
|
17
17
|
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
|
18
18
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
19
19
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
20
|
+
/** @typedef {import("./HarmonyExportInitFragment").UnusedExports} UnusedExports */
|
|
21
|
+
/** @typedef {import("./HarmonyExportInitFragment").ExportMap} ExportMap */
|
|
20
22
|
|
|
21
23
|
class HarmonyExportSpecifierDependency extends NullDependency {
|
|
22
24
|
/**
|
|
@@ -104,6 +106,7 @@ HarmonyExportSpecifierDependency.Template = class HarmonyExportSpecifierDependen
|
|
|
104
106
|
.getExportsInfo(module)
|
|
105
107
|
.getUsedName(dep.name, runtime);
|
|
106
108
|
if (!used) {
|
|
109
|
+
/** @type {UnusedExports} */
|
|
107
110
|
const set = new Set();
|
|
108
111
|
set.add(dep.name || "namespace");
|
|
109
112
|
initFragments.push(
|
|
@@ -112,6 +115,7 @@ HarmonyExportSpecifierDependency.Template = class HarmonyExportSpecifierDependen
|
|
|
112
115
|
return;
|
|
113
116
|
}
|
|
114
117
|
|
|
118
|
+
/** @type {ExportMap} */
|
|
115
119
|
const map = new Map();
|
|
116
120
|
map.set(used, `/* binding */ ${dep.id}`);
|
|
117
121
|
initFragments.push(
|
|
@@ -29,7 +29,7 @@ const ModuleDependency = require("./ModuleDependency");
|
|
|
29
29
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
30
30
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
31
31
|
|
|
32
|
-
/** @typedef {0 | 1 | 2 | 3
|
|
32
|
+
/** @typedef {0 | 1 | 2 | 3} ExportPresenceMode */
|
|
33
33
|
|
|
34
34
|
const ExportPresenceModes = {
|
|
35
35
|
NONE: /** @type {ExportPresenceMode} */ (0),
|
|
@@ -12,6 +12,7 @@ const {
|
|
|
12
12
|
getImportAttributes
|
|
13
13
|
} = require("../javascript/JavascriptParser");
|
|
14
14
|
const InnerGraph = require("../optimize/InnerGraph");
|
|
15
|
+
const AppendOnlyStackedSet = require("../util/AppendOnlyStackedSet");
|
|
15
16
|
const ConstDependency = require("./ConstDependency");
|
|
16
17
|
const HarmonyAcceptDependency = require("./HarmonyAcceptDependency");
|
|
17
18
|
const HarmonyAcceptImportDependency = require("./HarmonyAcceptImportDependency");
|
|
@@ -36,9 +37,18 @@ const { ImportPhaseUtils, createGetImportPhase } = require("./ImportPhase");
|
|
|
36
37
|
/** @typedef {import("../javascript/JavascriptParser").Members} Members */
|
|
37
38
|
/** @typedef {import("../javascript/JavascriptParser").MembersOptionals} MembersOptionals */
|
|
38
39
|
/** @typedef {import("./HarmonyImportDependency").Ids} Ids */
|
|
40
|
+
/** @typedef {import("./HarmonyImportDependency").ExportPresenceMode} ExportPresenceMode */
|
|
39
41
|
/** @typedef {import("./ImportPhase").ImportPhaseType} ImportPhaseType */
|
|
40
42
|
|
|
43
|
+
/**
|
|
44
|
+
* @typedef {object} HarmonySpecifierGuards
|
|
45
|
+
* @property {AppendOnlyStackedSet<string> | undefined} guards
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/** @typedef {Map<string, Set<string>>} Guards Map of import root to guarded member keys */
|
|
49
|
+
|
|
41
50
|
const harmonySpecifierTag = Symbol("harmony import");
|
|
51
|
+
const harmonySpecifierGuardTag = Symbol("harmony import guard");
|
|
42
52
|
|
|
43
53
|
/**
|
|
44
54
|
* @typedef {object} HarmonySettings
|
|
@@ -53,12 +63,25 @@ const harmonySpecifierTag = Symbol("harmony import");
|
|
|
53
63
|
|
|
54
64
|
const PLUGIN_NAME = "HarmonyImportDependencyParserPlugin";
|
|
55
65
|
|
|
66
|
+
/** @type {(members: Members) => string} */
|
|
67
|
+
const getMembersKey = (members) => members.join(".");
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Strip the root binding name if needed
|
|
71
|
+
* @param {HarmonySettings} settings settings
|
|
72
|
+
* @param {Ids} ids ids
|
|
73
|
+
* @returns {Ids} ids for presence check
|
|
74
|
+
*/
|
|
75
|
+
const getIdsForPresence = (settings, ids) =>
|
|
76
|
+
settings.ids.length ? ids.slice(1) : ids;
|
|
77
|
+
|
|
56
78
|
module.exports = class HarmonyImportDependencyParserPlugin {
|
|
57
79
|
/**
|
|
58
80
|
* @param {JavascriptParserOptions} options options
|
|
59
81
|
*/
|
|
60
82
|
constructor(options) {
|
|
61
83
|
this.options = options;
|
|
84
|
+
/** @type {ExportPresenceMode} */
|
|
62
85
|
this.exportPresenceMode =
|
|
63
86
|
options.importExportsPresence !== undefined
|
|
64
87
|
? ExportPresenceModes.fromUserOption(options.importExportsPresence)
|
|
@@ -70,13 +93,30 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
70
93
|
this.strictThisContextOnImports = options.strictThisContextOnImports;
|
|
71
94
|
}
|
|
72
95
|
|
|
96
|
+
/**
|
|
97
|
+
* @param {JavascriptParser} parser the parser
|
|
98
|
+
* @param {Ids} ids ids
|
|
99
|
+
* @returns {ExportPresenceMode} exportPresenceMode
|
|
100
|
+
*/
|
|
101
|
+
getExportPresenceMode(parser, ids) {
|
|
102
|
+
const harmonySettings = /** @type {HarmonySettings=} */ (
|
|
103
|
+
parser.currentTagData
|
|
104
|
+
);
|
|
105
|
+
if (!harmonySettings) return this.exportPresenceMode;
|
|
106
|
+
|
|
107
|
+
const data = /** @type {HarmonySpecifierGuards=} */ (
|
|
108
|
+
parser.getTagData(harmonySettings.name, harmonySpecifierGuardTag)
|
|
109
|
+
);
|
|
110
|
+
return data && data.guards && data.guards.has(getMembersKey(ids))
|
|
111
|
+
? ExportPresenceModes.NONE
|
|
112
|
+
: this.exportPresenceMode;
|
|
113
|
+
}
|
|
114
|
+
|
|
73
115
|
/**
|
|
74
116
|
* @param {JavascriptParser} parser the parser
|
|
75
117
|
* @returns {void}
|
|
76
118
|
*/
|
|
77
119
|
apply(parser) {
|
|
78
|
-
const { exportPresenceMode } = this;
|
|
79
|
-
|
|
80
120
|
const getImportPhase = createGetImportPhase(this.options.deferImport);
|
|
81
121
|
|
|
82
122
|
/**
|
|
@@ -228,6 +268,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
228
268
|
.for(harmonySpecifierTag)
|
|
229
269
|
.tap(PLUGIN_NAME, (expr) => {
|
|
230
270
|
const settings = /** @type {HarmonySettings} */ (parser.currentTagData);
|
|
271
|
+
|
|
231
272
|
const dep = new HarmonyImportSpecifierDependency(
|
|
232
273
|
settings.source,
|
|
233
274
|
settings.sourceOrder,
|
|
@@ -235,7 +276,10 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
235
276
|
settings.name,
|
|
236
277
|
/** @type {Range} */
|
|
237
278
|
(expr.range),
|
|
238
|
-
|
|
279
|
+
this.getExportPresenceMode(
|
|
280
|
+
parser,
|
|
281
|
+
getIdsForPresence(settings, settings.ids)
|
|
282
|
+
),
|
|
239
283
|
settings.phase,
|
|
240
284
|
settings.attributes,
|
|
241
285
|
[]
|
|
@@ -285,7 +329,10 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
285
329
|
settings.name,
|
|
286
330
|
/** @type {Range} */
|
|
287
331
|
(expr.range),
|
|
288
|
-
|
|
332
|
+
this.getExportPresenceMode(
|
|
333
|
+
parser,
|
|
334
|
+
getIdsForPresence(settings, ids)
|
|
335
|
+
),
|
|
289
336
|
settings.phase,
|
|
290
337
|
settings.attributes,
|
|
291
338
|
ranges
|
|
@@ -335,7 +382,10 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
335
382
|
ids,
|
|
336
383
|
settings.name,
|
|
337
384
|
/** @type {Range} */ (expr.range),
|
|
338
|
-
|
|
385
|
+
this.getExportPresenceMode(
|
|
386
|
+
parser,
|
|
387
|
+
getIdsForPresence(settings, ids)
|
|
388
|
+
),
|
|
339
389
|
settings.phase,
|
|
340
390
|
settings.attributes,
|
|
341
391
|
ranges
|
|
@@ -402,7 +452,221 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
402
452
|
parser.state.module.addDependency(dep);
|
|
403
453
|
}
|
|
404
454
|
});
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* @param {Expression} expression expression
|
|
458
|
+
* @returns {{ root: string, members: Members } | undefined} info
|
|
459
|
+
*/
|
|
460
|
+
const getHarmonyImportInfo = (expression) => {
|
|
461
|
+
const nameInfo = parser.getNameForExpression(expression);
|
|
462
|
+
if (!nameInfo) return;
|
|
463
|
+
|
|
464
|
+
const rootInfo = nameInfo.rootInfo;
|
|
465
|
+
const root =
|
|
466
|
+
typeof rootInfo === "string"
|
|
467
|
+
? rootInfo
|
|
468
|
+
: rootInfo instanceof VariableInfo
|
|
469
|
+
? rootInfo.name
|
|
470
|
+
: undefined;
|
|
471
|
+
if (!root) return;
|
|
472
|
+
if (!parser.getTagData(root, harmonySpecifierTag)) return;
|
|
473
|
+
return { root, members: nameInfo.getMembers() };
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* @param {Guards} guards guards
|
|
478
|
+
* @param {string} root root name
|
|
479
|
+
* @param {Members} members members
|
|
480
|
+
*/
|
|
481
|
+
const addToGuards = (guards, root, members) => {
|
|
482
|
+
const membersKey = getMembersKey(members);
|
|
483
|
+
const guardedMembers = guards.get(root);
|
|
484
|
+
if (guardedMembers) {
|
|
485
|
+
guardedMembers.add(membersKey);
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
guards.set(
|
|
490
|
+
root,
|
|
491
|
+
// Adding `foo.bar` implies guarding `foo` as well
|
|
492
|
+
membersKey === "" ? new Set([""]) : new Set([membersKey, ""])
|
|
493
|
+
);
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* @param {Expression} expression expression
|
|
498
|
+
* @param {Guards} guards guards
|
|
499
|
+
* @param {boolean} needTruthy need to be truthy
|
|
500
|
+
*/
|
|
501
|
+
const collect = (expression, guards, needTruthy) => {
|
|
502
|
+
// !foo
|
|
503
|
+
if (
|
|
504
|
+
expression.type === "UnaryExpression" &&
|
|
505
|
+
expression.operator === "!"
|
|
506
|
+
) {
|
|
507
|
+
collect(expression.argument, guards, !needTruthy);
|
|
508
|
+
return;
|
|
509
|
+
} else if (expression.type === "LogicalExpression" && needTruthy) {
|
|
510
|
+
// foo && bar
|
|
511
|
+
if (expression.operator === "&&") {
|
|
512
|
+
collect(expression.left, guards, true);
|
|
513
|
+
collect(expression.right, guards, true);
|
|
514
|
+
}
|
|
515
|
+
// falsy || foo
|
|
516
|
+
else if (expression.operator === "||") {
|
|
517
|
+
const leftEvaluation = parser.evaluateExpression(expression.left);
|
|
518
|
+
const leftBool = leftEvaluation.asBool();
|
|
519
|
+
if (leftBool === false) {
|
|
520
|
+
collect(expression.right, guards, true);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
// nullish ?? foo
|
|
524
|
+
else if (expression.operator === "??") {
|
|
525
|
+
const leftEvaluation = parser.evaluateExpression(expression.left);
|
|
526
|
+
const leftNullish = leftEvaluation.asNullish();
|
|
527
|
+
if (leftNullish === true) {
|
|
528
|
+
collect(expression.right, guards, true);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
if (!needTruthy) return;
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* @param {Expression} targetExpression expression
|
|
537
|
+
* @returns {boolean} is added
|
|
538
|
+
*/
|
|
539
|
+
const addGuardForExpression = (targetExpression) => {
|
|
540
|
+
const info = getHarmonyImportInfo(targetExpression);
|
|
541
|
+
if (!info) return false;
|
|
542
|
+
addToGuards(guards, info.root, info.members);
|
|
543
|
+
return true;
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* @param {Expression} left left expression
|
|
548
|
+
* @param {Expression} right right expression
|
|
549
|
+
* @param {(evaluation: ReturnType<JavascriptParser["evaluateExpression"]>) => boolean} matcher matcher
|
|
550
|
+
* @returns {boolean} is added
|
|
551
|
+
*/
|
|
552
|
+
const addGuardForNullishCompare = (left, right, matcher) => {
|
|
553
|
+
const leftEval = parser.evaluateExpression(left);
|
|
554
|
+
if (leftEval && matcher(leftEval)) {
|
|
555
|
+
return addGuardForExpression(right);
|
|
556
|
+
}
|
|
557
|
+
const rightEval = parser.evaluateExpression(right);
|
|
558
|
+
if (rightEval && matcher(rightEval)) {
|
|
559
|
+
return addGuardForExpression(/** @type {Expression} */ (left));
|
|
560
|
+
}
|
|
561
|
+
return false;
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
if (expression.type === "BinaryExpression") {
|
|
565
|
+
// "bar" in foo
|
|
566
|
+
if (expression.operator === "in") {
|
|
567
|
+
const leftEvaluation = parser.evaluateExpression(expression.left);
|
|
568
|
+
if (leftEvaluation.couldHaveSideEffects()) return;
|
|
569
|
+
const propertyName = leftEvaluation.asString();
|
|
570
|
+
if (!propertyName) return;
|
|
571
|
+
parser.evaluateExpression(expression.right);
|
|
572
|
+
const info = getHarmonyImportInfo(expression.right);
|
|
573
|
+
if (!info) return;
|
|
574
|
+
|
|
575
|
+
if (info.members.length) {
|
|
576
|
+
for (const member of info.members) {
|
|
577
|
+
addToGuards(guards, info.root, [member]);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
addToGuards(guards, info.root, [...info.members, propertyName]);
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
// foo !== undefined
|
|
584
|
+
else if (
|
|
585
|
+
expression.operator === "!==" &&
|
|
586
|
+
addGuardForNullishCompare(
|
|
587
|
+
/** @type {Expression} */ (expression.left),
|
|
588
|
+
expression.right,
|
|
589
|
+
(evaluation) => evaluation.isUndefined()
|
|
590
|
+
)
|
|
591
|
+
) {
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
// foo != undefined
|
|
595
|
+
// foo != null
|
|
596
|
+
else if (
|
|
597
|
+
expression.operator === "!=" &&
|
|
598
|
+
addGuardForNullishCompare(
|
|
599
|
+
/** @type {Expression} */ (expression.left),
|
|
600
|
+
expression.right,
|
|
601
|
+
(evaluation) => Boolean(evaluation.asNullish())
|
|
602
|
+
)
|
|
603
|
+
) {
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
addGuardForExpression(expression);
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* @param {Guards} guards guards
|
|
612
|
+
* @param {() => void} walk walk callback
|
|
613
|
+
* @returns {void}
|
|
614
|
+
*/
|
|
615
|
+
const withGuards = (guards, walk) => {
|
|
616
|
+
const applyGuards = () => {
|
|
617
|
+
/** @type {(() => void)[]} */
|
|
618
|
+
const restoreFns = [];
|
|
619
|
+
|
|
620
|
+
for (const [rootName, members] of guards) {
|
|
621
|
+
const previous = parser.getVariableInfo(rootName);
|
|
622
|
+
const exist = /** @type {HarmonySpecifierGuards=} */ (
|
|
623
|
+
parser.getTagData(rootName, harmonySpecifierGuardTag)
|
|
624
|
+
);
|
|
625
|
+
|
|
626
|
+
const mergedGuards =
|
|
627
|
+
exist && exist.guards
|
|
628
|
+
? exist.guards.createChild()
|
|
629
|
+
: new AppendOnlyStackedSet();
|
|
630
|
+
|
|
631
|
+
for (const memberKey of members) mergedGuards.add(memberKey);
|
|
632
|
+
parser.tagVariable(rootName, harmonySpecifierGuardTag, {
|
|
633
|
+
guards: mergedGuards
|
|
634
|
+
});
|
|
635
|
+
restoreFns.push(() => {
|
|
636
|
+
parser.setVariable(rootName, previous);
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
return () => {
|
|
641
|
+
for (const restore of restoreFns) {
|
|
642
|
+
restore();
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
const restore = applyGuards();
|
|
648
|
+
try {
|
|
649
|
+
walk();
|
|
650
|
+
} finally {
|
|
651
|
+
restore();
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
if (this.exportPresenceMode !== ExportPresenceModes.NONE) {
|
|
656
|
+
parser.hooks.collectGuards.tap(PLUGIN_NAME, (expression) => {
|
|
657
|
+
if (parser.scope.isAsmJs) return;
|
|
658
|
+
/** @type {Guards} */
|
|
659
|
+
const guards = new Map();
|
|
660
|
+
collect(expression, guards, true);
|
|
661
|
+
|
|
662
|
+
if (guards.size === 0) return;
|
|
663
|
+
return (walk) => {
|
|
664
|
+
withGuards(guards, walk);
|
|
665
|
+
};
|
|
666
|
+
});
|
|
667
|
+
}
|
|
405
668
|
}
|
|
406
669
|
};
|
|
407
670
|
|
|
671
|
+
module.exports.harmonySpecifierGuardTag = harmonySpecifierGuardTag;
|
|
408
672
|
module.exports.harmonySpecifierTag = harmonySpecifierTag;
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const Dependency = require("../Dependency");
|
|
9
|
+
const InitFragment = require("../InitFragment");
|
|
9
10
|
const Template = require("../Template");
|
|
10
11
|
const {
|
|
11
12
|
getDependencyUsedByExportsCondition
|
|
@@ -72,10 +73,15 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
|
72
73
|
this.range = range;
|
|
73
74
|
this.idRanges = idRanges;
|
|
74
75
|
this.exportPresenceMode = exportPresenceMode;
|
|
76
|
+
/** @type {undefined | boolean} */
|
|
75
77
|
this.namespaceObjectAsContext = false;
|
|
78
|
+
/** @type {undefined | boolean} */
|
|
76
79
|
this.call = undefined;
|
|
80
|
+
/** @type {undefined | boolean} */
|
|
77
81
|
this.directImport = undefined;
|
|
82
|
+
/** @type {undefined | boolean | string} */
|
|
78
83
|
this.shorthand = undefined;
|
|
84
|
+
/** @type {undefined | boolean} */
|
|
79
85
|
this.asiSafe = undefined;
|
|
80
86
|
/** @type {UsedByExports | undefined} */
|
|
81
87
|
this.usedByExports = undefined;
|
|
@@ -336,10 +342,22 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
|
|
336
342
|
*/
|
|
337
343
|
apply(dependency, source, templateContext) {
|
|
338
344
|
const dep = /** @type {HarmonyImportSpecifierDependency} */ (dependency);
|
|
339
|
-
const { moduleGraph, runtime } = templateContext;
|
|
345
|
+
const { moduleGraph, runtime, initFragments } = templateContext;
|
|
340
346
|
const connection = moduleGraph.getConnection(dep);
|
|
341
|
-
|
|
342
|
-
|
|
347
|
+
|
|
348
|
+
// Only render declaration for import specifier when the dependency is conditional
|
|
349
|
+
if (connection && !connection.isTargetActive(runtime)) {
|
|
350
|
+
initFragments.push(
|
|
351
|
+
new InitFragment(
|
|
352
|
+
`/* unused harmony import specifier */ var ${dep.name};\n`,
|
|
353
|
+
InitFragment.STAGE_HARMONY_IMPORTS,
|
|
354
|
+
0,
|
|
355
|
+
`unused import specifier ${dep.name}`
|
|
356
|
+
)
|
|
357
|
+
);
|
|
358
|
+
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
343
361
|
|
|
344
362
|
const ids = dep.getIds(moduleGraph);
|
|
345
363
|
const {
|
|
@@ -431,6 +449,7 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
|
|
431
449
|
const { moduleGraph, module, runtime, concatenationScope } =
|
|
432
450
|
templateContext;
|
|
433
451
|
const connection = moduleGraph.getConnection(dep);
|
|
452
|
+
/** @type {string} */
|
|
434
453
|
let exportExpr;
|
|
435
454
|
if (
|
|
436
455
|
connection &&
|
|
@@ -67,6 +67,7 @@ class ImportDependency extends ModuleDependency {
|
|
|
67
67
|
*/
|
|
68
68
|
getReferencedExports(moduleGraph, runtime) {
|
|
69
69
|
if (!this.referencedExports) return Dependency.EXPORTS_OBJECT_REFERENCED;
|
|
70
|
+
/** @type {ReferencedExports} */
|
|
70
71
|
const refs = [];
|
|
71
72
|
for (const referencedExport of this.referencedExports) {
|
|
72
73
|
if (referencedExport[0] === "default") {
|
|
@@ -84,6 +84,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
|
84
84
|
);
|
|
85
85
|
if (!requestExpr.isString()) return;
|
|
86
86
|
const request = /** @type {string} */ (requestExpr.string);
|
|
87
|
+
/** @type {WebpackError[]} */
|
|
87
88
|
const errors = [];
|
|
88
89
|
let regExp = /^\.\/.*$/;
|
|
89
90
|
let recursive = true;
|