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
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
const { UsageState } = require("../ExportsInfo");
|
|
9
9
|
const JavascriptParser = require("../javascript/JavascriptParser");
|
|
10
10
|
|
|
11
|
+
/** @typedef {import("../Compilation")} Compilation */
|
|
11
12
|
/** @typedef {import("../Dependency")} Dependency */
|
|
12
13
|
/** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */
|
|
13
14
|
/** @typedef {import("../Module")} Module */
|
|
@@ -15,11 +16,12 @@ const JavascriptParser = require("../javascript/JavascriptParser");
|
|
|
15
16
|
/** @typedef {import("../Parser").ParserState} ParserState */
|
|
16
17
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
17
18
|
|
|
19
|
+
/** @typedef {boolean | ((compilation: Compilation, module: Module) => boolean)} PureCondition */
|
|
18
20
|
/** @typedef {Set<string | TopLevelSymbol>} InnerGraphValueSet */
|
|
19
21
|
/** @typedef {InnerGraphValueSet | true} InnerGraphValue */
|
|
20
22
|
/** @typedef {TopLevelSymbol | null} InnerGraphKey */
|
|
21
23
|
/** @typedef {Map<InnerGraphKey, InnerGraphValue | undefined>} InnerGraph */
|
|
22
|
-
/** @typedef {(value: boolean | Set<string> | undefined) => void} UsageCallback */
|
|
24
|
+
/** @typedef {(value: boolean | Set<string> | undefined, module: Module) => void} UsageCallback */
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
27
|
* Defines the state object type used by this module.
|
|
@@ -30,225 +32,398 @@ const JavascriptParser = require("../javascript/JavascriptParser");
|
|
|
30
32
|
*/
|
|
31
33
|
|
|
32
34
|
/** @typedef {false | StateObject} State */
|
|
35
|
+
/** @typedef {string | TopLevelSymbol | true} Usage */
|
|
36
|
+
/** @typedef {Set<string> | boolean} UsedByExports */
|
|
37
|
+
/** @typedef {Dependency & { usedByExports: UsedByExports | undefined }} DependencyWithUsedByExports */
|
|
33
38
|
|
|
34
39
|
class TopLevelSymbol {
|
|
35
40
|
/**
|
|
36
41
|
* Creates an instance of TopLevelSymbol.
|
|
37
42
|
* @param {string} name name of the variable
|
|
43
|
+
* @param {PureCondition=} pure pure condition
|
|
38
44
|
*/
|
|
39
|
-
constructor(name) {
|
|
45
|
+
constructor(name, pure = false) {
|
|
40
46
|
/** @type {string} */
|
|
41
47
|
this.name = name;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
48
|
|
|
45
|
-
|
|
49
|
+
/** @type {boolean} */
|
|
50
|
+
this.conditional = false;
|
|
51
|
+
/** @type {boolean} */
|
|
52
|
+
this._pure = false;
|
|
53
|
+
/** @type {((compilation: Compilation, module: Module) => boolean) | undefined} */
|
|
54
|
+
this.pureFn = undefined;
|
|
46
55
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const topLevelSymbolTag = Symbol("top level symbol");
|
|
56
|
+
this.setPure(pure);
|
|
57
|
+
}
|
|
50
58
|
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Sets the pure condition
|
|
61
|
+
* @param {PureCondition} pure pure condition
|
|
62
|
+
* @returns {void}
|
|
63
|
+
*/
|
|
64
|
+
setPure(pure) {
|
|
65
|
+
this.conditional = typeof pure === "function";
|
|
66
|
+
this._pure = pure === true;
|
|
67
|
+
this.pureFn = typeof pure === "function" ? pure : undefined;
|
|
68
|
+
}
|
|
59
69
|
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (usage === true) {
|
|
74
|
-
innerGraph.set(symbol, true);
|
|
75
|
-
} else if (info === undefined) {
|
|
76
|
-
innerGraph.set(symbol, new Set([usage]));
|
|
77
|
-
} else if (info !== true) {
|
|
78
|
-
info.add(usage);
|
|
79
|
-
}
|
|
70
|
+
/**
|
|
71
|
+
* @param {Compilation} compilation compilation
|
|
72
|
+
* @param {Module} module module
|
|
73
|
+
* @returns {boolean} if the symbol is pure
|
|
74
|
+
*/
|
|
75
|
+
isPure(compilation, module) {
|
|
76
|
+
if (!this.conditional) return this._pure;
|
|
77
|
+
|
|
78
|
+
const pureFn =
|
|
79
|
+
/** @type {(compilation: Compilation, module: Module) => boolean} */ (
|
|
80
|
+
this.pureFn
|
|
81
|
+
);
|
|
82
|
+
return pureFn(compilation, module);
|
|
80
83
|
}
|
|
81
|
-
}
|
|
84
|
+
}
|
|
82
85
|
|
|
83
|
-
|
|
86
|
+
module.exports.TopLevelSymbol = TopLevelSymbol;
|
|
84
87
|
|
|
85
|
-
|
|
86
|
-
* Processes the provided parser.
|
|
87
|
-
* @param {JavascriptParser} parser the parser
|
|
88
|
-
* @param {string} name name of variable
|
|
89
|
-
* @param {Usage} usage usage data
|
|
90
|
-
* @returns {void}
|
|
91
|
-
*/
|
|
92
|
-
module.exports.addVariableUsage = (parser, name, usage) => {
|
|
93
|
-
const symbol =
|
|
94
|
-
/** @type {TopLevelSymbol} */ (
|
|
95
|
-
parser.getTagData(name, topLevelSymbolTag)
|
|
96
|
-
) || module.exports.tagTopLevelSymbol(parser, name);
|
|
97
|
-
if (symbol) {
|
|
98
|
-
module.exports.addUsage(parser.state, symbol, usage);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
88
|
+
const topLevelSymbolTag = Symbol("top level symbol");
|
|
101
89
|
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
* @param {ParserState} parserState parser state
|
|
105
|
-
* @returns {void}
|
|
106
|
-
*/
|
|
107
|
-
module.exports.bailout = (parserState) => {
|
|
108
|
-
parserStateMap.set(parserState, false);
|
|
109
|
-
};
|
|
90
|
+
/** @type {WeakMap<Compilation, InnerGraphUtils>} */
|
|
91
|
+
const innerGraphByCompilation = new WeakMap();
|
|
110
92
|
|
|
111
93
|
/**
|
|
112
|
-
*
|
|
113
|
-
* @
|
|
114
|
-
* @
|
|
94
|
+
* @typedef {object} InnerGraphUtils
|
|
95
|
+
* @property {(parserState: ParserState) => void} enable
|
|
96
|
+
* @property {(parserState: ParserState) => void} bailout
|
|
97
|
+
* @property {(parserState: ParserState) => boolean} isEnabled
|
|
98
|
+
* @property {(parserState: ParserState, symbol: TopLevelSymbol | null, usage: Usage) => void} addUsage
|
|
99
|
+
* @property {(parserState: ParserState, onUsageCallback: UsageCallback) => void} onUsage
|
|
100
|
+
* @property {(parserState: ParserState, symbol: TopLevelSymbol | undefined) => void} setTopLevelSymbol
|
|
101
|
+
* @property {(parserState: ParserState) => TopLevelSymbol | void} getTopLevelSymbol
|
|
102
|
+
* @property {(parser: JavascriptParser, name: string, pure?: PureCondition) => TopLevelSymbol | undefined} tagTopLevelSymbol
|
|
103
|
+
* @property {(parser: JavascriptParser, name: string, usage: Usage) => void} addVariableUsage
|
|
104
|
+
* @property {(module: Module) => void} inferDependencyUsage
|
|
105
|
+
* @property {(module: Module) => void} release
|
|
115
106
|
*/
|
|
116
|
-
module.exports.enable = (parserState) => {
|
|
117
|
-
const state = parserStateMap.get(parserState);
|
|
118
|
-
if (state === false) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
parserStateMap.set(parserState, {
|
|
122
|
-
innerGraph: new Map(),
|
|
123
|
-
currentTopLevelSymbol: undefined,
|
|
124
|
-
usageCallbackMap: new Map()
|
|
125
|
-
});
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
/** @typedef {Set<string> | boolean} UsedByExports */
|
|
129
107
|
|
|
130
108
|
/**
|
|
131
|
-
*
|
|
109
|
+
* Returns false, when unused. Otherwise true.
|
|
132
110
|
* @param {Dependency} dependency the dependency
|
|
133
111
|
* @param {UsedByExports | undefined} usedByExports usedByExports info
|
|
134
112
|
* @param {ModuleGraph} moduleGraph moduleGraph
|
|
135
|
-
* @
|
|
113
|
+
* @param {RuntimeSpec} runtime runtime
|
|
114
|
+
* @returns {boolean} false, when unused. Otherwise true
|
|
136
115
|
*/
|
|
137
|
-
|
|
116
|
+
function isDependencyUsedByExports(
|
|
138
117
|
dependency,
|
|
139
118
|
usedByExports,
|
|
140
|
-
moduleGraph
|
|
141
|
-
|
|
119
|
+
moduleGraph,
|
|
120
|
+
runtime
|
|
121
|
+
) {
|
|
142
122
|
if (usedByExports === false) return false;
|
|
143
123
|
if (usedByExports !== true && usedByExports !== undefined) {
|
|
144
124
|
const selfModule =
|
|
145
125
|
/** @type {Module} */
|
|
146
126
|
(moduleGraph.getParentModule(dependency));
|
|
147
127
|
const exportsInfo = moduleGraph.getExportsInfo(selfModule);
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
128
|
+
for (const exportName of usedByExports) {
|
|
129
|
+
if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused) {
|
|
130
|
+
return true;
|
|
153
131
|
}
|
|
154
|
-
|
|
155
|
-
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
156
134
|
}
|
|
157
|
-
return
|
|
158
|
-
}
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
159
137
|
|
|
160
138
|
/**
|
|
161
|
-
* Returns
|
|
162
|
-
* @param {
|
|
163
|
-
* @
|
|
139
|
+
* Returns dependency condition
|
|
140
|
+
* @param {Dependency} dependency the dependency
|
|
141
|
+
* @param {ModuleGraph} moduleGraph moduleGraph
|
|
142
|
+
* @returns {null | false | GetConditionFn} function to determine if the connection is active
|
|
164
143
|
*/
|
|
165
|
-
module.exports.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
144
|
+
module.exports.getDependencyUsedByExportsCondition = (
|
|
145
|
+
dependency,
|
|
146
|
+
moduleGraph
|
|
147
|
+
) => {
|
|
148
|
+
switch (
|
|
149
|
+
/** @type {DependencyWithUsedByExports} */ (dependency).usedByExports
|
|
150
|
+
) {
|
|
151
|
+
case false:
|
|
152
|
+
return false;
|
|
153
|
+
case true:
|
|
154
|
+
return null;
|
|
155
|
+
default:
|
|
156
|
+
return (_connections, runtime) =>
|
|
157
|
+
isDependencyUsedByExports(
|
|
158
|
+
dependency,
|
|
159
|
+
/** @type {DependencyWithUsedByExports} */ (dependency).usedByExports,
|
|
160
|
+
moduleGraph,
|
|
161
|
+
runtime
|
|
162
|
+
);
|
|
170
163
|
}
|
|
171
164
|
};
|
|
172
165
|
|
|
173
166
|
/**
|
|
174
|
-
*
|
|
175
|
-
* @param {
|
|
176
|
-
* @returns {
|
|
167
|
+
* Returns the InnerGraph utils scoped to a single compilation.
|
|
168
|
+
* @param {Compilation} compilation the compilation
|
|
169
|
+
* @returns {InnerGraphUtils} utils
|
|
177
170
|
*/
|
|
178
|
-
module.exports.
|
|
179
|
-
|
|
171
|
+
module.exports.getInnerGraphUtils = (compilation) => {
|
|
172
|
+
let utils = innerGraphByCompilation.get(compilation);
|
|
173
|
+
if (utils) return utils;
|
|
174
|
+
|
|
175
|
+
/** @type {WeakMap<Module, State>} */
|
|
176
|
+
const states = new WeakMap();
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @param {ParserState} parserState parser state
|
|
180
|
+
* @returns {State | undefined} state
|
|
181
|
+
*/
|
|
182
|
+
function getState(parserState) {
|
|
183
|
+
return states.get(parserState.module);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @param {ParserState} parserState parser state
|
|
188
|
+
* @returns {void}
|
|
189
|
+
*/
|
|
190
|
+
function enable(parserState) {
|
|
191
|
+
const state = states.get(parserState.module);
|
|
192
|
+
if (state === false) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
states.set(parserState.module, {
|
|
196
|
+
innerGraph: new Map(),
|
|
197
|
+
currentTopLevelSymbol: undefined,
|
|
198
|
+
usageCallbackMap: new Map()
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @param {ParserState} parserState parser state
|
|
204
|
+
* @returns {void}
|
|
205
|
+
*/
|
|
206
|
+
function bailout(parserState) {
|
|
207
|
+
states.set(parserState.module, false);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* @param {ParserState} parserState parser state
|
|
212
|
+
* @returns {boolean} true, when enabled
|
|
213
|
+
*/
|
|
214
|
+
function isEnabled(parserState) {
|
|
215
|
+
return Boolean(states.get(parserState.module));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @param {ParserState} state parser state
|
|
220
|
+
* @param {TopLevelSymbol | null} symbol the symbol, or null for all symbols
|
|
221
|
+
* @param {Usage} usage usage data
|
|
222
|
+
* @returns {void}
|
|
223
|
+
*/
|
|
224
|
+
function addUsage(state, symbol, usage) {
|
|
225
|
+
const innerGraphState = getState(state);
|
|
226
|
+
|
|
227
|
+
if (innerGraphState) {
|
|
228
|
+
const { innerGraph } = innerGraphState;
|
|
229
|
+
const info = innerGraph.get(symbol);
|
|
230
|
+
if (usage === true) {
|
|
231
|
+
innerGraph.set(symbol, true);
|
|
232
|
+
} else if (info === undefined) {
|
|
233
|
+
innerGraph.set(symbol, new Set([usage]));
|
|
234
|
+
} else if (info !== true) {
|
|
235
|
+
info.add(usage);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* @param {JavascriptParser} parser the parser
|
|
242
|
+
* @param {string} name name of variable
|
|
243
|
+
* @param {Usage} usage usage data
|
|
244
|
+
* @returns {void}
|
|
245
|
+
*/
|
|
246
|
+
function addVariableUsage(parser, name, usage) {
|
|
247
|
+
const symbol =
|
|
248
|
+
/** @type {TopLevelSymbol} */ (
|
|
249
|
+
parser.getTagData(name, topLevelSymbolTag)
|
|
250
|
+
) || tagTopLevelSymbol(parser, name);
|
|
251
|
+
if (symbol) {
|
|
252
|
+
addUsage(parser.state, symbol, usage);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* @param {ParserState} state parser state
|
|
258
|
+
* @returns {TopLevelSymbol | void} usage data
|
|
259
|
+
*/
|
|
260
|
+
function getTopLevelSymbol(state) {
|
|
261
|
+
const innerGraphState = getState(state);
|
|
262
|
+
|
|
263
|
+
if (innerGraphState) {
|
|
264
|
+
return innerGraphState.currentTopLevelSymbol;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
180
267
|
|
|
181
|
-
|
|
182
|
-
|
|
268
|
+
/**
|
|
269
|
+
* @param {ParserState} state parser state
|
|
270
|
+
* @param {TopLevelSymbol | undefined} symbol the symbol
|
|
271
|
+
*/
|
|
272
|
+
function setTopLevelSymbol(state, symbol) {
|
|
273
|
+
const innerGraphState = getState(state);
|
|
274
|
+
|
|
275
|
+
if (innerGraphState) {
|
|
276
|
+
innerGraphState.currentTopLevelSymbol = symbol;
|
|
277
|
+
}
|
|
183
278
|
}
|
|
184
279
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
280
|
+
/**
|
|
281
|
+
* @param {ParserState} state parser state
|
|
282
|
+
* @param {UsageCallback} onUsageCallback on usage callback
|
|
283
|
+
*/
|
|
284
|
+
function onUsage(state, onUsageCallback) {
|
|
285
|
+
const innerGraphState = getState(state);
|
|
286
|
+
|
|
287
|
+
if (innerGraphState) {
|
|
288
|
+
const { usageCallbackMap, currentTopLevelSymbol } = innerGraphState;
|
|
289
|
+
if (currentTopLevelSymbol) {
|
|
290
|
+
let callbacks = usageCallbackMap.get(currentTopLevelSymbol);
|
|
291
|
+
|
|
292
|
+
if (callbacks === undefined) {
|
|
293
|
+
/** @type {Set<UsageCallback>} */
|
|
294
|
+
callbacks = new Set();
|
|
295
|
+
usageCallbackMap.set(currentTopLevelSymbol, callbacks);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
callbacks.add(onUsageCallback);
|
|
299
|
+
} else {
|
|
300
|
+
onUsageCallback(true, state.module);
|
|
201
301
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
302
|
+
} else {
|
|
303
|
+
onUsageCallback(undefined, state.module);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* @param {JavascriptParser} parser parser
|
|
309
|
+
* @param {string} name name of variable
|
|
310
|
+
* @param {PureCondition=} pure pure condition
|
|
311
|
+
* @returns {TopLevelSymbol=} symbol
|
|
312
|
+
*/
|
|
313
|
+
function tagTopLevelSymbol(parser, name, pure) {
|
|
314
|
+
const innerGraphState = getState(parser.state);
|
|
315
|
+
if (!innerGraphState) return;
|
|
316
|
+
|
|
317
|
+
parser.defineVariable(name);
|
|
318
|
+
|
|
319
|
+
const existingTag = /** @type {TopLevelSymbol} */ (
|
|
320
|
+
parser.getTagData(name, topLevelSymbolTag)
|
|
321
|
+
);
|
|
322
|
+
if (existingTag) {
|
|
323
|
+
if (pure !== undefined) {
|
|
324
|
+
existingTag.setPure(pure);
|
|
325
|
+
}
|
|
326
|
+
return existingTag;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const symbol = new TopLevelSymbol(name, pure);
|
|
330
|
+
parser.tagVariable(
|
|
331
|
+
name,
|
|
332
|
+
topLevelSymbolTag,
|
|
333
|
+
symbol,
|
|
334
|
+
JavascriptParser.VariableInfoFlags.Normal
|
|
335
|
+
);
|
|
336
|
+
return symbol;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* @param {Module} module module
|
|
341
|
+
* @returns {void}
|
|
342
|
+
*/
|
|
343
|
+
function inferDependencyUsage(module) {
|
|
344
|
+
const innerGraphState = states.get(module);
|
|
345
|
+
|
|
346
|
+
if (!innerGraphState) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const { innerGraph, usageCallbackMap } = innerGraphState;
|
|
351
|
+
/** @type {Map<InnerGraphKey, InnerGraphValueSet | undefined>} */
|
|
352
|
+
const processed = new Map();
|
|
353
|
+
// flatten graph to terminal nodes (string, undefined or true)
|
|
354
|
+
const nonTerminal = new Set(innerGraph.keys());
|
|
355
|
+
while (nonTerminal.size > 0) {
|
|
356
|
+
for (const key of nonTerminal) {
|
|
357
|
+
if (key !== null && !key.isPure(compilation, module)) {
|
|
358
|
+
innerGraph.set(key, true);
|
|
359
|
+
nonTerminal.delete(key);
|
|
360
|
+
continue;
|
|
205
361
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
362
|
+
|
|
363
|
+
/** @type {InnerGraphValue} */
|
|
364
|
+
let newSet = new Set();
|
|
365
|
+
let isTerminal = true;
|
|
366
|
+
const value = innerGraph.get(key);
|
|
367
|
+
let alreadyProcessed = processed.get(key);
|
|
368
|
+
if (alreadyProcessed === undefined) {
|
|
369
|
+
/** @type {InnerGraphValueSet} */
|
|
370
|
+
alreadyProcessed = new Set();
|
|
371
|
+
processed.set(key, alreadyProcessed);
|
|
372
|
+
}
|
|
373
|
+
if (value !== true && value !== undefined) {
|
|
374
|
+
for (const item of value) {
|
|
375
|
+
alreadyProcessed.add(item);
|
|
376
|
+
}
|
|
377
|
+
for (const item of value) {
|
|
378
|
+
if (typeof item === "string") {
|
|
379
|
+
newSet.add(item);
|
|
380
|
+
} else if (!item.isPure(compilation, module)) {
|
|
212
381
|
newSet = true;
|
|
213
382
|
break;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
383
|
+
} else {
|
|
384
|
+
const itemValue = innerGraph.get(item);
|
|
385
|
+
if (itemValue === true) {
|
|
386
|
+
newSet = true;
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
if (itemValue !== undefined) {
|
|
390
|
+
for (const i of itemValue) {
|
|
391
|
+
if (i === key) continue;
|
|
392
|
+
if (alreadyProcessed.has(i)) continue;
|
|
393
|
+
newSet.add(i);
|
|
394
|
+
if (typeof i !== "string") {
|
|
395
|
+
isTerminal = false;
|
|
396
|
+
}
|
|
222
397
|
}
|
|
223
398
|
}
|
|
224
399
|
}
|
|
225
400
|
}
|
|
401
|
+
if (newSet === true) {
|
|
402
|
+
innerGraph.set(key, true);
|
|
403
|
+
} else if (newSet.size === 0) {
|
|
404
|
+
innerGraph.set(key, undefined);
|
|
405
|
+
} else {
|
|
406
|
+
innerGraph.set(key, newSet);
|
|
407
|
+
}
|
|
226
408
|
}
|
|
227
|
-
if (
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
if (globalValue === true) {
|
|
245
|
-
innerGraph.set(key, true);
|
|
246
|
-
} else {
|
|
247
|
-
const newSet = new Set(value);
|
|
248
|
-
for (const item of globalValue) {
|
|
249
|
-
newSet.add(item);
|
|
409
|
+
if (isTerminal) {
|
|
410
|
+
nonTerminal.delete(key);
|
|
411
|
+
|
|
412
|
+
// For the global key, merge with all other keys
|
|
413
|
+
if (key === null) {
|
|
414
|
+
const globalValue = innerGraph.get(null);
|
|
415
|
+
if (globalValue) {
|
|
416
|
+
for (const [key, value] of innerGraph) {
|
|
417
|
+
if (key !== null && value !== true) {
|
|
418
|
+
if (globalValue === true) {
|
|
419
|
+
innerGraph.set(key, true);
|
|
420
|
+
} else {
|
|
421
|
+
const newSet = new Set(value);
|
|
422
|
+
for (const item of globalValue) {
|
|
423
|
+
newSet.add(item);
|
|
424
|
+
}
|
|
425
|
+
innerGraph.set(key, newSet);
|
|
250
426
|
}
|
|
251
|
-
innerGraph.set(key, newSet);
|
|
252
427
|
}
|
|
253
428
|
}
|
|
254
429
|
}
|
|
@@ -256,128 +431,50 @@ module.exports.inferDependencyUsage = (state) => {
|
|
|
256
431
|
}
|
|
257
432
|
}
|
|
258
433
|
}
|
|
259
|
-
}
|
|
260
434
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
for (const callback of callbacks) {
|
|
267
|
-
callback(usage === undefined ? false : usage);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
};
|
|
435
|
+
/** @type {Map<Dependency, true | Set<string>>} */
|
|
436
|
+
for (const [symbol, callbacks] of usageCallbackMap) {
|
|
437
|
+
const usage = symbol.isPure(compilation, module)
|
|
438
|
+
? /** @type {true | Set<string> | undefined} */ (innerGraph.get(symbol))
|
|
439
|
+
: true;
|
|
271
440
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
* @param {Dependency} dependency the dependency
|
|
275
|
-
* @param {UsedByExports | undefined} usedByExports usedByExports info
|
|
276
|
-
* @param {ModuleGraph} moduleGraph moduleGraph
|
|
277
|
-
* @param {RuntimeSpec} runtime runtime
|
|
278
|
-
* @returns {boolean} false, when unused. Otherwise true
|
|
279
|
-
*/
|
|
280
|
-
module.exports.isDependencyUsedByExports = (
|
|
281
|
-
dependency,
|
|
282
|
-
usedByExports,
|
|
283
|
-
moduleGraph,
|
|
284
|
-
runtime
|
|
285
|
-
) => {
|
|
286
|
-
if (usedByExports === false) return false;
|
|
287
|
-
if (usedByExports !== true && usedByExports !== undefined) {
|
|
288
|
-
const selfModule =
|
|
289
|
-
/** @type {Module} */
|
|
290
|
-
(moduleGraph.getParentModule(dependency));
|
|
291
|
-
const exportsInfo = moduleGraph.getExportsInfo(selfModule);
|
|
292
|
-
let used = false;
|
|
293
|
-
for (const exportName of usedByExports) {
|
|
294
|
-
if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused) {
|
|
295
|
-
used = true;
|
|
441
|
+
for (const callback of callbacks) {
|
|
442
|
+
callback(usage === undefined ? false : usage, module);
|
|
296
443
|
}
|
|
297
444
|
}
|
|
298
|
-
if (!used) return false;
|
|
299
445
|
}
|
|
300
|
-
return true;
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Returns true, when enabled.
|
|
305
|
-
* @param {ParserState} parserState parser state
|
|
306
|
-
* @returns {boolean} true, when enabled
|
|
307
|
-
*/
|
|
308
|
-
module.exports.isEnabled = (parserState) => {
|
|
309
|
-
const state = parserStateMap.get(parserState);
|
|
310
|
-
return Boolean(state);
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Processes the provided state.
|
|
315
|
-
* @param {ParserState} state parser state
|
|
316
|
-
* @param {UsageCallback} onUsageCallback on usage callback
|
|
317
|
-
*/
|
|
318
|
-
module.exports.onUsage = (state, onUsageCallback) => {
|
|
319
|
-
const innerGraphState = getState(state);
|
|
320
|
-
|
|
321
|
-
if (innerGraphState) {
|
|
322
|
-
const { usageCallbackMap, currentTopLevelSymbol } = innerGraphState;
|
|
323
|
-
if (currentTopLevelSymbol) {
|
|
324
|
-
let callbacks = usageCallbackMap.get(currentTopLevelSymbol);
|
|
325
|
-
|
|
326
|
-
if (callbacks === undefined) {
|
|
327
|
-
/** @type {Set<UsageCallback>} */
|
|
328
|
-
callbacks = new Set();
|
|
329
|
-
usageCallbackMap.set(currentTopLevelSymbol, callbacks);
|
|
330
|
-
}
|
|
331
446
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
447
|
+
/**
|
|
448
|
+
* @param {Module} module module
|
|
449
|
+
* @returns {void}
|
|
450
|
+
*/
|
|
451
|
+
function release(module) {
|
|
452
|
+
states.delete(module);
|
|
338
453
|
}
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Processes the provided state.
|
|
343
|
-
* @param {ParserState} state parser state
|
|
344
|
-
* @param {TopLevelSymbol | undefined} symbol the symbol
|
|
345
|
-
*/
|
|
346
|
-
module.exports.setTopLevelSymbol = (state, symbol) => {
|
|
347
|
-
const innerGraphState = getState(state);
|
|
348
454
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
455
|
+
utils = {
|
|
456
|
+
enable,
|
|
457
|
+
bailout,
|
|
458
|
+
isEnabled,
|
|
459
|
+
addUsage,
|
|
460
|
+
addVariableUsage,
|
|
461
|
+
getTopLevelSymbol,
|
|
462
|
+
setTopLevelSymbol,
|
|
463
|
+
onUsage,
|
|
464
|
+
tagTopLevelSymbol,
|
|
465
|
+
inferDependencyUsage,
|
|
466
|
+
release
|
|
467
|
+
};
|
|
468
|
+
innerGraphByCompilation.set(compilation, utils);
|
|
469
|
+
return utils;
|
|
352
470
|
};
|
|
353
471
|
|
|
354
472
|
/**
|
|
355
|
-
*
|
|
356
|
-
* @param {
|
|
357
|
-
* @param {
|
|
358
|
-
* @
|
|
473
|
+
* Usage callback map.
|
|
474
|
+
* @param {Dependency} dependency the dependency
|
|
475
|
+
* @param {UsedByExports | undefined} usedByExports usedByExports info
|
|
476
|
+
* @param {ModuleGraph} moduleGraph moduleGraph
|
|
477
|
+
* @returns {null | false | GetConditionFn} function to determine if the connection is active
|
|
359
478
|
*/
|
|
360
|
-
module.exports.tagTopLevelSymbol = (parser, name) => {
|
|
361
|
-
const innerGraphState = getState(parser.state);
|
|
362
|
-
if (!innerGraphState) return;
|
|
363
|
-
|
|
364
|
-
parser.defineVariable(name);
|
|
365
|
-
|
|
366
|
-
const existingTag = /** @type {TopLevelSymbol} */ (
|
|
367
|
-
parser.getTagData(name, topLevelSymbolTag)
|
|
368
|
-
);
|
|
369
|
-
if (existingTag) {
|
|
370
|
-
return existingTag;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
const symbol = new TopLevelSymbol(name);
|
|
374
|
-
parser.tagVariable(
|
|
375
|
-
name,
|
|
376
|
-
topLevelSymbolTag,
|
|
377
|
-
symbol,
|
|
378
|
-
JavascriptParser.VariableInfoFlags.Normal
|
|
379
|
-
);
|
|
380
|
-
return symbol;
|
|
381
|
-
};
|
|
382
479
|
|
|
383
480
|
module.exports.topLevelSymbolTag = topLevelSymbolTag;
|