webpack 5.107.1 → 5.108.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hot/dev-server.js +2 -0
- package/lib/APIPlugin.js +8 -4
- package/lib/CacheFacade.js +7 -0
- package/lib/Chunk.js +4 -0
- package/lib/ChunkGraph.js +30 -9
- package/lib/CircularModulesPlugin.js +190 -0
- package/lib/CleanPlugin.js +2 -1
- package/lib/Compilation.js +396 -65
- package/lib/Compiler.js +52 -14
- package/lib/ConcatenationScope.js +10 -3
- package/lib/ContextExclusionPlugin.js +1 -0
- package/lib/ContextModule.js +92 -47
- package/lib/ContextModuleFactory.js +45 -38
- package/lib/ContextReplacementPlugin.js +4 -0
- package/lib/DefinePlugin.js +89 -15
- package/lib/Dependency.js +111 -7
- package/lib/EntryOptionPlugin.js +39 -2
- package/lib/EntryPlugin.js +2 -0
- package/lib/ExportsInfo.js +314 -73
- package/lib/ExternalModule.js +82 -34
- package/lib/ExternalModuleFactoryPlugin.js +1 -0
- package/lib/ExternalsPlugin.js +1 -0
- package/lib/FileSystemInfo.js +173 -23
- package/lib/FlagAllModulesAsUsedPlugin.js +1 -5
- package/lib/FlagDependencyExportsPlugin.js +23 -0
- package/lib/FlagDependencyUsagePlugin.js +87 -5
- package/lib/FlagEntryExportAsUsedPlugin.js +2 -0
- package/lib/Generator.js +8 -0
- package/lib/HotModuleReplacementPlugin.js +65 -28
- package/lib/IgnorePlugin.js +1 -0
- package/lib/InitFragment.js +5 -0
- package/lib/JavascriptMetaInfoPlugin.js +7 -5
- package/lib/LazyBarrel.js +361 -0
- package/lib/LoaderTargetPlugin.js +1 -0
- package/lib/Module.js +21 -42
- package/lib/ModuleGraph.js +3 -2
- package/lib/ModuleProfile.js +27 -1
- package/lib/ModuleTemplate.js +2 -0
- package/lib/MultiCompiler.js +16 -0
- package/lib/MultiStats.js +1 -0
- package/lib/MultiWatching.js +2 -0
- package/lib/NodeStuffPlugin.js +22 -17
- package/lib/NormalModule.js +557 -77
- package/lib/NormalModuleReplacementPlugin.js +2 -0
- package/lib/PrefetchPlugin.js +2 -0
- package/lib/ProgressPlugin.js +9 -1
- package/lib/ProvidePlugin.js +1 -0
- package/lib/RawModule.js +20 -16
- package/lib/RecordIdsPlugin.js +1 -0
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimePlugin.js +58 -26
- package/lib/RuntimeTemplate.js +278 -21
- package/lib/SelfModuleFactory.js +1 -0
- package/lib/SourceMapDevToolPlugin.js +105 -30
- package/lib/Stats.js +1 -0
- package/lib/Template.js +8 -2
- package/lib/TemplatedPathPlugin.js +473 -131
- package/lib/WarnCaseSensitiveModulesPlugin.js +1 -0
- package/lib/WarnDeprecatedOptionPlugin.js +4 -0
- package/lib/WarnNoModeSetPlugin.js +1 -0
- package/lib/WatchIgnorePlugin.js +1 -0
- package/lib/Watching.js +9 -0
- package/lib/WebpackOptionsApply.js +50 -5
- package/lib/asset/AssetBytesGenerator.js +11 -3
- package/lib/asset/AssetGenerator.js +47 -22
- package/lib/asset/AssetModule.js +47 -0
- package/lib/asset/AssetModulesPlugin.js +14 -14
- package/lib/asset/AssetParser.js +2 -2
- package/lib/asset/AssetSourceGenerator.js +8 -0
- package/lib/asset/RawDataUrlModule.js +12 -13
- package/lib/buildChunkGraph.js +88 -9
- package/lib/bun/BunTargetPlugin.js +48 -0
- package/lib/cache/AddBuildDependenciesPlugin.js +1 -0
- package/lib/cache/AddManagedPathsPlugin.js +3 -0
- package/lib/cache/IdleFileCachePlugin.js +4 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +1 -0
- package/lib/cache/ResolverCachePlugin.js +2 -0
- package/lib/cache/getLazyHashedEtag.js +9 -2
- package/lib/cache/mergeEtags.js +2 -0
- package/lib/cli.js +109 -19
- package/lib/config/browserslistTargetHandler.js +99 -0
- package/lib/config/defaults.js +147 -7
- package/lib/config/defineConfig.js +31 -0
- package/lib/config/normalization.js +5 -0
- package/lib/config/target.js +181 -2
- package/lib/container/ContainerEntryModule.js +15 -14
- package/lib/container/ContainerExposedDependency.js +2 -2
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackDependency.js +5 -7
- package/lib/container/FallbackModule.js +10 -9
- package/lib/container/RemoteModule.js +20 -10
- package/lib/container/RemoteRuntimeModule.js +14 -12
- package/lib/css/CssGenerator.js +353 -327
- package/lib/css/CssInjectStyleRuntimeModule.js +36 -8
- package/lib/css/CssLoadingRuntimeModule.js +118 -47
- package/lib/css/CssModule.js +52 -23
- package/lib/css/CssModulesPlugin.js +107 -124
- package/lib/css/CssParser.js +2759 -2205
- package/lib/css/syntax.js +2859 -0
- package/lib/debug/ProfilingPlugin.js +2 -0
- package/lib/deno/DenoTargetPlugin.js +47 -0
- package/lib/dependencies/AMDDefineDependency.js +22 -17
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +1 -0
- package/lib/dependencies/AMDRequireArrayDependency.js +7 -11
- package/lib/dependencies/AMDRequireContextDependency.js +7 -11
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -0
- package/lib/dependencies/AMDRequireDependency.js +24 -20
- package/lib/dependencies/CachedConstDependency.js +3 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +1 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +79 -31
- package/lib/dependencies/CommonJsExportsDependency.js +21 -16
- package/lib/dependencies/CommonJsExportsParserPlugin.js +230 -7
- package/lib/dependencies/CommonJsFullRequireDependency.js +27 -19
- package/lib/dependencies/CommonJsImportsParserPlugin.js +51 -16
- package/lib/dependencies/CommonJsPlugin.js +1 -1
- package/lib/dependencies/CommonJsRequireContextDependency.js +10 -13
- package/lib/dependencies/CommonJsRequireDependency.js +42 -11
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -14
- package/lib/dependencies/ConstDependency.js +16 -11
- package/lib/dependencies/ContextDependency.js +4 -0
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +23 -14
- package/lib/dependencies/CreateRequireParserPlugin.js +1 -0
- package/lib/dependencies/CreateScriptUrlDependency.js +5 -7
- package/lib/dependencies/CriticalDependencyWarning.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +512 -574
- package/lib/dependencies/CssIcssImportDependency.js +9 -9
- package/lib/dependencies/CssIcssSymbolDependency.js +22 -15
- package/lib/dependencies/CssImportDependency.js +25 -1
- package/lib/dependencies/CssUrlDependency.js +23 -14
- package/lib/dependencies/DllEntryDependency.js +9 -13
- package/lib/dependencies/ExportBindingInitFragment.js +164 -0
- package/lib/dependencies/ExportsInfoDependency.js +12 -12
- package/lib/dependencies/ExternalModuleDependency.js +8 -5
- package/lib/dependencies/ExternalModuleInitFragment.js +7 -5
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +13 -10
- package/lib/dependencies/HarmonyAcceptDependency.js +11 -11
- package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +47 -22
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +28 -2
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +46 -22
- package/lib/dependencies/HarmonyExportExpressionDependency.js +107 -30
- package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -9
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +109 -31
- package/lib/dependencies/HarmonyExportInitFragment.js +22 -20
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +83 -18
- package/lib/dependencies/HarmonyExports.js +4 -1
- package/lib/dependencies/HarmonyImportDependency.js +24 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +110 -74
- package/lib/dependencies/HarmonyImportGuard.js +254 -0
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +18 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +118 -14
- package/lib/dependencies/HarmonyLinkingError.js +1 -0
- package/lib/dependencies/HarmonyModulesPlugin.js +1 -0
- package/lib/dependencies/{HtmlScriptSrcDependency.js → HtmlEntryDependency.js} +267 -154
- package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
- package/lib/dependencies/HtmlInlineScriptDependency.js +20 -27
- package/lib/dependencies/HtmlInlineStyleDependency.js +62 -11
- package/lib/dependencies/HtmlSourceDependency.js +18 -0
- package/lib/dependencies/ImportContextDependency.js +5 -9
- package/lib/dependencies/ImportDependency.js +44 -2
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -0
- package/lib/dependencies/ImportMetaPlugin.js +74 -30
- package/lib/dependencies/ImportParserPlugin.js +19 -0
- package/lib/dependencies/ImportWeakDependency.js +1 -0
- package/lib/dependencies/JsonExportsDependency.js +9 -9
- package/lib/dependencies/LoaderImportDependency.js +1 -0
- package/lib/dependencies/LocalModule.js +11 -12
- package/lib/dependencies/LocalModuleDependency.js +11 -13
- package/lib/dependencies/ModuleDecoratorDependency.js +9 -9
- package/lib/dependencies/ModuleDependency.js +7 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +1 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +15 -11
- package/lib/dependencies/ProvidedDependency.js +31 -27
- package/lib/dependencies/PureExpressionDependency.js +7 -9
- package/lib/dependencies/RequireEnsureDependency.js +12 -13
- package/lib/dependencies/RequireHeaderDependency.js +3 -4
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
- package/lib/dependencies/RequireResolveContextDependency.js +7 -11
- package/lib/dependencies/RequireResolveDependency.js +1 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +3 -5
- package/lib/dependencies/RuntimeRequirementsDependency.js +6 -7
- package/lib/dependencies/StaticExportsDependency.js +10 -10
- package/lib/dependencies/SystemPlugin.js +2 -0
- package/lib/dependencies/URLContextDependency.js +5 -7
- package/lib/dependencies/URLDependency.js +14 -16
- package/lib/dependencies/UnsupportedDependency.js +8 -13
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +11 -16
- package/lib/dependencies/WebAssemblyImportDependency.js +14 -16
- package/lib/dependencies/WebpackIsIncludedDependency.js +1 -0
- package/lib/dependencies/WorkerDependency.js +19 -8
- package/lib/dependencies/WorkerPlugin.js +40 -10
- package/lib/dependencies/processExportInfo.js +13 -11
- package/lib/dll/DelegatedModule.js +29 -15
- package/lib/dll/DelegatedModuleFactoryPlugin.js +1 -0
- package/lib/dll/DelegatedPlugin.js +1 -0
- package/lib/dll/DllEntryPlugin.js +3 -0
- package/lib/dll/DllModule.js +3 -2
- package/lib/dll/DllPlugin.js +16 -0
- package/lib/dll/DllReferencePlugin.js +3 -0
- package/lib/dll/LibManifestPlugin.js +1 -0
- package/lib/electron/ElectronTargetPlugin.js +22 -4
- package/lib/errors/ConcurrentCompilationError.js +1 -0
- package/lib/errors/HookWebpackError.js +11 -13
- package/lib/errors/IgnoreErrorModuleFactory.js +1 -0
- package/lib/errors/InvalidDependenciesModuleWarning.js +2 -0
- package/lib/errors/JSONParseError.js +9 -8
- package/lib/errors/ModuleBuildError.js +16 -13
- package/lib/errors/ModuleDependencyError.js +8 -1
- package/lib/errors/ModuleDependencyWarning.js +8 -1
- package/lib/errors/ModuleError.js +5 -11
- package/lib/errors/ModuleHashingError.js +4 -0
- package/lib/errors/ModuleNotFoundError.js +3 -0
- package/lib/errors/ModuleParseError.js +5 -11
- package/lib/errors/ModuleRestoreError.js +2 -0
- package/lib/errors/ModuleStoreError.js +3 -0
- package/lib/errors/ModuleWarning.js +7 -11
- package/lib/errors/NodeStuffInWebError.js +1 -0
- package/lib/errors/NonErrorEmittedError.js +2 -0
- package/lib/errors/UnhandledSchemeError.js +1 -0
- package/lib/esm/ModuleChunkLoadingPlugin.js +0 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +28 -23
- package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +7 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
- package/lib/hmr/LazyCompilationPlugin.js +134 -6
- package/lib/html/HtmlGenerator.js +292 -50
- package/lib/html/HtmlModule.js +40 -0
- package/lib/html/HtmlModulesPlugin.js +287 -60
- package/lib/html/HtmlParser.js +1108 -1099
- package/lib/html/{walkHtmlTokens.js → syntax.js} +4701 -212
- package/lib/ids/IdHelpers.js +4 -2
- package/lib/index.js +19 -0
- package/lib/javascript/BasicEvaluatedExpression.js +1 -0
- package/lib/javascript/EnableChunkLoadingPlugin.js +1 -0
- package/lib/javascript/JavascriptGenerator.js +6 -2
- package/lib/javascript/JavascriptModule.js +54 -0
- package/lib/javascript/JavascriptModulesPlugin.js +257 -102
- package/lib/javascript/JavascriptParser.js +286 -159
- package/lib/json/JsonModule.js +40 -0
- package/lib/json/JsonModulesPlugin.js +7 -0
- package/lib/json/JsonParser.js +4 -2
- package/lib/library/AssignLibraryPlugin.js +5 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -0
- package/lib/library/FalseIIFEUmdWarning.js +1 -0
- package/lib/library/ModuleLibraryPlugin.js +54 -29
- package/lib/library/SystemLibraryPlugin.js +3 -3
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/node/NodeWatchFileSystem.js +38 -22
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -9
- package/lib/node/RequireChunkLoadingRuntimeModule.js +18 -16
- package/lib/optimize/ConcatenatedModule.js +397 -78
- package/lib/optimize/ConstExportsPlugin.js +211 -0
- package/lib/optimize/InlineExports.js +178 -0
- package/lib/optimize/InnerGraph.js +372 -275
- package/lib/optimize/InnerGraphPlugin.js +196 -99
- package/lib/optimize/ModuleConcatenationPlugin.js +56 -25
- package/lib/optimize/RealContentHashPlugin.js +14 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +234 -64
- package/lib/runtime/AsyncModuleRuntimeModule.js +32 -30
- package/lib/runtime/AutoPublicPathRuntimeModule.js +11 -5
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +6 -4
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +33 -4
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +82 -3
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +18 -13
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +39 -26
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
- package/lib/runtime/RelativeUrlRuntimeModule.js +3 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
- package/lib/runtime/StartupEntrypointRuntimeModule.js +4 -3
- package/lib/runtime/WorkerRuntimeModule.js +33 -0
- package/lib/schemes/HttpUriPlugin.js +3 -2
- package/lib/serialization/AggregateErrorSerializer.js +7 -6
- package/lib/serialization/ArraySerializer.js +4 -8
- package/lib/serialization/BinaryMiddleware.js +538 -468
- package/lib/serialization/DateObjectSerializer.js +2 -2
- package/lib/serialization/ErrorObjectSerializer.js +7 -6
- package/lib/serialization/MapObjectSerializer.js +5 -9
- package/lib/serialization/NullPrototypeObjectSerializer.js +7 -9
- package/lib/serialization/ObjectMiddleware.js +50 -13
- package/lib/serialization/PlainObjectSerializer.js +9 -8
- package/lib/serialization/RegExpObjectSerializer.js +2 -2
- package/lib/serialization/Serializer.js +1 -0
- package/lib/serialization/SetObjectSerializer.js +4 -8
- package/lib/sharing/ConsumeSharedModule.js +6 -7
- package/lib/sharing/ConsumeSharedPlugin.js +1 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +46 -41
- package/lib/sharing/ProvideSharedDependency.js +30 -15
- package/lib/sharing/ProvideSharedModule.js +30 -11
- package/lib/sharing/ProvideSharedPlugin.js +4 -2
- package/lib/sharing/SharePlugin.js +3 -0
- package/lib/sharing/ShareRuntimeModule.js +18 -16
- package/lib/sharing/resolveMatchedConfigs.js +2 -1
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +4 -6
- package/lib/stats/DefaultStatsPrinterPlugin.js +14 -14
- package/lib/stats/StatsFactory.js +11 -9
- package/lib/stats/StatsPrinter.js +9 -2
- package/lib/url/URLParserPlugin.js +5 -2
- package/lib/util/AsyncQueue.js +10 -0
- package/lib/util/LazyBucketSortedSet.js +5 -0
- package/lib/util/LazySet.js +6 -4
- package/lib/util/LocConverter.js +11 -1
- package/lib/util/Semaphore.js +1 -0
- package/lib/util/SourceProcessor.js +106 -0
- package/lib/util/TupleSet.js +1 -0
- package/lib/util/WeakTupleMap.js +27 -1
- package/lib/util/chainedImports.js +3 -3
- package/lib/util/comparators.js +2 -2
- package/lib/util/concatenate.js +31 -7
- package/lib/util/createHash.js +0 -1
- package/lib/util/deterministicGrouping.js +19 -12
- package/lib/util/extractSourceMap.js +1 -1
- package/lib/util/findGraphRoots.js +2 -0
- package/lib/util/fs.js +16 -6
- package/lib/util/hash/DebugHash.js +1 -0
- package/lib/util/hash/hash-digest.js +24 -15
- package/lib/util/identifier.js +7 -0
- package/lib/util/internalSerializables.js +11 -2
- package/lib/util/magicComment.js +42 -0
- package/lib/util/makeSerializable.js +1 -0
- package/lib/util/nonNumericOnlyHash.js +30 -1
- package/lib/util/property.js +7 -1
- package/lib/util/publicPathPlaceholder.js +64 -0
- package/lib/util/registerExternalSerializer.js +4 -4
- package/lib/wasm-async/AsyncWasmModule.js +77 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -96
- package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +1 -1
- package/lib/wasm-sync/SyncWasmModule.js +39 -0
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +1 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -3
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +10 -0
- package/lib/wasm-sync/WebAssemblyParser.js +7 -3
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +45 -39
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +11 -10
- package/package.json +36 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +212 -3
- package/schemas/plugins/HtmlGeneratorOptions.check.js +1 -1
- package/schemas/plugins/HtmlParserOptions.check.d.ts +7 -0
- package/schemas/plugins/HtmlParserOptions.check.js +6 -0
- package/schemas/plugins/HtmlParserOptions.json +3 -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 +1592 -314
- package/lib/css/walkCssTokens.js +0 -2020
- package/lib/util/AppendOnlyStackedSet.js +0 -93
|
@@ -11,8 +11,8 @@ const {
|
|
|
11
11
|
VariableInfo,
|
|
12
12
|
getImportAttributes
|
|
13
13
|
} = require("../javascript/JavascriptParser");
|
|
14
|
-
const
|
|
15
|
-
const
|
|
14
|
+
const { getInnerGraphUtils } = require("../optimize/InnerGraph");
|
|
15
|
+
const memoize = require("../util/memoize");
|
|
16
16
|
const ConstDependency = require("./ConstDependency");
|
|
17
17
|
const HarmonyAcceptDependency = require("./HarmonyAcceptDependency");
|
|
18
18
|
const HarmonyAcceptImportDependency = require("./HarmonyAcceptImportDependency");
|
|
@@ -32,6 +32,7 @@ const { ImportPhaseUtils, createGetImportPhase } = require("./ImportPhase");
|
|
|
32
32
|
/** @typedef {import("estree").MemberExpression} MemberExpression */
|
|
33
33
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
|
34
34
|
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
|
35
|
+
/** @typedef {import("../Module")} Module */
|
|
35
36
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
|
36
37
|
/** @typedef {import("../javascript/JavascriptParser").ExportAllDeclaration} ExportAllDeclaration */
|
|
37
38
|
/** @typedef {import("../javascript/JavascriptParser").ExportNamedDeclaration} ExportNamedDeclaration */
|
|
@@ -43,17 +44,18 @@ const { ImportPhaseUtils, createGetImportPhase } = require("./ImportPhase");
|
|
|
43
44
|
/** @typedef {import("./HarmonyImportDependency").Ids} Ids */
|
|
44
45
|
/** @typedef {import("./HarmonyImportDependency").ExportPresenceMode} ExportPresenceMode */
|
|
45
46
|
/** @typedef {import("./ImportPhase").ImportPhaseType} ImportPhaseType */
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Defines the harmony specifier guards type used by this module.
|
|
49
|
-
* @typedef {object} HarmonySpecifierGuards
|
|
50
|
-
* @property {AppendOnlyStackedSet<string> | undefined} guards
|
|
51
|
-
*/
|
|
47
|
+
/** @typedef {import("./HarmonyImportGuard").GuardFrame} GuardFrame */
|
|
52
48
|
|
|
53
49
|
/** @typedef {Map<string, Set<string>>} Guards Map of import root to guarded member keys */
|
|
54
50
|
|
|
51
|
+
const getHarmonyImportGuard = memoize(() => require("./HarmonyImportGuard"));
|
|
52
|
+
|
|
55
53
|
const harmonySpecifierTag = Symbol("harmony import");
|
|
56
|
-
|
|
54
|
+
|
|
55
|
+
// Shared placeholder: plain specifier references have no member ranges, so they
|
|
56
|
+
// can all reuse one (never-mutated) array instead of allocating per dependency.
|
|
57
|
+
/** @type {Range[]} */
|
|
58
|
+
const EMPTY_ID_RANGES = [];
|
|
57
59
|
|
|
58
60
|
/**
|
|
59
61
|
* Defines the harmony settings type used by this module.
|
|
@@ -109,18 +111,51 @@ const getInOperatorHarmonyImportInfo = (parser, left, right) => {
|
|
|
109
111
|
};
|
|
110
112
|
};
|
|
111
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Whether the conditional test references an imported binding (so a dependency
|
|
116
|
+
* guard can possibly gate a dead branch). Cheap pre-scan over the test AST.
|
|
117
|
+
* @param {JavascriptParser} parser the parser
|
|
118
|
+
* @param {Expression} node test expression
|
|
119
|
+
* @returns {boolean} true when the test references a harmony import specifier
|
|
120
|
+
*/
|
|
121
|
+
const findImportSpecifier = (parser, node) => {
|
|
122
|
+
switch (node.type) {
|
|
123
|
+
case "Identifier":
|
|
124
|
+
return Boolean(parser.getTagData(node.name, harmonySpecifierTag));
|
|
125
|
+
case "UnaryExpression":
|
|
126
|
+
return findImportSpecifier(
|
|
127
|
+
parser,
|
|
128
|
+
/** @type {Expression} */ (node.argument)
|
|
129
|
+
);
|
|
130
|
+
case "LogicalExpression":
|
|
131
|
+
return (
|
|
132
|
+
findImportSpecifier(parser, /** @type {Expression} */ (node.left)) ||
|
|
133
|
+
findImportSpecifier(parser, /** @type {Expression} */ (node.right))
|
|
134
|
+
);
|
|
135
|
+
case "MemberExpression":
|
|
136
|
+
return findImportSpecifier(
|
|
137
|
+
parser,
|
|
138
|
+
/** @type {Expression} */ (node.object)
|
|
139
|
+
);
|
|
140
|
+
default:
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
112
145
|
module.exports = class HarmonyImportDependencyParserPlugin {
|
|
113
146
|
/**
|
|
114
147
|
* Creates an instance of HarmonyImportDependencyParserPlugin.
|
|
115
148
|
* @param {JavascriptParserOptions} options options
|
|
116
149
|
*/
|
|
117
150
|
constructor(options) {
|
|
151
|
+
/** @type {JavascriptParserOptions} */
|
|
118
152
|
this.options = options;
|
|
119
153
|
/** @type {ExportPresenceMode} */
|
|
120
154
|
this.exportPresenceMode = ExportPresenceModes.resolveFromOptions(
|
|
121
155
|
options.importExportsPresence,
|
|
122
156
|
options
|
|
123
157
|
);
|
|
158
|
+
/** @type {boolean | undefined} */
|
|
124
159
|
this.strictThisContextOnImports = options.strictThisContextOnImports;
|
|
125
160
|
}
|
|
126
161
|
|
|
@@ -140,12 +175,21 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
140
175
|
);
|
|
141
176
|
if (!harmonySettings) return this.exportPresenceMode;
|
|
142
177
|
|
|
143
|
-
const
|
|
144
|
-
parser.
|
|
178
|
+
const stack = /** @type {GuardFrame[] | undefined} */ (
|
|
179
|
+
parser.state.guardStack
|
|
145
180
|
);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
181
|
+
if (stack !== undefined) {
|
|
182
|
+
const name = harmonySettings.name;
|
|
183
|
+
const member = ids[0];
|
|
184
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
185
|
+
const presence = stack[i].presence;
|
|
186
|
+
if (presence !== undefined) {
|
|
187
|
+
const members = presence.get(name);
|
|
188
|
+
if (members !== undefined && members.has(member)) {
|
|
189
|
+
return ExportPresenceModes.NONE;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
149
193
|
}
|
|
150
194
|
|
|
151
195
|
return this.exportPresenceMode;
|
|
@@ -263,7 +307,10 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
263
307
|
);
|
|
264
308
|
dep.loc = /** @type {DependencyLocation} */ (expression.loc);
|
|
265
309
|
parser.state.module.addDependency(dep);
|
|
266
|
-
|
|
310
|
+
getInnerGraphUtils(parser.state.compilation).onUsage(
|
|
311
|
+
parser.state,
|
|
312
|
+
(e) => (dep.usedByExports = e)
|
|
313
|
+
);
|
|
267
314
|
return true;
|
|
268
315
|
});
|
|
269
316
|
parser.hooks.collectDestructuringAssignmentProperties.tap(
|
|
@@ -295,7 +342,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
295
342
|
this.exportPresenceMode,
|
|
296
343
|
settings.phase,
|
|
297
344
|
settings.attributes,
|
|
298
|
-
|
|
345
|
+
EMPTY_ID_RANGES
|
|
299
346
|
);
|
|
300
347
|
dep.referencedPropertiesInDestructuring =
|
|
301
348
|
parser.destructuringAssignmentPropertiesFor(expr);
|
|
@@ -307,7 +354,11 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
307
354
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
|
308
355
|
dep.call = parser.scope.inTaggedTemplateTag;
|
|
309
356
|
parser.state.module.addDependency(dep);
|
|
310
|
-
|
|
357
|
+
getHarmonyImportGuard().attachDependencyGuards(parser, dep);
|
|
358
|
+
getInnerGraphUtils(parser.state.compilation).onUsage(
|
|
359
|
+
parser.state,
|
|
360
|
+
(e) => (dep.usedByExports = e)
|
|
361
|
+
);
|
|
311
362
|
return true;
|
|
312
363
|
});
|
|
313
364
|
parser.hooks.expressionMemberChain
|
|
@@ -355,7 +406,11 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
355
406
|
);
|
|
356
407
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
|
357
408
|
parser.state.module.addDependency(dep);
|
|
358
|
-
|
|
409
|
+
getHarmonyImportGuard().attachDependencyGuards(parser, dep);
|
|
410
|
+
getInnerGraphUtils(parser.state.compilation).onUsage(
|
|
411
|
+
parser.state,
|
|
412
|
+
(e) => (dep.usedByExports = e)
|
|
413
|
+
);
|
|
359
414
|
return true;
|
|
360
415
|
}
|
|
361
416
|
);
|
|
@@ -408,8 +463,12 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
408
463
|
/** @type {boolean} */ (this.strictThisContextOnImports);
|
|
409
464
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
|
410
465
|
parser.state.module.addDependency(dep);
|
|
466
|
+
getHarmonyImportGuard().attachDependencyGuards(parser, dep);
|
|
411
467
|
if (args) parser.walkExpressions(args);
|
|
412
|
-
|
|
468
|
+
getInnerGraphUtils(parser.state.compilation).onUsage(
|
|
469
|
+
parser.state,
|
|
470
|
+
(e) => (dep.usedByExports = e)
|
|
471
|
+
);
|
|
413
472
|
return true;
|
|
414
473
|
}
|
|
415
474
|
);
|
|
@@ -481,55 +540,14 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
481
540
|
}
|
|
482
541
|
});
|
|
483
542
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
* @param {Guards} guards guards
|
|
487
|
-
* @param {() => void} walk walk callback
|
|
488
|
-
* @returns {void}
|
|
489
|
-
*/
|
|
490
|
-
const withGuards = (guards, walk) => {
|
|
491
|
-
const applyGuards = () => {
|
|
492
|
-
/** @type {(() => void)[]} */
|
|
493
|
-
const restoreFns = [];
|
|
494
|
-
|
|
495
|
-
for (const [rootName, members] of guards) {
|
|
496
|
-
const previous = parser.getVariableInfo(rootName);
|
|
497
|
-
const exist = /** @type {HarmonySpecifierGuards=} */ (
|
|
498
|
-
parser.getTagData(rootName, harmonySpecifierGuardTag)
|
|
499
|
-
);
|
|
500
|
-
|
|
501
|
-
const mergedGuards =
|
|
502
|
-
exist && exist.guards
|
|
503
|
-
? exist.guards.createChild()
|
|
504
|
-
: new AppendOnlyStackedSet();
|
|
505
|
-
|
|
506
|
-
for (const memberKey of members) mergedGuards.add(memberKey);
|
|
507
|
-
parser.tagVariable(rootName, harmonySpecifierGuardTag, {
|
|
508
|
-
guards: mergedGuards
|
|
509
|
-
});
|
|
510
|
-
restoreFns.push(() => {
|
|
511
|
-
parser.setVariable(rootName, previous);
|
|
512
|
-
});
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
return () => {
|
|
516
|
-
for (const restore of restoreFns) {
|
|
517
|
-
restore();
|
|
518
|
-
}
|
|
519
|
-
};
|
|
520
|
-
};
|
|
521
|
-
|
|
522
|
-
const restore = applyGuards();
|
|
523
|
-
try {
|
|
524
|
-
walk();
|
|
525
|
-
} finally {
|
|
526
|
-
restore();
|
|
527
|
-
}
|
|
528
|
-
};
|
|
543
|
+
parser.hooks.collectGuards.tap(PLUGIN_NAME, (expression) => {
|
|
544
|
+
if (parser.scope.isAsmJs) return;
|
|
529
545
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
546
|
+
// Presence guards: `"x" in ns` checks that suppress export-presence errors
|
|
547
|
+
// (consequent only).
|
|
548
|
+
/** @type {Guards | undefined} */
|
|
549
|
+
let presence;
|
|
550
|
+
if (this.exportPresenceMode !== ExportPresenceModes.NONE) {
|
|
533
551
|
/** @type {Guards} */
|
|
534
552
|
const guards = new Map();
|
|
535
553
|
|
|
@@ -596,14 +614,32 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
|
596
614
|
|
|
597
615
|
collect(expression, true);
|
|
598
616
|
|
|
599
|
-
if (guards.size
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
617
|
+
if (guards.size > 0) presence = guards;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
const hasSpecifier = findImportSpecifier(parser, expression);
|
|
621
|
+
const depStart = hasSpecifier
|
|
622
|
+
? /** @type {Module} */ (parser.state.module).dependencies.length
|
|
623
|
+
: undefined;
|
|
624
|
+
|
|
625
|
+
if (presence === undefined && depStart === undefined) return;
|
|
626
|
+
|
|
627
|
+
/** @type {GuardFrame} */
|
|
628
|
+
const consequent = {
|
|
629
|
+
presence,
|
|
630
|
+
test: expression,
|
|
631
|
+
depStart,
|
|
632
|
+
condition: true
|
|
633
|
+
};
|
|
634
|
+
/** @type {GuardFrame | undefined} */
|
|
635
|
+
const alternate =
|
|
636
|
+
depStart === undefined
|
|
637
|
+
? undefined
|
|
638
|
+
: { test: expression, depStart, condition: false };
|
|
639
|
+
|
|
640
|
+
return { consequent, alternate };
|
|
641
|
+
});
|
|
605
642
|
}
|
|
606
643
|
};
|
|
607
644
|
|
|
608
|
-
module.exports.harmonySpecifierGuardTag = harmonySpecifierGuardTag;
|
|
609
645
|
module.exports.harmonySpecifierTag = harmonySpecifierTag;
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Haijie Xie @hai-x
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const { InlinedUsedName } = require("../optimize/InlineExports");
|
|
9
|
+
const memoize = require("../util/memoize");
|
|
10
|
+
|
|
11
|
+
/** @typedef {import("estree").Expression} Expression */
|
|
12
|
+
/** @typedef {import("../Dependency")} Dependency */
|
|
13
|
+
/** @typedef {import("../Module")} Module */
|
|
14
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
15
|
+
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
|
16
|
+
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
17
|
+
/** @typedef {import("./CommonJsRequireDependency")} CommonJsRequireDependency */
|
|
18
|
+
/** @typedef {import("./HarmonyImportSpecifierDependency")} HarmonyImportSpecifierDependency */
|
|
19
|
+
/** @typedef {import("./ImportDependency")} ImportDependency */
|
|
20
|
+
|
|
21
|
+
// Tuple-encoded boolean formula over guard dependencies. Split into per-shape
|
|
22
|
+
// aliases so the recursive references resolve through array/object types.
|
|
23
|
+
/** @typedef {["v", Dependency]} GuardAtom */
|
|
24
|
+
/** @typedef {["?"]} GuardUnknown */
|
|
25
|
+
/** @typedef {["!", GuardFormula]} GuardNot */
|
|
26
|
+
/** @typedef {["&&" | "||" | "??", GuardFormula, GuardFormula]} GuardLogical */
|
|
27
|
+
/** @typedef {GuardAtom | GuardUnknown | GuardNot | GuardLogical} GuardFormula */
|
|
28
|
+
/** @typedef {{ formula: GuardFormula, value: boolean }} DependencyGuard branch guard: the dependency is live only when the formula evaluates to `value` */
|
|
29
|
+
/** @typedef {HarmonyImportSpecifierDependency | CommonJsRequireDependency | ImportDependency} GuardableDependency */
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A guard frame pushed onto `parser.state.guardStack` for the duration of one
|
|
33
|
+
* conditional branch body. Carries the `"x" in ns` presence guards and/or the
|
|
34
|
+
* dead-branch dependency guard for that branch.
|
|
35
|
+
* @typedef {object} GuardFrame
|
|
36
|
+
* @property {Map<string, Set<string>>=} presence `"x" in ns` presence guards active in this branch
|
|
37
|
+
* @property {Expression=} test the conditional test (for the lazily built formula)
|
|
38
|
+
* @property {number=} depStart dependency count before the test was walked
|
|
39
|
+
* @property {boolean=} condition branch truthiness the dependency guard is live for
|
|
40
|
+
* @property {GuardFormula | null=} formula memoized formula (null = no knowable atom)
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
const getHarmonyImportSpecifierDependency = memoize(() =>
|
|
44
|
+
require("./HarmonyImportSpecifierDependency")
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
// Tri-state truthiness: UNKNOWN means not statically known.
|
|
48
|
+
const UNKNOWN = 0;
|
|
49
|
+
const FALSE = 1;
|
|
50
|
+
const TRUE = 2;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {number} t tri-state value
|
|
54
|
+
* @returns {number} negated tri-state
|
|
55
|
+
*/
|
|
56
|
+
const flip = (t) => (t === TRUE ? FALSE : t === FALSE ? TRUE : UNKNOWN);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param {boolean} b boolean
|
|
60
|
+
* @returns {number} tri-state value
|
|
61
|
+
*/
|
|
62
|
+
const fromBool = (b) => (b ? TRUE : FALSE);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Build a guard formula from a conditional test AST.
|
|
66
|
+
* @param {Expression} test conditional test expression
|
|
67
|
+
* @param {Map<number, HarmonyImportSpecifierDependency>} depByRangeStart import-specifier deps in the test, keyed by range start
|
|
68
|
+
* @returns {GuardFormula | null} formula, or null when it has no knowable atom
|
|
69
|
+
*/
|
|
70
|
+
const buildGuardFormula = (test, depByRangeStart) => {
|
|
71
|
+
/**
|
|
72
|
+
* @param {Expression} node ast node
|
|
73
|
+
* @returns {GuardFormula} formula node
|
|
74
|
+
*/
|
|
75
|
+
const build = (node) => {
|
|
76
|
+
if (node.type === "UnaryExpression" && node.operator === "!") {
|
|
77
|
+
return ["!", build(/** @type {Expression} */ (node.argument))];
|
|
78
|
+
}
|
|
79
|
+
if (
|
|
80
|
+
node.type === "LogicalExpression" &&
|
|
81
|
+
(node.operator === "&&" ||
|
|
82
|
+
node.operator === "||" ||
|
|
83
|
+
node.operator === "??")
|
|
84
|
+
) {
|
|
85
|
+
return [
|
|
86
|
+
node.operator,
|
|
87
|
+
build(/** @type {Expression} */ (node.left)),
|
|
88
|
+
build(/** @type {Expression} */ (node.right))
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
const dep =
|
|
92
|
+
node.range && depByRangeStart.get(/** @type {number} */ (node.range[0]));
|
|
93
|
+
return dep ? ["v", dep] : ["?"];
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const formula = build(test);
|
|
97
|
+
return hasAtom(formula) ? formula : null;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @param {GuardFormula} formula formula
|
|
102
|
+
* @returns {boolean} true when the formula contains at least one atom
|
|
103
|
+
*/
|
|
104
|
+
const hasAtom = (formula) => {
|
|
105
|
+
switch (formula[0]) {
|
|
106
|
+
case "v":
|
|
107
|
+
return true;
|
|
108
|
+
case "!":
|
|
109
|
+
return hasAtom(formula[1]);
|
|
110
|
+
case "&&":
|
|
111
|
+
case "||":
|
|
112
|
+
case "??":
|
|
113
|
+
return hasAtom(formula[1]) || hasAtom(formula[2]);
|
|
114
|
+
default:
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @param {GuardFormula} formula formula
|
|
121
|
+
* @param {ModuleGraph} moduleGraph module graph
|
|
122
|
+
* @param {RuntimeSpec} runtime runtime
|
|
123
|
+
* @returns {{ t: number, n: number }} truthy `t` and null `n` tri-states
|
|
124
|
+
*/
|
|
125
|
+
const evalNode = (formula, moduleGraph, runtime) => {
|
|
126
|
+
switch (formula[0]) {
|
|
127
|
+
case "v": {
|
|
128
|
+
const dep = /** @type {HarmonyImportSpecifierDependency} */ (formula[1]);
|
|
129
|
+
const module = moduleGraph.getModule(dep);
|
|
130
|
+
if (!module) return { t: UNKNOWN, n: UNKNOWN };
|
|
131
|
+
const used = moduleGraph
|
|
132
|
+
.getExportsInfo(module)
|
|
133
|
+
.getUsedName(dep.getIds(moduleGraph), runtime);
|
|
134
|
+
// Only a bare inlined primitive is knowable; a property suffix is not.
|
|
135
|
+
if (!(used instanceof InlinedUsedName) || used.suffix.length !== 0) {
|
|
136
|
+
return { t: UNKNOWN, n: UNKNOWN };
|
|
137
|
+
}
|
|
138
|
+
const value = used.value;
|
|
139
|
+
const nullish = value.kind === "null" || value.kind === "undefined";
|
|
140
|
+
return {
|
|
141
|
+
t: fromBool(!nullish && Boolean(value.value)),
|
|
142
|
+
n: fromBool(nullish)
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
case "!":
|
|
146
|
+
// `!x` always yields a boolean → never nullish.
|
|
147
|
+
return {
|
|
148
|
+
t: flip(evalNode(formula[1], moduleGraph, runtime).t),
|
|
149
|
+
n: FALSE
|
|
150
|
+
};
|
|
151
|
+
case "&&": {
|
|
152
|
+
const l = evalNode(formula[1], moduleGraph, runtime);
|
|
153
|
+
const r = evalNode(formula[2], moduleGraph, runtime);
|
|
154
|
+
const t =
|
|
155
|
+
l.t === FALSE || r.t === FALSE
|
|
156
|
+
? FALSE
|
|
157
|
+
: l.t === TRUE && r.t === TRUE
|
|
158
|
+
? TRUE
|
|
159
|
+
: UNKNOWN;
|
|
160
|
+
return { t, n: UNKNOWN };
|
|
161
|
+
}
|
|
162
|
+
case "||": {
|
|
163
|
+
const l = evalNode(formula[1], moduleGraph, runtime);
|
|
164
|
+
const r = evalNode(formula[2], moduleGraph, runtime);
|
|
165
|
+
const t =
|
|
166
|
+
l.t === TRUE || r.t === TRUE
|
|
167
|
+
? TRUE
|
|
168
|
+
: l.t === FALSE && r.t === FALSE
|
|
169
|
+
? FALSE
|
|
170
|
+
: UNKNOWN;
|
|
171
|
+
return { t, n: UNKNOWN };
|
|
172
|
+
}
|
|
173
|
+
case "??": {
|
|
174
|
+
const l = evalNode(formula[1], moduleGraph, runtime);
|
|
175
|
+
const r = evalNode(formula[2], moduleGraph, runtime);
|
|
176
|
+
// `l ?? r` is l when l non-nullish, else r.
|
|
177
|
+
const t =
|
|
178
|
+
l.n === FALSE ? l.t : l.n === TRUE ? r.t : l.t === r.t ? l.t : UNKNOWN;
|
|
179
|
+
return { t, n: UNKNOWN };
|
|
180
|
+
}
|
|
181
|
+
default:
|
|
182
|
+
return { t: UNKNOWN, n: UNKNOWN };
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Whether any guard proves its branch dead.
|
|
188
|
+
* @param {DependencyGuard[]} guards dependency guards
|
|
189
|
+
* @param {ModuleGraph} moduleGraph module graph
|
|
190
|
+
* @param {RuntimeSpec} runtime runtime
|
|
191
|
+
* @returns {boolean} true when a test is provably the opposite of its branch
|
|
192
|
+
*/
|
|
193
|
+
const isDeadByGuards = (guards, moduleGraph, runtime) => {
|
|
194
|
+
for (const guard of guards) {
|
|
195
|
+
const t = evalNode(guard.formula, moduleGraph, runtime).t;
|
|
196
|
+
if (t !== UNKNOWN && t !== (guard.value ? TRUE : FALSE)) return true;
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Builds (once) the dependency-guard formula for a frame from the import
|
|
203
|
+
* specifier deps created while walking the test.
|
|
204
|
+
* @param {JavascriptParser} parser the parser
|
|
205
|
+
* @param {GuardFrame} frame guard frame
|
|
206
|
+
* @returns {GuardFormula | null} formula, or null when it has no knowable atom
|
|
207
|
+
*/
|
|
208
|
+
const buildFrameFormula = (parser, frame) => {
|
|
209
|
+
const HarmonyImportSpecifierDependency =
|
|
210
|
+
getHarmonyImportSpecifierDependency();
|
|
211
|
+
const deps = /** @type {Module} */ (parser.state.module).dependencies;
|
|
212
|
+
/** @type {Map<number, HarmonyImportSpecifierDependency>} */
|
|
213
|
+
const depByRangeStart = new Map();
|
|
214
|
+
for (let i = /** @type {number} */ (frame.depStart); i < deps.length; i++) {
|
|
215
|
+
const dep = deps[i];
|
|
216
|
+
if (dep instanceof HarmonyImportSpecifierDependency && dep.range) {
|
|
217
|
+
depByRangeStart.set(dep.range[0], dep);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return buildGuardFormula(
|
|
221
|
+
/** @type {Expression} */ (frame.test),
|
|
222
|
+
depByRangeStart
|
|
223
|
+
);
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Tags a freshly created dependency with the active dependency guards.
|
|
228
|
+
* @param {JavascriptParser} parser the parser
|
|
229
|
+
* @param {GuardableDependency} dep the dependency
|
|
230
|
+
*/
|
|
231
|
+
const attachDependencyGuards = (parser, dep) => {
|
|
232
|
+
const stack = /** @type {GuardFrame[] | undefined} */ (
|
|
233
|
+
parser.state.guardStack
|
|
234
|
+
);
|
|
235
|
+
if (stack === undefined || stack.length === 0) return;
|
|
236
|
+
/** @type {DependencyGuard[] | undefined} */
|
|
237
|
+
let guards;
|
|
238
|
+
for (const frame of stack) {
|
|
239
|
+
if (frame.depStart === undefined) continue;
|
|
240
|
+
let formula = frame.formula;
|
|
241
|
+
if (formula === undefined) {
|
|
242
|
+
formula = frame.formula = buildFrameFormula(parser, frame);
|
|
243
|
+
}
|
|
244
|
+
if (formula === null) continue;
|
|
245
|
+
(guards || (guards = [])).push({
|
|
246
|
+
formula,
|
|
247
|
+
value: /** @type {boolean} */ (frame.condition)
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
if (guards !== undefined) dep.branchGuards = guards;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
module.exports.attachDependencyGuards = attachDependencyGuards;
|
|
254
|
+
module.exports.isDeadByGuards = isDeadByGuards;
|
|
@@ -5,14 +5,15 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
+
const Dependency = require("../Dependency");
|
|
8
9
|
const Module = require("../Module");
|
|
9
10
|
const { JAVASCRIPT_TYPE } = require("../ModuleSourceTypeConstants");
|
|
10
11
|
const makeSerializable = require("../util/makeSerializable");
|
|
11
12
|
const HarmonyImportDependency = require("./HarmonyImportDependency");
|
|
12
13
|
|
|
13
14
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
14
|
-
/** @typedef {import("../Dependency")} Dependency */
|
|
15
15
|
/** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */
|
|
16
|
+
/** @typedef {import("../Dependency").LazyUntil} LazyUntil */
|
|
16
17
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
|
17
18
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
18
19
|
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
|
@@ -35,6 +36,22 @@ class HarmonyImportSideEffectDependency extends HarmonyImportDependency {
|
|
|
35
36
|
return "harmony side effect evaluation";
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Returns the export name this dependency requests from its target module (lazy barrel optimization).
|
|
41
|
+
* @returns {string | true | null} export name, true for all exports, null for none
|
|
42
|
+
*/
|
|
43
|
+
getForwardId() {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Returns how this dependency may be deferred when its parent module is side-effect-free (lazy barrel optimization).
|
|
49
|
+
* @returns {LazyUntil | null} lazy classification, null when it must be processed eagerly
|
|
50
|
+
*/
|
|
51
|
+
getLazyUntil() {
|
|
52
|
+
return Dependency.LAZY_UNTIL_REQUEST;
|
|
53
|
+
}
|
|
54
|
+
|
|
38
55
|
/**
|
|
39
56
|
* Returns function to determine if the connection is active.
|
|
40
57
|
* @param {ModuleGraph} moduleGraph module graph
|