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
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
const { HTML_TYPE } = require("../ModuleSourceTypeConstants");
|
|
8
|
+
const makeSerializable = require("../util/makeSerializable");
|
|
9
|
+
const ModuleDependency = require("./ModuleDependency");
|
|
10
|
+
|
|
11
|
+
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
12
|
+
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
|
|
13
|
+
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
|
14
|
+
/** @typedef {import("../Dependency")} Dependency */
|
|
15
|
+
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
|
16
|
+
/** @typedef {import("../Module")} Module */
|
|
17
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
18
|
+
/** @typedef {import("../util/Hash")} Hash */
|
|
19
|
+
|
|
20
|
+
// One pass over the source: each char is replaced once and replacements aren't
|
|
21
|
+
// re-scanned, so this matches the `&`-first sequential escape chain exactly.
|
|
22
|
+
const ATTR_ESCAPE_REGEXP = /[&"']/g;
|
|
23
|
+
/** @type {Record<string, string>} */
|
|
24
|
+
const ATTR_ESCAPES = { "&": "&", '"': """, "'": "'" };
|
|
25
|
+
/**
|
|
26
|
+
* @param {string} c matched character
|
|
27
|
+
* @returns {string} the HTML-attribute-escaped entity
|
|
28
|
+
*/
|
|
29
|
+
const escapeAttrChar = (c) => ATTR_ESCAPES[c];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Represents an `<iframe srcdoc="...">` attribute — an entity-encoded HTML
|
|
33
|
+
* document. The decoded document is fed back through webpack's HTML pipeline as
|
|
34
|
+
* a virtual `data:text/html` module so its asset URLs resolve relative to the
|
|
35
|
+
* host HTML file. At render time the attribute value is replaced with the
|
|
36
|
+
* processed HTML read from the nested module's `html` code-generation data,
|
|
37
|
+
* re-escaped so the surrounding attribute stays valid.
|
|
38
|
+
*/
|
|
39
|
+
class HtmlInlineHtmlDependency extends ModuleDependency {
|
|
40
|
+
/**
|
|
41
|
+
* @param {string} request virtual request resolving to the inline HTML (data URI)
|
|
42
|
+
* @param {Range} range range of the `srcdoc` attribute value
|
|
43
|
+
*/
|
|
44
|
+
constructor(request, range) {
|
|
45
|
+
super(request);
|
|
46
|
+
this.range = range;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get type() {
|
|
50
|
+
return "html inline html";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get category() {
|
|
54
|
+
return "html-srcdoc";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Updates the hash with the data contributed by this instance.
|
|
59
|
+
* @param {Hash} hash hash to be updated
|
|
60
|
+
* @param {UpdateHashContext} context context
|
|
61
|
+
* @returns {void}
|
|
62
|
+
*/
|
|
63
|
+
updateHash(hash, context) {
|
|
64
|
+
// Recurse so the inline HTML's transitive deps (assets) propagate up.
|
|
65
|
+
// The module is guaranteed — it is registered as a code-generation dependency.
|
|
66
|
+
const module = /** @type {Module} */ (
|
|
67
|
+
context.chunkGraph.moduleGraph.getModule(this)
|
|
68
|
+
);
|
|
69
|
+
module.updateHash(hash, context);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
HtmlInlineHtmlDependency.Template = class HtmlInlineHtmlDependencyTemplate extends (
|
|
74
|
+
ModuleDependency.Template
|
|
75
|
+
) {
|
|
76
|
+
/**
|
|
77
|
+
* Applies the plugin by registering its hooks on the compiler.
|
|
78
|
+
* @param {Dependency} dependency the dependency for which the template should be applied
|
|
79
|
+
* @param {ReplaceSource} source the current replace source which can be modified
|
|
80
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
|
81
|
+
* @returns {void}
|
|
82
|
+
*/
|
|
83
|
+
apply(dependency, source, { moduleGraph, runtime, codeGenerationResults }) {
|
|
84
|
+
const dep = /** @type {HtmlInlineHtmlDependency} */ (dependency);
|
|
85
|
+
// The module is guaranteed — it is registered as a code-generation dependency.
|
|
86
|
+
const module = /** @type {Module} */ (moduleGraph.getModule(dep));
|
|
87
|
+
const codeGen =
|
|
88
|
+
/** @type {CodeGenerationResults} */
|
|
89
|
+
(codeGenerationResults).get(module, runtime);
|
|
90
|
+
const htmlSource = codeGen.sources.get(HTML_TYPE);
|
|
91
|
+
|
|
92
|
+
// The attribute value was entity-decoded before parsing, so re-escape the
|
|
93
|
+
// processed HTML to keep the surrounding `srcdoc="..."` attribute valid.
|
|
94
|
+
const htmlText = (
|
|
95
|
+
htmlSource ? /** @type {string} */ (htmlSource.source()) : ""
|
|
96
|
+
).replace(ATTR_ESCAPE_REGEXP, escapeAttrChar);
|
|
97
|
+
|
|
98
|
+
source.replace(dep.range[0], dep.range[1] - 1, htmlText);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
makeSerializable(
|
|
103
|
+
HtmlInlineHtmlDependency,
|
|
104
|
+
"webpack/lib/dependencies/HtmlInlineHtmlDependency"
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
module.exports = HtmlInlineHtmlDependency;
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
"use strict";
|
|
6
6
|
|
|
7
|
+
const HtmlGenerator = require("../html/HtmlGenerator");
|
|
7
8
|
const makeSerializable = require("../util/makeSerializable");
|
|
8
|
-
const CssUrlDependency = require("./CssUrlDependency");
|
|
9
9
|
const ModuleDependency = require("./ModuleDependency");
|
|
10
10
|
|
|
11
11
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
@@ -14,8 +14,8 @@ const ModuleDependency = require("./ModuleDependency");
|
|
|
14
14
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
|
15
15
|
/** @typedef {import("../Entrypoint")} Entrypoint */
|
|
16
16
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
17
|
-
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
18
|
-
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
17
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[number, Range, string, string]>} ObjectDeserializerContext */
|
|
18
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[number, Range, string, string]>} ObjectSerializerContext */
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Represents an inline `<script>...</script>` block in an HTML module. The
|
|
@@ -34,9 +34,11 @@ class HtmlInlineScriptDependency extends ModuleDependency {
|
|
|
34
34
|
*/
|
|
35
35
|
constructor(request, insertPos, contentRange, entryName, category) {
|
|
36
36
|
super(request);
|
|
37
|
+
/** @type {number} */
|
|
37
38
|
this.insertPos = insertPos;
|
|
38
39
|
this.contentRange = contentRange;
|
|
39
40
|
this.range = contentRange;
|
|
41
|
+
/** @type {string} */
|
|
40
42
|
this.entryName = entryName;
|
|
41
43
|
/** @type {string} */
|
|
42
44
|
this._category = category || "commonjs";
|
|
@@ -55,11 +57,11 @@ class HtmlInlineScriptDependency extends ModuleDependency {
|
|
|
55
57
|
* @param {ObjectSerializerContext} context context
|
|
56
58
|
*/
|
|
57
59
|
serialize(context) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
context
|
|
61
|
+
.write(this.insertPos)
|
|
62
|
+
.write(this.contentRange)
|
|
63
|
+
.write(this.entryName)
|
|
64
|
+
.write(this._category);
|
|
63
65
|
super.serialize(context);
|
|
64
66
|
}
|
|
65
67
|
|
|
@@ -68,13 +70,15 @@ class HtmlInlineScriptDependency extends ModuleDependency {
|
|
|
68
70
|
* @param {ObjectDeserializerContext} context context
|
|
69
71
|
*/
|
|
70
72
|
deserialize(context) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
this.contentRange = read();
|
|
73
|
+
this.insertPos = context.read();
|
|
74
|
+
const c1 = context.rest;
|
|
75
|
+
this.contentRange = c1.read();
|
|
74
76
|
this.range = this.contentRange;
|
|
75
|
-
|
|
76
|
-
this.
|
|
77
|
-
|
|
77
|
+
const c2 = c1.rest;
|
|
78
|
+
this.entryName = c2.read();
|
|
79
|
+
const c3 = c2.rest;
|
|
80
|
+
this._category = c3.read();
|
|
81
|
+
super.deserialize(c3.rest);
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
|
|
@@ -101,19 +105,8 @@ HtmlInlineScriptDependency.Template = class HtmlInlineScriptDependencyTemplate e
|
|
|
101
105
|
|
|
102
106
|
if (entrypoint) {
|
|
103
107
|
const chunk = /** @type {Chunk} */ (entrypoint.getEntrypointChunk());
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
chunk.filenameTemplate ||
|
|
107
|
-
(chunk.canBeInitial()
|
|
108
|
-
? outputOptions.filename
|
|
109
|
-
: outputOptions.chunkFilename);
|
|
110
|
-
|
|
111
|
-
const filename = compilation.getPath(filenameTemplate, {
|
|
112
|
-
chunk,
|
|
113
|
-
contentHashType: "javascript"
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
url = `${CssUrlDependency.PUBLIC_PATH_AUTO}${filename}`;
|
|
108
|
+
// Defer chunk-URL substitution to renderManifest — chunk hashes aren't ready yet.
|
|
109
|
+
url = HtmlGenerator.makeChunkUrlSentinel(chunk, "javascript");
|
|
117
110
|
}
|
|
118
111
|
|
|
119
112
|
// Insert ` src="…"` right after `<script` so the inline body is
|
|
@@ -10,31 +10,54 @@ const ModuleDependency = require("./ModuleDependency");
|
|
|
10
10
|
|
|
11
11
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
12
12
|
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
|
|
13
|
+
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
|
13
14
|
/** @typedef {import("../Dependency")} Dependency */
|
|
14
15
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
|
15
16
|
/** @typedef {import("../Module")} Module */
|
|
17
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
|
16
18
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
17
|
-
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
18
|
-
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
19
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<boolean[]>} ObjectDeserializerContext */
|
|
20
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<boolean[]>} ObjectSerializerContext */
|
|
21
|
+
/** @typedef {import("../util/Hash")} Hash */
|
|
19
22
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
20
23
|
|
|
24
|
+
const TRAILING_WHITESPACE_REGEXP = /\s+$/;
|
|
25
|
+
// One pass over the source: each char is replaced once and replacements aren't
|
|
26
|
+
// re-scanned, so this matches the `&`-first sequential escape chain exactly
|
|
27
|
+
// while avoiding two extra full-string scans + intermediate strings.
|
|
28
|
+
const ATTR_ESCAPE_REGEXP = /[&"']/g;
|
|
29
|
+
/** @type {Record<string, string>} */
|
|
30
|
+
const ATTR_ESCAPES = { "&": "&", '"': """, "'": "'" };
|
|
21
31
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
* @param {string} c matched character
|
|
33
|
+
* @returns {string} the HTML-attribute-escaped entity
|
|
34
|
+
*/
|
|
35
|
+
const escapeAttrChar = (c) => ATTR_ESCAPES[c];
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Represents inline CSS in an HTML module — either a `<style>...</style>`
|
|
39
|
+
* block (a stylesheet) or an element's `style="..."` attribute (a CSS
|
|
40
|
+
* block's contents). The content is fed into webpack's CSS pipeline as a
|
|
41
|
+
* virtual CSS module with `exportType: "text"` so `url()` and `\@import`
|
|
42
|
+
* references are resolved relative to the HTML file. At render time the
|
|
43
|
+
* original content range is replaced with the processed CSS text read from
|
|
44
|
+
* the CSS module's code generation data.
|
|
28
45
|
*/
|
|
29
46
|
class HtmlInlineStyleDependency extends ModuleDependency {
|
|
30
47
|
/**
|
|
31
48
|
* Creates an instance of HtmlInlineStyleDependency.
|
|
32
49
|
* @param {string} request virtual request resolving to the inline CSS (data URI)
|
|
33
|
-
* @param {Range} range range of the inline CSS content (between `<style>` and `</style
|
|
50
|
+
* @param {Range} range range of the inline CSS content (between `<style>` and `</style>`, or the `style` attribute value)
|
|
51
|
+
* @param {boolean=} attribute true when the source is a `style="..."` attribute (a block's contents) rather than a `<style>` block (stylesheet)
|
|
52
|
+
* @param {boolean=} inAttribute true when the range is an attribute value (decoded on parse, so the processed CSS must be re-escaped on write-back); defaults to `attribute` — differs only for attribute values parsed as full stylesheets
|
|
34
53
|
*/
|
|
35
|
-
constructor(request, range) {
|
|
54
|
+
constructor(request, range, attribute = false, inAttribute = attribute) {
|
|
36
55
|
super(request);
|
|
37
56
|
this.range = range;
|
|
57
|
+
/** @type {boolean} */
|
|
58
|
+
this.attribute = attribute;
|
|
59
|
+
/** @type {boolean} */
|
|
60
|
+
this.inAttribute = inAttribute;
|
|
38
61
|
}
|
|
39
62
|
|
|
40
63
|
get type() {
|
|
@@ -42,7 +65,21 @@ class HtmlInlineStyleDependency extends ModuleDependency {
|
|
|
42
65
|
}
|
|
43
66
|
|
|
44
67
|
get category() {
|
|
45
|
-
return "html-style";
|
|
68
|
+
return this.attribute ? "html-style-attribute" : "html-style";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Updates the hash with the data contributed by this instance.
|
|
73
|
+
* @param {Hash} hash hash to be updated
|
|
74
|
+
* @param {UpdateHashContext} context context
|
|
75
|
+
* @returns {void}
|
|
76
|
+
*/
|
|
77
|
+
updateHash(hash, context) {
|
|
78
|
+
// Recurse so the inline CSS's transitive deps (e.g. `url(asset)`) propagate up.
|
|
79
|
+
const { chunkGraph } = context;
|
|
80
|
+
const module = chunkGraph.moduleGraph.getModule(this);
|
|
81
|
+
if (!module) return;
|
|
82
|
+
module.updateHash(hash, context);
|
|
46
83
|
}
|
|
47
84
|
|
|
48
85
|
/**
|
|
@@ -51,6 +88,8 @@ class HtmlInlineStyleDependency extends ModuleDependency {
|
|
|
51
88
|
*/
|
|
52
89
|
serialize(context) {
|
|
53
90
|
super.serialize(context);
|
|
91
|
+
context.write(this.attribute);
|
|
92
|
+
context.write(this.inAttribute);
|
|
54
93
|
}
|
|
55
94
|
|
|
56
95
|
/**
|
|
@@ -59,6 +98,8 @@ class HtmlInlineStyleDependency extends ModuleDependency {
|
|
|
59
98
|
*/
|
|
60
99
|
deserialize(context) {
|
|
61
100
|
super.deserialize(context);
|
|
101
|
+
this.attribute = context.read();
|
|
102
|
+
this.inAttribute = context.read();
|
|
62
103
|
}
|
|
63
104
|
}
|
|
64
105
|
|
|
@@ -89,6 +130,16 @@ HtmlInlineStyleDependency.Template = class HtmlInlineStyleDependencyTemplate ext
|
|
|
89
130
|
}
|
|
90
131
|
}
|
|
91
132
|
|
|
133
|
+
// An attribute value was entity-decoded before parsing, so re-escape
|
|
134
|
+
// the processed CSS to keep the surrounding markup valid in any
|
|
135
|
+
// quoting context, and drop the trailing newline the CSS generator
|
|
136
|
+
// appends so the rewritten attribute stays on one line.
|
|
137
|
+
if (dep.inAttribute) {
|
|
138
|
+
cssText = cssText
|
|
139
|
+
.replace(TRAILING_WHITESPACE_REGEXP, "")
|
|
140
|
+
.replace(ATTR_ESCAPE_REGEXP, escapeAttrChar);
|
|
141
|
+
}
|
|
142
|
+
|
|
92
143
|
source.replace(dep.range[0], dep.range[1] - 1, cssText);
|
|
93
144
|
}
|
|
94
145
|
};
|
|
@@ -13,14 +13,17 @@ const ModuleDependency = require("./ModuleDependency");
|
|
|
13
13
|
|
|
14
14
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
15
15
|
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
|
|
16
|
+
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
|
16
17
|
/** @typedef {import("../Dependency")} Dependency */
|
|
17
18
|
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
|
18
19
|
/** @typedef {import("../Module")} Module */
|
|
20
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
|
19
21
|
/** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
|
|
20
22
|
/** @typedef {import("../Module").CodeGenerationResultData} CodeGenerationResultData */
|
|
21
23
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
22
24
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
23
25
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
26
|
+
/** @typedef {import("../util/Hash")} Hash */
|
|
24
27
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
25
28
|
|
|
26
29
|
const getIgnoredRawDataUrlModule = memoize(
|
|
@@ -55,6 +58,21 @@ class HtmlSourceDependency extends ModuleDependency {
|
|
|
55
58
|
return getIgnoredRawDataUrlModule();
|
|
56
59
|
}
|
|
57
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Updates the hash with the data contributed by this instance.
|
|
63
|
+
* @param {Hash} hash hash to be updated
|
|
64
|
+
* @param {UpdateHashContext} context context
|
|
65
|
+
* @returns {void}
|
|
66
|
+
*/
|
|
67
|
+
updateHash(hash, context) {
|
|
68
|
+
// Fold in the asset's hash so the HTML invalidates when the embedded URL changes.
|
|
69
|
+
const { chunkGraph } = context;
|
|
70
|
+
const module = chunkGraph.moduleGraph.getModule(this);
|
|
71
|
+
if (!module) return;
|
|
72
|
+
const { hash: buildHash } = /** @type {BuildInfo} */ (module.buildInfo);
|
|
73
|
+
if (buildHash) hash.update(buildHash);
|
|
74
|
+
}
|
|
75
|
+
|
|
58
76
|
/**
|
|
59
77
|
* Serializes this instance into the provided serializer context.
|
|
60
78
|
* @param {ObjectSerializerContext} context context
|
|
@@ -10,8 +10,8 @@ const ContextDependency = require("./ContextDependency");
|
|
|
10
10
|
const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
|
|
11
11
|
|
|
12
12
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
13
|
-
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
14
|
-
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
13
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[Range]>} ObjectDeserializerContext */
|
|
14
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[Range]>} ObjectSerializerContext */
|
|
15
15
|
/** @typedef {import("./ContextDependency").ContextDependencyOptions} ContextDependencyOptions */
|
|
16
16
|
|
|
17
17
|
class ImportContextDependency extends ContextDependency {
|
|
@@ -55,9 +55,7 @@ class ImportContextDependency extends ContextDependency {
|
|
|
55
55
|
* @param {ObjectSerializerContext} context context
|
|
56
56
|
*/
|
|
57
57
|
serialize(context) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
write(this.valueRange);
|
|
58
|
+
context.write(this.valueRange);
|
|
61
59
|
|
|
62
60
|
super.serialize(context);
|
|
63
61
|
}
|
|
@@ -67,11 +65,9 @@ class ImportContextDependency extends ContextDependency {
|
|
|
67
65
|
* @param {ObjectDeserializerContext} context context
|
|
68
66
|
*/
|
|
69
67
|
deserialize(context) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.valueRange = read();
|
|
68
|
+
this.valueRange = context.read();
|
|
73
69
|
|
|
74
|
-
super.deserialize(context);
|
|
70
|
+
super.deserialize(context.rest);
|
|
75
71
|
}
|
|
76
72
|
}
|
|
77
73
|
|
|
@@ -7,11 +7,13 @@
|
|
|
7
7
|
|
|
8
8
|
const Dependency = require("../Dependency");
|
|
9
9
|
const makeSerializable = require("../util/makeSerializable");
|
|
10
|
+
const memoize = require("../util/memoize");
|
|
10
11
|
const { ImportPhaseUtils } = require("./ImportPhase");
|
|
11
12
|
const ModuleDependency = require("./ModuleDependency");
|
|
12
13
|
|
|
13
14
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
|
14
15
|
/** @typedef {import("../AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
|
16
|
+
/** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */
|
|
15
17
|
/** @typedef {import("../Dependency").RawReferencedExports} RawReferencedExports */
|
|
16
18
|
/** @typedef {import("../Dependency").ReferencedExports} ReferencedExports */
|
|
17
19
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
|
@@ -23,8 +25,11 @@ const ModuleDependency = require("./ModuleDependency");
|
|
|
23
25
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
24
26
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
25
27
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
28
|
+
/** @typedef {import("./HarmonyImportGuard").DependencyGuard} DependencyGuard */
|
|
26
29
|
/** @typedef {import("./ImportPhase").ImportPhaseType} ImportPhaseType */
|
|
27
30
|
|
|
31
|
+
const getHarmonyImportGuard = memoize(() => require("./HarmonyImportGuard"));
|
|
32
|
+
|
|
28
33
|
class ImportDependency extends ModuleDependency {
|
|
29
34
|
/**
|
|
30
35
|
* Creates an instance of ImportDependency.
|
|
@@ -37,9 +42,14 @@ class ImportDependency extends ModuleDependency {
|
|
|
37
42
|
constructor(request, range, referencedExports, phase, attributes) {
|
|
38
43
|
super(request);
|
|
39
44
|
this.range = range;
|
|
45
|
+
/** @type {RawReferencedExports | null} */
|
|
40
46
|
this.referencedExports = referencedExports;
|
|
47
|
+
/** @type {ImportPhaseType} */
|
|
41
48
|
this.phase = phase;
|
|
49
|
+
/** @type {ImportAttributes | undefined} */
|
|
42
50
|
this.attributes = attributes;
|
|
51
|
+
/** @type {DependencyGuard[] | undefined} */
|
|
52
|
+
this.branchGuards = undefined;
|
|
43
53
|
}
|
|
44
54
|
|
|
45
55
|
get type() {
|
|
@@ -50,6 +60,18 @@ class ImportDependency extends ModuleDependency {
|
|
|
50
60
|
return "esm";
|
|
51
61
|
}
|
|
52
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Returns function to determine if the connection is active.
|
|
65
|
+
* @param {ModuleGraph} moduleGraph module graph
|
|
66
|
+
* @returns {null | false | GetConditionFn} function to determine if the connection is active
|
|
67
|
+
*/
|
|
68
|
+
getCondition(moduleGraph) {
|
|
69
|
+
const guards = this.branchGuards;
|
|
70
|
+
if (guards === undefined) return null;
|
|
71
|
+
return (connection, runtime) =>
|
|
72
|
+
!getHarmonyImportGuard().isDeadByGuards(guards, moduleGraph, runtime);
|
|
73
|
+
}
|
|
74
|
+
|
|
53
75
|
/**
|
|
54
76
|
* Returns an identifier to merge equal requests.
|
|
55
77
|
* @returns {string | null} an identifier to merge equal requests
|
|
@@ -98,7 +120,8 @@ class ImportDependency extends ModuleDependency {
|
|
|
98
120
|
}
|
|
99
121
|
refs.push({
|
|
100
122
|
name: referencedExport,
|
|
101
|
-
canMangle: false
|
|
123
|
+
canMangle: false,
|
|
124
|
+
canInline: false
|
|
102
125
|
});
|
|
103
126
|
}
|
|
104
127
|
return refs;
|
|
@@ -113,6 +136,7 @@ class ImportDependency extends ModuleDependency {
|
|
|
113
136
|
context.write(this.referencedExports);
|
|
114
137
|
context.write(this.phase);
|
|
115
138
|
context.write(this.attributes);
|
|
139
|
+
context.write(this.branchGuards);
|
|
116
140
|
super.serialize(context);
|
|
117
141
|
}
|
|
118
142
|
|
|
@@ -125,6 +149,7 @@ class ImportDependency extends ModuleDependency {
|
|
|
125
149
|
this.referencedExports = context.read();
|
|
126
150
|
this.phase = context.read();
|
|
127
151
|
this.attributes = context.read();
|
|
152
|
+
this.branchGuards = context.read();
|
|
128
153
|
super.deserialize(context);
|
|
129
154
|
}
|
|
130
155
|
}
|
|
@@ -144,9 +169,26 @@ ImportDependency.Template = class ImportDependencyTemplate extends (
|
|
|
144
169
|
apply(
|
|
145
170
|
dependency,
|
|
146
171
|
source,
|
|
147
|
-
{
|
|
172
|
+
{
|
|
173
|
+
runtimeTemplate,
|
|
174
|
+
module,
|
|
175
|
+
moduleGraph,
|
|
176
|
+
chunkGraph,
|
|
177
|
+
runtimeRequirements,
|
|
178
|
+
runtime
|
|
179
|
+
}
|
|
148
180
|
) {
|
|
149
181
|
const dep = /** @type {ImportDependency} */ (dependency);
|
|
182
|
+
const connection = moduleGraph.getConnection(dep);
|
|
183
|
+
// Dead branch: module is excluded and has no id; code is never executed.
|
|
184
|
+
if (connection && !connection.isTargetActive(runtime)) {
|
|
185
|
+
source.replace(
|
|
186
|
+
dep.range[0],
|
|
187
|
+
dep.range[1] - 1,
|
|
188
|
+
"Promise.resolve(/* dead branch */)"
|
|
189
|
+
);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
150
192
|
const block = /** @type {AsyncDependenciesBlock} */ (
|
|
151
193
|
moduleGraph.getParentBlock(dep)
|
|
152
194
|
);
|