@depup/webpack 5.111.1-depup.1 → 5.112.0-depup.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/README.md +4 -7
- package/changes.json +3 -15
- package/lib/Chunk.js +3 -966
- package/lib/Compilation.js +224 -106
- package/lib/Compiler.js +19 -19
- package/lib/Dependency.js +3 -551
- package/lib/DependencyTemplate.js +3 -70
- package/lib/EntryPlugin.js +3 -68
- package/lib/Entrypoint.js +3 -121
- package/lib/ExternalsPlugin.js +3 -92
- package/lib/FileSystemInfo.js +3 -4629
- package/lib/InitFragment.js +3 -204
- package/lib/LibraryTemplatePlugin.js +3 -46
- package/lib/ModuleFilenameHelpers.js +3 -400
- package/lib/ModuleNotFoundError.js +2 -2
- package/lib/MultiCompiler.js +37 -8
- package/lib/NormalModule.js +3 -2242
- package/lib/NullFactory.js +3 -22
- package/lib/ProgressPlugin.js +3 -908
- package/lib/RawModule.js +3 -197
- package/lib/RequestShortener.js +3 -37
- package/lib/SingleEntryPlugin.js +1 -1
- package/lib/WebpackError.js +2 -2
- package/lib/asset/AssetBytesGenerator.js +8 -8
- package/lib/asset/AssetBytesParser.js +3 -3
- package/lib/asset/AssetGenerator.js +36 -22
- package/lib/asset/AssetModule.js +2 -2
- package/lib/asset/AssetModulesPlugin.js +6 -9
- package/lib/asset/AssetParser.js +3 -3
- package/lib/asset/AssetSourceGenerator.js +8 -8
- package/lib/asset/AssetSourceParser.js +3 -3
- package/lib/asset/RawDataUrlModule.js +17 -10
- package/lib/asset/WebManifestGenerator.js +7 -7
- package/lib/asset/WebManifestParser.js +5 -5
- package/lib/async-modules/AsyncModuleHelpers.js +6 -5
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
- package/lib/async-modules/InferAsyncModulesPlugin.js +4 -3
- package/lib/async-modules/isGeneratorLowered.js +3 -3
- package/lib/bun/BunTargetPlugin.js +1 -1
- package/lib/cache/AddBuildDependenciesPlugin.js +2 -19
- package/lib/{Cache.js → cache/Cache.js} +1 -1
- package/lib/{CacheFacade.js → cache/CacheFacade.js} +5 -5
- package/lib/cache/IdleFileCachePlugin.js +2 -2
- package/lib/cache/MemoryCachePlugin.js +2 -2
- package/lib/cache/MemoryWithGcCachePlugin.js +2 -2
- package/lib/cache/PackFileCacheStrategy.js +8 -10
- package/lib/cache/ResolverCachePlugin.js +8 -4
- package/lib/cache/mergeEtags.js +1 -1
- package/lib/{OptionsApply.js → config/OptionsApply.js} +3 -3
- package/lib/{PlatformPlugin.js → config/PlatformPlugin.js} +2 -2
- package/lib/{WebpackOptionsApply.js → config/WebpackOptionsApply.js} +217 -200
- package/lib/{WebpackOptionsDefaulter.js → config/WebpackOptionsDefaulter.js} +3 -3
- package/lib/config/browserslistTargetHandler.js +1 -1
- package/lib/{cli.js → config/cli.js} +5 -158
- package/lib/config/defaults.js +144 -48
- package/lib/config/getClaimedAssetTypes.js +21 -13
- package/lib/config/normalization.js +18 -7
- package/lib/config/target.js +10 -0
- package/lib/container/ContainerEntryDependency.js +1 -1
- package/lib/container/ContainerEntryModule.js +13 -11
- package/lib/container/ContainerEntryModuleFactory.js +2 -2
- package/lib/container/ContainerExposedDependency.js +1 -1
- package/lib/container/ContainerPlugin.js +178 -5
- package/lib/container/ContainerReferencePlugin.js +75 -14
- package/lib/container/FallbackDependency.js +1 -1
- package/lib/container/FallbackItemDependency.js +1 -1
- package/lib/container/FallbackModule.js +12 -10
- package/lib/container/FallbackModuleFactory.js +2 -2
- package/lib/container/HoistContainerReferencesPlugin.js +10 -11
- package/lib/container/ModuleFederationPlugin.js +306 -7
- package/lib/container/RemoteModule.js +14 -10
- package/lib/container/RemoteRuntimeModule.js +5 -5
- package/lib/container/RemoteToExternalDependency.js +1 -1
- package/lib/container/moduleFederationHooks.js +1 -1
- package/lib/context/ContextModule.js +36 -25
- package/lib/context/ContextModuleFactory.js +13 -10
- package/lib/context/ContextReplacementPlugin.js +3 -3
- package/lib/css/CssGenerator.js +38 -31
- package/lib/css/CssInjectStyleRuntimeModule.js +36 -30
- package/lib/css/CssLoadingRuntimeModule.js +77 -44
- package/lib/css/CssModule.js +27 -29
- package/lib/css/CssModulesPlugin.js +128 -44
- package/lib/css/CssParser.js +682 -291
- package/lib/css/CssServerStylesRuntimeModule.js +3 -3
- package/lib/css/cssMinify.js +110 -37
- package/lib/css/data.js +6985 -5125
- package/lib/css/syntax-parser.js +19873 -0
- package/lib/css/syntax-printer.js +6037 -0
- package/lib/css/syntax.js +37 -18686
- package/lib/debug/ProfilingPlugin.js +52 -19
- package/lib/{DefinePlugin.js → define/DefinePlugin.js} +407 -41
- package/lib/{DotenvPlugin.js → define/DotenvPlugin.js} +9 -9
- package/lib/{EnvironmentPlugin.js → define/EnvironmentPlugin.js} +2 -2
- package/lib/deno/DenoTargetPlugin.js +1 -1
- package/lib/dependencies/ConstDependency.js +3 -120
- package/lib/dependencies/ContextElementDependency.js +5 -172
- package/lib/dependencies/NullDependency.js +3 -37
- package/lib/dependencies/{AMDDefineDependency.js → amd/AMDDefineDependency.js} +12 -11
- package/lib/dependencies/{AMDDefineDependencyParserPlugin.js → amd/AMDDefineDependencyParserPlugin.js} +10 -10
- package/lib/dependencies/{AMDPlugin.js → amd/AMDPlugin.js} +11 -11
- package/lib/dependencies/{AMDRequireArrayDependency.js → amd/AMDRequireArrayDependency.js} +15 -13
- package/lib/dependencies/{AMDRequireContextDependency.js → amd/AMDRequireContextDependency.js} +11 -10
- package/lib/dependencies/{AMDRequireDependenciesBlock.js → amd/AMDRequireDependenciesBlock.js} +7 -6
- package/lib/dependencies/{AMDRequireDependenciesBlockParserPlugin.js → amd/AMDRequireDependenciesBlockParserPlugin.js} +10 -10
- package/lib/dependencies/{AMDRequireDependency.js → amd/AMDRequireDependency.js} +13 -12
- package/lib/dependencies/{AMDRequireItemDependency.js → amd/AMDRequireItemDependency.js} +8 -7
- package/lib/dependencies/{AMDRuntimeModules.js → amd/AMDRuntimeModules.js} +3 -3
- package/lib/dependencies/{LocalModule.js → amd/LocalModule.js} +8 -4
- package/lib/dependencies/{LocalModuleDependency.js → amd/LocalModuleDependency.js} +17 -10
- package/lib/dependencies/{LocalModulesHelpers.js → amd/LocalModulesHelpers.js} +1 -1
- package/lib/dependencies/{RequireJsStuffPlugin.js → amd/RequireJsStuffPlugin.js} +9 -9
- package/lib/dependencies/{UnsupportedDependency.js → amd/UnsupportedDependency.js} +11 -10
- package/lib/dependencies/{CommonJsDependencyHelpers.js → commonjs/CommonJsDependencyHelpers.js} +8 -9
- package/lib/dependencies/{CommonJsExportRequireDependency.js → commonjs/CommonJsExportRequireDependency.js} +166 -33
- package/lib/dependencies/{CommonJsExportsDependency.js → commonjs/CommonJsExportsDependency.js} +15 -14
- package/lib/dependencies/{CommonJsExportsParserPlugin.js → commonjs/CommonJsExportsParserPlugin.js} +138 -61
- package/lib/dependencies/{CommonJsFullRequireDependency.js → commonjs/CommonJsFullRequireDependency.js} +32 -24
- package/lib/dependencies/{CommonJsImportsParserPlugin.js → commonjs/CommonJsImportsParserPlugin.js} +35 -30
- package/lib/dependencies/{CommonJsObjectExportDependency.js → commonjs/CommonJsObjectExportDependency.js} +13 -12
- package/lib/dependencies/{CommonJsPlugin.js → commonjs/CommonJsPlugin.js} +47 -35
- package/lib/dependencies/{CommonJsRequireContextDependency.js → commonjs/CommonJsRequireContextDependency.js} +15 -14
- package/lib/dependencies/{CommonJsRequireDependency.js → commonjs/CommonJsRequireDependency.js} +33 -25
- package/lib/dependencies/{CommonJsSelfReferenceDependency.js → commonjs/CommonJsSelfReferenceDependency.js} +17 -16
- package/lib/dependencies/{ModuleDecoratorDependency.js → commonjs/ModuleDecoratorDependency.js} +16 -15
- package/lib/dependencies/{RequireEnsureDependenciesBlock.js → commonjs/RequireEnsureDependenciesBlock.js} +8 -7
- package/lib/dependencies/{RequireEnsureDependenciesBlockParserPlugin.js → commonjs/RequireEnsureDependenciesBlockParserPlugin.js} +5 -5
- package/lib/dependencies/{RequireEnsureDependency.js → commonjs/RequireEnsureDependency.js} +13 -12
- package/lib/dependencies/{RequireEnsureItemDependency.js → commonjs/RequireEnsureItemDependency.js} +7 -6
- package/lib/dependencies/{RequireEnsurePlugin.js → commonjs/RequireEnsurePlugin.js} +8 -8
- package/lib/dependencies/{RequireHeaderDependency.js → commonjs/RequireHeaderDependency.js} +14 -13
- package/lib/dependencies/{RequireIncludeDependency.js → commonjs/RequireIncludeDependency.js} +13 -12
- package/lib/dependencies/{RequireIncludeDependencyParserPlugin.js → commonjs/RequireIncludeDependencyParserPlugin.js} +3 -27
- package/lib/dependencies/{RequireIncludePlugin.js → commonjs/RequireIncludePlugin.js} +4 -4
- package/lib/dependencies/{RequireResolveContextDependency.js → commonjs/RequireResolveContextDependency.js} +11 -10
- package/lib/dependencies/{RequireResolveDependency.js → commonjs/RequireResolveDependency.js} +12 -11
- package/lib/dependencies/{RequireResolveHeaderDependency.js → commonjs/RequireResolveHeaderDependency.js} +13 -12
- package/lib/dependencies/commonjs/TopLevelThisParserPlugin.js +59 -0
- package/lib/dependencies/{ContextDependency.js → context/ContextDependency.js} +15 -14
- package/lib/dependencies/{ContextDependencyHelpers.js → context/ContextDependencyHelpers.js} +31 -9
- package/lib/dependencies/{ContextDependencyTemplateAsId.js → context/ContextDependencyTemplateAsId.js} +3 -3
- package/lib/dependencies/{ContextDependencyTemplateAsRequireCall.js → context/ContextDependencyTemplateAsRequireCall.js} +3 -3
- package/lib/dependencies/context/ContextElementDependency.js +198 -0
- package/lib/dependencies/{ImportMetaContextDependency.js → context/ImportMetaContextDependency.js} +7 -6
- package/lib/dependencies/{ImportMetaContextDependencyParserPlugin.js → context/ImportMetaContextDependencyParserPlugin.js} +9 -9
- package/lib/dependencies/{ImportMetaContextPlugin.js → context/ImportMetaContextPlugin.js} +5 -5
- package/lib/dependencies/{ImportMetaGlobDependency.js → context/ImportMetaGlobDependency.js} +7 -6
- package/lib/dependencies/{ImportMetaGlobDependencyParserPlugin.js → context/ImportMetaGlobDependencyParserPlugin.js} +4 -4
- package/lib/dependencies/{ImportMetaGlobHelpers.js → context/ImportMetaGlobHelpers.js} +9 -9
- package/lib/dependencies/{RequireContextDependency.js → context/RequireContextDependency.js} +7 -6
- package/lib/dependencies/{RequireContextDependencyParserPlugin.js → context/RequireContextDependencyParserPlugin.js} +2 -2
- package/lib/dependencies/{RequireContextPlugin.js → context/RequireContextPlugin.js} +5 -5
- package/lib/dependencies/{CachedConstDependency.js → core/CachedConstDependency.js} +12 -11
- package/lib/dependencies/core/ConstDependency.js +131 -0
- package/lib/dependencies/{ImportPhase.js → core/ImportPhase.js} +5 -4
- package/lib/dependencies/{ModuleDependency.js → core/ModuleDependency.js} +10 -7
- package/lib/dependencies/{ModuleDependencyTemplateAsId.js → core/ModuleDependencyTemplateAsId.js} +3 -3
- package/lib/dependencies/{ModuleDependencyTemplateAsRequireId.js → core/ModuleDependencyTemplateAsRequireId.js} +2 -2
- package/lib/dependencies/{ModuleInitFragmentDependency.js → core/ModuleInitFragmentDependency.js} +10 -9
- package/lib/dependencies/core/NullDependency.js +44 -0
- package/lib/dependencies/{RuntimeRequirementsDependency.js → core/RuntimeRequirementsDependency.js} +10 -9
- package/lib/dependencies/{StaticExportsDependency.js → core/StaticExportsDependency.js} +15 -8
- package/lib/dependencies/{CssIcssExportDependency.js → css/CssIcssExportDependency.js} +369 -92
- package/lib/dependencies/{CssIcssImportDependency.js → css/CssIcssImportDependency.js} +23 -16
- package/lib/dependencies/{CssIcssSymbolDependency.js → css/CssIcssSymbolDependency.js} +13 -12
- package/lib/dependencies/{CssImportDependency.js → css/CssImportDependency.js} +15 -11
- package/lib/dependencies/{CssUrlDependency.js → css/CssUrlDependency.js} +23 -16
- package/lib/dependencies/{CreateRequireParserPlugin.js → esm/CreateRequireParserPlugin.js} +9 -9
- package/lib/dependencies/{HarmonyAcceptDependency.js → esm/ESMAcceptDependency.js} +41 -38
- package/lib/dependencies/esm/ESMAcceptImportDependency.js +39 -0
- package/lib/dependencies/{HarmonyCompatibilityDependency.js → esm/ESMCompatibilityDependency.js} +29 -21
- package/lib/dependencies/{HarmonyDetectionParserPlugin.js → esm/ESMDetectionParserPlugin.js} +19 -17
- package/lib/dependencies/{HarmonyEvaluatedImportSpecifierDependency.js → esm/ESMEvaluatedImportSpecifierDependency.js} +33 -30
- package/lib/dependencies/{HarmonyExportDependencyParserPlugin.js → esm/ESMExportDependencyParserPlugin.js} +60 -89
- package/lib/dependencies/{HarmonyExportExpressionDependency.js → esm/ESMExportExpressionDependency.js} +80 -45
- package/lib/dependencies/{HarmonyExportHeaderDependency.js → esm/ESMExportHeaderDependency.js} +17 -15
- package/lib/dependencies/esm/ESMExportImportedSideEffectDependency.js +37 -0
- package/lib/dependencies/{HarmonyExportImportedSpecifierDependency.js → esm/ESMExportImportedSpecifierDependency.js} +133 -118
- package/lib/dependencies/{HarmonyExportInitFragment.js → esm/ESMExportInitFragment.js} +48 -30
- package/lib/dependencies/{HarmonyExportSpecifierDependency.js → esm/ESMExportSpecifierDependency.js} +60 -36
- package/lib/dependencies/{HarmonyExports.js → esm/ESMExports.js} +4 -4
- package/lib/dependencies/{HarmonyImportBareSideEffectDependency.js → esm/ESMImportBareSideEffectDependency.js} +21 -13
- package/lib/dependencies/{HarmonyImportDependency.js → esm/ESMImportDependency.js} +74 -71
- package/lib/dependencies/{HarmonyImportDependencyParserPlugin.js → esm/ESMImportDependencyParserPlugin.js} +99 -84
- package/lib/dependencies/{HarmonyImportGuard.js → esm/ESMImportGuard.js} +26 -29
- package/lib/dependencies/{HarmonyImportSideEffectDependency.js → esm/ESMImportSideEffectDependency.js} +83 -39
- package/lib/dependencies/{HarmonyImportSpecifierDependency.js → esm/ESMImportSpecifierDependency.js} +94 -59
- package/lib/dependencies/esm/ESMModulesPlugin.js +207 -0
- package/lib/dependencies/{HarmonyTopLevelThisParserPlugin.js → esm/ESMTopLevelThisParserPlugin.js} +7 -7
- package/lib/dependencies/{TopLevelAwaitDependency.js → esm/TopLevelAwaitDependency.js} +12 -11
- package/lib/dependencies/{DynamicExports.js → helpers/DynamicExports.js} +2 -2
- package/lib/{util → dependencies/helpers}/chainedImports.js +5 -5
- package/lib/dependencies/{processExportInfo.js → helpers/processExportInfo.js} +4 -4
- package/lib/{util → dependencies/helpers}/traverseDestructuringAssignmentProperties.js +1 -1
- package/lib/dependencies/{ImportMetaHotAcceptDependency.js → hmr/ImportMetaHotAcceptDependency.js} +8 -7
- package/lib/dependencies/{ImportMetaHotDeclineDependency.js → hmr/ImportMetaHotDeclineDependency.js} +8 -7
- package/lib/dependencies/{ModuleHotAcceptDependency.js → hmr/ModuleHotAcceptDependency.js} +8 -7
- package/lib/dependencies/{ModuleHotDeclineDependency.js → hmr/ModuleHotDeclineDependency.js} +8 -7
- package/lib/dependencies/{HtmlEntryDependency.js → html/HtmlEntryDependency.js} +51 -141
- package/lib/dependencies/{HtmlInlineHtmlDependency.js → html/HtmlInlineHtmlDependency.js} +13 -12
- package/lib/dependencies/{HtmlInlineScriptDependency.js → html/HtmlInlineScriptDependency.js} +69 -19
- package/lib/dependencies/{HtmlInlineStyleDependency.js → html/HtmlInlineStyleDependency.js} +50 -15
- package/lib/dependencies/{HtmlSourceDependency.js → html/HtmlSourceDependency.js} +23 -16
- package/lib/dependencies/{ImportContextDependency.js → import/ImportContextDependency.js} +24 -10
- package/lib/dependencies/{ImportDependency.js → import/ImportDependency.js} +26 -18
- package/lib/dependencies/{ImportEagerDependency.js → import/ImportEagerDependency.js} +18 -10
- package/lib/dependencies/{ImportParserPlugin.js → import/ImportParserPlugin.js} +20 -20
- package/lib/dependencies/{ImportPlugin.js → import/ImportPlugin.js} +4 -4
- package/lib/dependencies/{ImportWeakDependency.js → import/ImportWeakDependency.js} +18 -10
- package/lib/dependencies/{importOptionsCheck.js → import/importOptionsCheck.js} +2 -2
- package/lib/dependencies/{BuildTimeConstDependency.js → import-meta/BuildTimeConstDependency.js} +12 -11
- package/lib/dependencies/{ImportMetaMainDependency.js → import-meta/ImportMetaMainDependency.js} +12 -11
- package/lib/dependencies/{ImportMetaPlugin.js → import-meta/ImportMetaPlugin.js} +119 -98
- package/lib/dependencies/{SystemPlugin.js → system/SystemPlugin.js} +11 -38
- package/lib/dependencies/{SystemRuntimeModule.js → system/SystemRuntimeModule.js} +3 -3
- package/lib/dependencies/{ImportMetaResolveDependency.js → url/ImportMetaResolveDependency.js} +9 -8
- package/lib/dependencies/{URLContextDependency.js → url/URLContextDependency.js} +11 -10
- package/lib/dependencies/{URLDependency.js → url/URLDependency.js} +28 -20
- package/lib/{url → dependencies/url}/URLParserPlugin.js +16 -18
- package/lib/dependencies/{URLPlugin.js → url/URLPlugin.js} +6 -7
- package/lib/dependencies/{WebAssemblyExportImportedDependency.js → wasm/WebAssemblyExportImportedDependency.js} +18 -11
- package/lib/dependencies/{WebAssemblyImportDependency.js → wasm/WebAssemblyImportDependency.js} +19 -12
- package/lib/dependencies/{CreateScriptUrlDependency.js → worker/CreateScriptUrlDependency.js} +12 -11
- package/lib/dependencies/{WorkerAndWorkletPlugin.js → worker/WorkerAndWorkletPlugin.js} +31 -33
- package/lib/dependencies/{WorkerDependency.js → worker/WorkerDependency.js} +22 -15
- package/lib/dependencies/{WorkletDependency.js → worker/WorkletDependency.js} +19 -18
- package/lib/{EvalDevToolModulePlugin.js → devtool/EvalDevToolModulePlugin.js} +20 -6
- package/lib/{EvalSourceMapDevToolPlugin.js → devtool/EvalSourceMapDevToolPlugin.js} +32 -24
- package/lib/devtool/ModuleFilenameHelpers.js +413 -0
- package/lib/{SourceMapDevToolModuleOptionsPlugin.js → devtool/SourceMapDevToolModuleOptionsPlugin.js} +10 -3
- package/lib/{SourceMapDevToolPlugin.js → devtool/SourceMapDevToolPlugin.js} +154 -26
- package/lib/{util → devtool}/generateDebugId.js +1 -1
- package/lib/{IgnoreWarningsPlugin.js → diagnostics/IgnoreWarningsPlugin.js} +2 -2
- package/lib/{NoEmitOnErrorsPlugin.js → diagnostics/NoEmitOnErrorsPlugin.js} +1 -1
- package/lib/diagnostics/WarnCaseSensitiveModulesPlugin.js +64 -0
- package/lib/{WarnDeprecatedOptionPlugin.js → diagnostics/WarnDeprecatedOptionPlugin.js} +2 -22
- package/lib/diagnostics/WarnNoModeSetPlugin.js +27 -0
- package/lib/dll/DelegatedModule.js +20 -18
- package/lib/dll/DelegatedModuleFactoryPlugin.js +2 -2
- package/lib/dll/DelegatedPlugin.js +1 -1
- package/lib/{dependencies → dll}/DelegatedSourceDependency.js +5 -4
- package/lib/{dependencies → dll}/DllEntryDependency.js +6 -5
- package/lib/dll/DllEntryPlugin.js +3 -3
- package/lib/dll/DllModule.js +11 -9
- package/lib/dll/DllModuleFactory.js +3 -3
- package/lib/dll/DllPlugin.js +18 -6
- package/lib/dll/DllReferencePlugin.js +102 -26
- package/lib/dll/LibManifestPlugin.js +9 -7
- package/lib/electron/ElectronTargetPlugin.js +2 -2
- package/lib/{DynamicEntryPlugin.js → entry/DynamicEntryPlugin.js} +3 -3
- package/lib/{dependencies → entry}/EntryDependency.js +11 -2
- package/lib/{EntryOptionPlugin.js → entry/EntryOptionPlugin.js} +6 -6
- package/lib/entry/EntryPlugin.js +75 -0
- package/lib/{performance → errors}/AssetsOverSizeLimitWarning.js +2 -2
- package/lib/errors/AsyncDependencyToInitialChunkError.js +2 -2
- package/lib/errors/BuildCycleError.js +1 -1
- package/lib/{WarnCaseSensitiveModulesPlugin.js → errors/CaseSensitiveModulesWarning.js} +4 -56
- package/lib/errors/ChunkRenderError.js +1 -1
- package/lib/errors/CodeGenerationError.js +1 -1
- package/lib/errors/CommentCompilationWarning.js +1 -1
- package/lib/errors/ConflictingEntryExportsWarning.js +38 -0
- package/lib/{dependencies → errors}/CriticalDependencyWarning.js +4 -3
- package/lib/errors/DeprecatedOptionWarning.js +30 -0
- package/lib/errors/DllManifestError.js +26 -0
- package/lib/{performance → errors}/DuplicatePackagesWarning.js +6 -6
- package/lib/{dependencies/HarmonyLinkingError.js → errors/ESMLinkingError.js} +4 -4
- package/lib/{performance → errors}/EntrypointsOverSizeLimitWarning.js +2 -2
- package/lib/errors/EnvironmentNotSupportAsyncWarning.js +2 -2
- package/lib/{ErrorHelpers.js → errors/ErrorHelpers.js} +7 -5
- package/lib/errors/ExternalStarReexportError.js +2 -2
- package/lib/{library → errors}/FalseIIFEUmdWarning.js +1 -1
- package/lib/errors/HookWebpackError.js +4 -4
- package/lib/errors/IgnoreErrorModuleFactory.js +3 -3
- package/lib/errors/InvalidDependenciesModuleWarning.js +1 -1
- package/lib/{optimize → errors}/MinMaxSizeWarning.js +1 -1
- package/lib/errors/ModuleBuildError.js +1 -1
- package/lib/errors/ModuleDependencyError.js +2 -2
- package/lib/errors/ModuleDependencyWarning.js +2 -2
- package/lib/errors/ModuleError.js +1 -1
- package/lib/errors/ModuleHashingError.js +1 -1
- package/lib/errors/ModuleNotFoundError.js +3 -3
- package/lib/errors/ModuleParseError.js +1 -1
- package/lib/errors/ModuleRestoreError.js +1 -1
- package/lib/errors/ModuleStoreError.js +1 -1
- package/lib/errors/ModuleWarning.js +1 -1
- package/lib/{performance → errors}/NoAsyncChunksWarning.js +1 -1
- package/lib/{WarnNoModeSetPlugin.js → errors/NoModeWarning.js} +2 -19
- package/lib/errors/NodeStuffInWebError.js +7 -2
- package/lib/errors/PathVariableError.js +31 -0
- package/lib/errors/RequireIncludeDeprecationWarning.js +40 -0
- package/lib/{performance → errors}/RuntimeInLargeChunkWarning.js +1 -1
- package/lib/errors/RuntimeModuleGenerationError.js +51 -0
- package/lib/errors/SSRManifestAutoPublicPathWarning.js +24 -0
- package/lib/errors/SystemImportDeprecationWarning.js +43 -0
- package/lib/errors/UnmergeableEntryExportsError.js +34 -0
- package/lib/errors/UnsupportedFeatureWarning.js +1 -1
- package/lib/{wasm-sync → errors}/UnsupportedWebAssemblyFeatureError.js +1 -1
- package/lib/{wasm-sync → errors}/WebAssemblyInInitialChunkError.js +7 -5
- package/lib/errors/WebpackError.js +12 -3
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -2
- package/lib/esm/ModuleChunkFormatPlugin.js +19 -19
- package/lib/esm/ModuleChunkLoadingPlugin.js +3 -3
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +8 -8
- package/lib/{ExternalModule.js → externals/ExternalModule.js} +79 -55
- package/lib/{ExternalModuleFactoryPlugin.js → externals/ExternalModuleFactoryPlugin.js} +41 -39
- package/lib/externals/ExternalsPlugin.js +99 -0
- package/lib/fs/FileSystemInfo.js +4642 -0
- package/lib/{util → fs}/fs.js +22 -9
- package/lib/{AsyncDependenciesBlock.js → graph/AsyncDependenciesBlock.js} +27 -4
- package/lib/graph/Chunk.js +985 -0
- package/lib/{ChunkGraph.js → graph/ChunkGraph.js} +187 -80
- package/lib/{ChunkGroup.js → graph/ChunkGroup.js} +11 -3
- package/lib/{DependenciesBlock.js → graph/DependenciesBlock.js} +16 -4
- package/lib/graph/Dependency.js +628 -0
- package/lib/graph/Entrypoint.js +136 -0
- package/lib/{ExportsInfo.js → graph/ExportsInfo.js} +130 -82
- package/lib/{HotUpdateChunk.js → graph/HotUpdateChunk.js} +8 -0
- package/lib/{ModuleGraph.js → graph/ModuleGraph.js} +30 -30
- package/lib/{ModuleGraphConnection.js → graph/ModuleGraphConnection.js} +2 -2
- package/lib/{buildChunkGraph.js → graph/buildChunkGraph.js} +152 -57
- package/lib/{util → graph}/findGraphRoots.js +14 -8
- package/lib/graph/isDependencyKind.js +23 -0
- package/lib/hmr/HotModuleReplacement.runtime.js +2 -2
- package/lib/{HotModuleReplacementPlugin.js → hmr/HotModuleReplacementPlugin.js} +47 -47
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +3 -3
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +10 -8
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +2 -2
- package/lib/hmr/LazyCompilationPlugin.js +31 -21
- package/lib/html/HtmlGenerator.js +107 -43
- package/lib/html/HtmlModule.js +6 -2
- package/lib/html/HtmlModulesPlugin.js +172 -76
- package/lib/html/HtmlParser.js +503 -153
- package/lib/html/builtinEmbeddedRenderer.js +60 -13
- package/lib/html/data.js +2 -1
- package/lib/html/htmlMinify.js +111 -41
- package/lib/html/syntax-parser.js +15796 -0
- package/lib/html/syntax-printer.js +1034 -0
- package/lib/html/syntax.js +37 -13952
- package/lib/html/xmlMinify.js +67 -0
- package/lib/ids/ChunkModuleIdRangePlugin.js +2 -2
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +31 -4
- package/lib/ids/IdHelpers.js +4 -4
- package/lib/ids/NaturalChunkIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -5
- package/lib/ids/OccurrenceModuleIdsPlugin.js +6 -5
- package/lib/{RecordIdsPlugin.js → ids/RecordIdsPlugin.js} +5 -5
- package/lib/ids/SyncModuleIdsPlugin.js +3 -3
- package/lib/{util → ids}/numberHash.js +1 -1
- package/lib/index.js +303 -97
- package/lib/{APIPlugin.js → javascript/APIPlugin.js} +25 -25
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -5
- package/lib/javascript/BasicEvaluatedExpression.js +4 -4
- package/lib/javascript/ChunkHelpers.js +64 -4
- package/lib/javascript/CommonJsChunkFormatPlugin.js +4 -7
- package/lib/{CompatibilityPlugin.js → javascript/CompatibilityPlugin.js} +7 -7
- package/lib/{ConstPlugin.js → javascript/ConstPlugin.js} +74 -7
- package/lib/{ExportsInfoApiPlugin.js → javascript/ExportsInfoApiPlugin.js} +5 -5
- package/lib/{dependencies → javascript}/ExportsInfoDependency.js +10 -9
- package/lib/javascript/JavascriptGenerator.js +17 -17
- package/lib/{JavascriptMetaInfoPlugin.js → javascript/JavascriptMetaInfoPlugin.js} +7 -7
- package/lib/javascript/JavascriptModule.js +4 -3
- package/lib/javascript/JavascriptModulesPlugin.js +440 -211
- package/lib/javascript/JavascriptParser.js +220 -134
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/MergedEntryExports.js +196 -0
- package/lib/javascript/ScopeAnalyzer.js +3840 -5
- package/lib/javascript/StartupHelpers.js +6 -6
- package/lib/{UseStrictPlugin.js → javascript/UseStrictPlugin.js} +12 -15
- package/lib/{dependencies → javascript}/WebpackIsIncludedDependency.js +10 -9
- package/lib/{WebpackIsIncludedPlugin.js → javascript/WebpackIsIncludedPlugin.js} +8 -8
- package/lib/javascript/data.js +533 -122
- package/lib/javascript/jsMinify.js +272 -0
- package/lib/javascript/regexp.js +67 -32
- package/lib/javascript/syntax-parser.js +18561 -0
- package/lib/javascript/syntax-printer-data.js +933 -0
- package/lib/javascript/syntax-printer.js +47106 -0
- package/lib/javascript/syntax.js +20 -11274
- package/lib/json/JsonData.js +1 -1
- package/lib/{dependencies → json}/JsonExportsDependency.js +8 -7
- package/lib/json/JsonGenerator.js +10 -10
- package/lib/json/JsonModule.js +2 -2
- package/lib/json/JsonModulesPlugin.js +1 -1
- package/lib/json/JsonParser.js +5 -5
- package/lib/json/jsonMinify.js +69 -0
- package/lib/library/AbstractLibraryPlugin.js +28 -15
- package/lib/library/AmdLibraryPlugin.js +4 -4
- package/lib/library/AssignLibraryPlugin.js +27 -11
- package/lib/library/EnableLibraryPlugin.js +1 -1
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -4
- package/lib/library/JsonpLibraryPlugin.js +1 -1
- package/lib/library/LibraryTemplatePlugin.js +53 -0
- package/lib/library/ModuleLibraryPlugin.js +160 -166
- package/lib/library/SystemLibraryPlugin.js +6 -8
- package/lib/library/UmdLibraryPlugin.js +3 -4
- package/lib/{dependencies → loaders}/LoaderDependency.js +3 -3
- package/lib/{dependencies → loaders}/LoaderImportDependency.js +9 -3
- package/lib/{LoaderOptionsPlugin.js → loaders/LoaderOptionsPlugin.js} +30 -12
- package/lib/{dependencies → loaders}/LoaderPlugin.js +2 -2
- package/lib/loaders/LoaderRunner.js +31 -21
- package/lib/{LoaderTargetPlugin.js → loaders/LoaderTargetPlugin.js} +2 -2
- package/lib/logging/Logger.js +7 -9
- package/lib/logging/ProgressPlugin.js +957 -0
- package/lib/{CodeGenerationResults.js → module/CodeGenerationResults.js} +7 -7
- package/lib/{Generator.js → module/Generator.js} +16 -14
- package/lib/{Module.js → module/Module.js} +119 -51
- package/lib/{ModuleFactory.js → module/ModuleFactory.js} +3 -3
- package/lib/module/NormalModule.js +2348 -0
- package/lib/{NormalModuleFactory.js → module/NormalModuleFactory.js} +53 -54
- package/lib/module/NullFactory.js +29 -0
- package/lib/{Parser.js → module/Parser.js} +3 -3
- package/lib/module/RawModule.js +208 -0
- package/lib/{SelfModuleFactory.js → module/SelfModuleFactory.js} +1 -1
- package/lib/{util → module}/extractSourceMap.js +2 -2
- package/lib/{util → module}/findCaseMismatch.js +2 -2
- package/lib/node/CommonJsChunkLoadingPlugin.js +3 -3
- package/lib/{dependencies → node}/ExternalModuleDependency.js +8 -7
- package/lib/{dependencies → node}/ExternalModuleInitFragment.js +6 -5
- package/lib/{dependencies → node}/ExternalModuleInitFragmentDependency.js +14 -9
- package/lib/node/NodeEnvironmentPlugin.js +11 -1
- package/lib/{NodeStuffPlugin.js → node/NodeStuffPlugin.js} +17 -17
- package/lib/node/NodeTargetPlugin.js +1 -1
- package/lib/node/NodeWatchFileSystem.js +58 -6
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +7 -7
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +9 -7
- package/lib/node/ReadFileCompileWasmPlugin.js +7 -5
- package/lib/node/RequireChunkLoadingRuntimeModule.js +7 -7
- package/lib/node/nodeConsole.js +2 -4
- package/lib/optimize/AggressiveMergingPlugin.js +2 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +12 -8
- package/lib/{CircularModulesPlugin.js → optimize/CircularModulesPlugin.js} +13 -13
- package/lib/optimize/ConcatenatedModule.js +229 -214
- package/lib/{ConcatenationScope.js → optimize/ConcatenationScope.js} +39 -6
- package/lib/optimize/ConstExportsPlugin.js +7 -7
- package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -3
- package/lib/{FlagAllModulesAsUsedPlugin.js → optimize/FlagAllModulesAsUsedPlugin.js} +3 -3
- package/lib/{FlagDependencyExportsPlugin.js → optimize/FlagDependencyExportsPlugin.js} +17 -17
- package/lib/{FlagDependencyUsagePlugin.js → optimize/FlagDependencyUsagePlugin.js} +17 -17
- package/lib/{FlagEntryExportAsUsedPlugin.js → optimize/FlagEntryExportAsUsedPlugin.js} +2 -2
- package/lib/optimize/FlagIncludedChunksPlugin.js +2 -2
- package/lib/optimize/InlineExports.js +11 -3
- package/lib/optimize/InnerGraph.js +5 -13
- package/lib/optimize/InnerGraphPlugin.js +10 -10
- package/lib/optimize/LazyBarrels.js +584 -0
- package/lib/{util → optimize}/LazyBucketSortedSet.js +2 -2
- package/lib/optimize/LimitChunkCountPlugin.js +16 -7
- package/lib/optimize/MangleExportsPlugin.js +5 -5
- package/lib/optimize/MergeDuplicateChunksPlugin.js +7 -6
- package/lib/optimize/MinChunkSizePlugin.js +9 -6
- package/lib/optimize/ModuleConcatenationPlugin.js +20 -12
- package/lib/{dependencies → optimize}/PureExpressionDependency.js +11 -10
- package/lib/optimize/RealContentHashPlugin.js +16 -7
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +4 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +18 -18
- package/lib/optimize/SplitChunksPlugin.js +713 -155
- package/lib/{util → optimize}/TupleQueue.js +9 -9
- package/lib/optimize/chunkSetIntersections.js +437 -0
- package/lib/{util → optimize}/deterministicGrouping.js +17 -17
- package/lib/{BannerPlugin.js → output/BannerPlugin.js} +82 -14
- package/lib/{CleanPlugin.js → output/CleanPlugin.js} +66 -24
- package/lib/{CopyPlugin.js → output/CopyPlugin.js} +142 -67
- package/lib/{ManifestPlugin.js → output/ManifestPlugin.js} +91 -17
- package/lib/output/SSRManifestPlugin.js +349 -0
- package/lib/performance/AnalyzableBailoutsPlugin.js +1 -1
- package/lib/performance/AsyncChunkWaterfallsPlugin.js +1 -1
- package/lib/performance/BroadContextsPlugin.js +4 -4
- package/lib/performance/CacheEffectivenessPlugin.js +2 -3
- package/lib/performance/ConflictingResourceHintsPlugin.js +1 -1
- package/lib/performance/DuplicateModulesPlugin.js +3 -4
- package/lib/performance/DuplicatePackagesPlugin.js +3 -3
- package/lib/performance/DynamicExportsPlugin.js +2 -2
- package/lib/performance/EvalUsagePlugin.js +3 -3
- package/lib/performance/HotspotsPlugin.js +11 -10
- package/lib/performance/LargeModulesPlugin.js +2 -3
- package/lib/performance/LegacyJavascriptPlugin.js +1 -2
- package/lib/performance/MissingSideEffectsPlugin.js +2 -3
- package/lib/performance/MissingSourceMapsPlugin.js +5 -6
- package/lib/performance/PureAnnotationsPlugin.js +3 -3
- package/lib/performance/RedundantDynamicImportsPlugin.js +6 -8
- package/lib/performance/ScopeHoistingBailoutsPlugin.js +2 -2
- package/lib/performance/SizeLimitsPlugin.js +11 -12
- package/lib/performance/TopLevelThisPlugin.js +8 -7
- package/lib/performance/UnsplitVendorsPlugin.js +1 -2
- package/lib/performance/UnusedAliasesPlugin.js +6 -7
- package/lib/performance/UnusedAssetsPlugin.js +5 -5
- package/lib/performance/UnusedDefinesPlugin.js +2 -2
- package/lib/performance/UnusedExternalsPlugin.js +3 -4
- package/lib/performance/UnusedFederationPlugin.js +2 -4
- package/lib/performance/UnusedModulesPlugin.js +5 -4
- package/lib/performance/getModuleSize.js +1 -1
- package/lib/performance/hasOnlyUnusedExports.js +4 -4
- package/lib/performance/isOnlyReexported.js +7 -6
- package/lib/{AutomaticPrefetchPlugin.js → prefetch/AutomaticPrefetchPlugin.js} +4 -5
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +2 -2
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +1 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +4 -4
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -4
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -4
- package/lib/{dependencies → prefetch}/PrefetchDependency.js +1 -1
- package/lib/{PrefetchPlugin.js → prefetch/PrefetchPlugin.js} +2 -2
- package/lib/prefetch/ResourceHintPlugin.js +65 -44
- package/lib/prefetch/ResourceHintRuntimeModule.js +3 -3
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +3 -3
- package/lib/prefetch/parseResourceHintOptions.js +4 -3
- package/lib/{ProvidePlugin.js → provide/ProvidePlugin.js} +7 -7
- package/lib/{dependencies → provide}/ProvidedDependency.js +14 -13
- package/lib/{IgnorePlugin.js → resolve/IgnorePlugin.js} +30 -13
- package/lib/{NormalModuleReplacementPlugin.js → resolve/NormalModuleReplacementPlugin.js} +4 -4
- package/lib/{ResolverFactory.js → resolve/ResolverFactory.js} +18 -5
- package/lib/resolve/getResolveOptionsKey.js +59 -0
- package/lib/rules/RuleSetCompiler.js +27 -46
- package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +2 -2
- package/lib/runtime/AsyncModuleRuntimeModule.js +7 -4
- package/lib/runtime/AutoPublicPathRuntimeModule.js +5 -5
- package/lib/runtime/BaseUriRuntimeModule.js +3 -3
- package/lib/runtime/ChunkNameRuntimeModule.js +2 -2
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +2 -2
- package/lib/runtime/CompatRuntimeModule.js +4 -4
- package/lib/runtime/ConcatenationWrapRuntimeModule.js +2 -2
- package/lib/runtime/ConstructRequireRuntimeModule.js +2 -2
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +2 -2
- package/lib/runtime/CreateScriptRuntimeModule.js +2 -2
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +2 -2
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +6 -6
- package/lib/runtime/EnsureChunkRuntimeModule.js +4 -4
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -6
- package/lib/runtime/GetFullHashRuntimeModule.js +2 -2
- package/lib/runtime/GetMainFilenameRuntimeModule.js +4 -4
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +3 -3
- package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +3 -3
- package/lib/runtime/GlobalRuntimeModule.js +3 -3
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +3 -3
- package/lib/runtime/HelperRuntimeModule.js +16 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +3 -3
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +80 -17
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +2 -2
- package/lib/runtime/NonceRuntimeModule.js +2 -2
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
- package/lib/runtime/PublicPathRuntimeModule.js +2 -2
- package/lib/runtime/RelativeUrlRuntimeModule.js +2 -2
- package/lib/{RuntimeGlobals.js → runtime/RuntimeGlobals.js} +18 -1
- package/lib/runtime/RuntimeIdRuntimeModule.js +4 -4
- package/lib/{RuntimeModule.js → runtime/RuntimeModule.js} +36 -21
- package/lib/{RuntimePlugin.js → runtime/RuntimePlugin.js} +48 -50
- package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +2 -2
- package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +2 -2
- package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +5 -5
- package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -3
- package/lib/runtime/SystemContextRuntimeModule.js +2 -2
- package/lib/runtime/ToBinaryRuntimeModule.js +3 -3
- package/lib/runtime/WorkerRuntimeModule.js +1 -1
- package/lib/runtime/baseUri.js +1 -1
- package/lib/schemes/DataUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +67 -11
- package/lib/schemes/VirtualUrlPlugin.js +50 -16
- package/lib/serialization/AggregateErrorSerializer.js +2 -2
- package/lib/serialization/FileMiddleware.js +3 -3
- package/lib/serialization/ObjectMiddleware.js +47 -16
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/serialization/SingleItemMiddleware.js +4 -2
- package/lib/sharing/ConsumeSharedFallbackDependency.js +9 -1
- package/lib/sharing/ConsumeSharedModule.js +18 -14
- package/lib/sharing/ConsumeSharedPlugin.js +148 -42
- package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -8
- package/lib/sharing/ProvideForSharedDependency.js +9 -1
- package/lib/sharing/ProvideSharedDependency.js +1 -1
- package/lib/sharing/ProvideSharedModule.js +11 -9
- package/lib/sharing/ProvideSharedModuleFactory.js +2 -2
- package/lib/sharing/ProvideSharedPlugin.js +111 -20
- package/lib/sharing/SharePlugin.js +102 -9
- package/lib/sharing/ShareRuntimeModule.js +6 -6
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/{util → sharing}/semver.js +14 -16
- package/lib/sharing/utils.js +59 -2
- package/lib/stats/DefaultStatsFactoryPlugin.js +22 -19
- package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +3 -3
- package/lib/{MultiStats.js → stats/MultiStats.js} +4 -4
- package/lib/{Stats.js → stats/Stats.js} +4 -4
- package/lib/stats/StatsFactory.js +14 -13
- package/lib/{ChunkTemplate.js → template/ChunkTemplate.js} +7 -7
- package/lib/{ConditionalInitFragment.js → template/ConditionalInitFragment.js} +3 -3
- package/lib/template/DependencyTemplate.js +77 -0
- package/lib/{DependencyTemplates.js → template/DependencyTemplates.js} +9 -4
- package/lib/template/InitFragment.js +223 -0
- package/lib/{MainTemplate.js → template/MainTemplate.js} +11 -11
- package/lib/{ModuleInfoHeaderPlugin.js → template/ModuleInfoHeaderPlugin.js} +30 -8
- package/lib/{ModuleTemplate.js → template/ModuleTemplate.js} +6 -6
- package/lib/{RuntimeTemplate.js → template/RuntimeTemplate.js} +145 -63
- package/lib/{Template.js → template/Template.js} +13 -11
- package/lib/{TemplatedPathPlugin.js → template/TemplatedPathPlugin.js} +19 -23
- package/lib/typescript/TypeScriptPlugin.js +3 -3
- package/lib/util/RequestShortener.js +44 -0
- package/lib/util/SortableSet.js +87 -22
- package/lib/util/SourceProcessor.js +349 -44
- package/lib/util/TupleSet.js +27 -27
- package/lib/util/WeakTupleMap.js +10 -12
- package/lib/util/buildDiagnostics.js +2 -2
- package/lib/util/comparators.js +10 -10
- package/lib/util/concatenate.js +28 -147
- package/lib/util/createMappings.js +111 -0
- package/lib/util/dataURL.js +94 -15
- package/lib/util/deprecation.js +1 -1
- package/lib/util/extractComments.js +118 -0
- package/lib/util/formatLocation.js +1 -1
- package/lib/util/globUtils.js +197 -16
- package/lib/util/haltVisitors.js +51 -0
- package/lib/util/handlerKeys.js +2 -2
- package/lib/util/identifier.js +117 -1
- package/lib/util/implicitTypeLoaderFallback.js +6 -4
- package/lib/util/internalSerializables.js +294 -102
- package/lib/util/magicComment.js +12 -7
- package/lib/util/makeSerializable.js +23 -4
- package/lib/util/parseJson.js +1 -1
- package/lib/util/preloadModuleType.js +5 -2
- package/lib/util/registerExternalSerializer.js +2 -2
- package/lib/util/removeBOM.js +1 -1
- package/lib/util/runtime.js +1 -1
- package/lib/util/serialization.js +4 -1
- package/lib/util/source.js +2 -2
- package/lib/util/terminalColors.js +161 -0
- package/lib/{wasm-async → wasm}/AsyncWasmCompileRuntimeModule.js +5 -5
- package/lib/{wasm-async → wasm}/AsyncWasmLoadingRuntimeModule.js +5 -5
- package/lib/{wasm-async → wasm}/AsyncWasmModule.js +9 -5
- package/lib/{wasm-async → wasm}/AsyncWebAssemblyGenerator.js +5 -5
- package/lib/{wasm-async → wasm}/AsyncWebAssemblyJavascriptGenerator.js +11 -10
- package/lib/{wasm-async → wasm}/AsyncWebAssemblyModulesPlugin.js +26 -10
- package/lib/{wasm-async → wasm}/AsyncWebAssemblyParser.js +8 -8
- package/lib/wasm/EnableWasmLoadingPlugin.js +1 -1
- package/lib/{wasm-async → wasm}/UniversalCompileAsyncWasmPlugin.js +9 -7
- package/lib/wasm/wasmModuleFilename.js +2 -2
- package/lib/wasm-sync/SyncWasmModule.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +8 -8
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -3
- package/lib/wasm-sync/WebAssemblyGenerator.js +9 -8
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +14 -15
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +9 -7
- package/lib/wasm-sync/WebAssemblyParser.js +6 -6
- package/lib/wasm-sync/WebAssemblyUtils.js +6 -5
- package/lib/{MultiWatching.js → watch/MultiWatching.js} +3 -3
- package/lib/{WatchIgnorePlugin.js → watch/WatchIgnorePlugin.js} +43 -9
- package/lib/{Watching.js → watch/Watching.js} +8 -8
- package/lib/web/FetchCompileAsyncWasmPlugin.js +8 -6
- package/lib/web/FetchCompileWasmPlugin.js +6 -4
- package/lib/web/JsonpChunkLoadingPlugin.js +3 -3
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
- package/lib/web/JsonpTemplatePlugin.js +1 -1
- package/lib/webpack.js +27 -17
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -3
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -6
- package/package.json +49 -38
- package/schemas/WebpackOptions.check.js +2 -1
- package/schemas/WebpackOptions.d.json.ts +2 -0
- package/schemas/WebpackOptions.json +294 -74
- package/schemas/plugins/BannerPlugin.check.js +2 -1
- package/schemas/plugins/BannerPlugin.json +29 -2
- package/schemas/plugins/HtmlGeneratorOptions.check.js +1 -0
- package/schemas/plugins/HtmlParserOptions.check.js +2 -1
- package/schemas/plugins/IgnorePlugin.check.js +1 -0
- package/schemas/plugins/IgnorePlugin.d.json.ts +2 -0
- package/schemas/plugins/IgnorePlugin.json +1 -1
- package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -0
- package/schemas/plugins/ManifestPlugin.check.js +1 -0
- package/schemas/plugins/ManifestPlugin.json +3 -3
- package/schemas/plugins/ProgressPlugin.check.js +2 -1
- package/schemas/plugins/ProgressPlugin.json +2 -7
- package/schemas/plugins/SSRManifestPlugin.check.js +7 -0
- package/schemas/plugins/SSRManifestPlugin.json +20 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +2 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +44 -12
- package/schemas/plugins/WatchIgnorePlugin.check.js +2 -1
- package/schemas/plugins/WatchIgnorePlugin.json +12 -3
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -0
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -0
- package/schemas/plugins/asset/AssetParserOptions.check.js +1 -0
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -0
- package/schemas/plugins/container/ContainerPlugin.check.js +2 -1
- package/schemas/plugins/container/ContainerPlugin.json +8 -0
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -0
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +2 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +40 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -0
- package/schemas/plugins/css/CssParserOptions.check.js +1 -0
- package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -0
- package/schemas/plugins/dll/DllPlugin.check.js +1 -0
- package/schemas/plugins/dll/DllReferencePlugin.check.js +2 -1
- package/schemas/plugins/dll/DllReferencePlugin.json +3 -18
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -0
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -0
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -0
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +1 -0
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -0
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -0
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -0
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -0
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +1 -0
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +2 -1
- package/schemas/plugins/sharing/ConsumeSharedPlugin.json +32 -0
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +2 -1
- package/schemas/plugins/sharing/ProvideSharedPlugin.json +32 -0
- package/schemas/plugins/sharing/SharePlugin.check.js +2 -1
- package/schemas/plugins/sharing/SharePlugin.json +32 -0
- package/types.d.ts +19355 -13873
- package/lib/LazyBarrel.js +0 -388
- package/lib/dependencies/HarmonyAcceptImportDependency.js +0 -39
- package/lib/dependencies/HarmonyModulesPlugin.js +0 -192
- package/lib/javascript/ChunkFormatHelpers.js +0 -72
- package/lib/javascript/grammar.js +0 -5546
- package/lib/javascript/parser.js +0 -1500
- package/lib/javascript/regexpData.js +0 -51
- package/lib/performance/getSourceModules.js +0 -22
- package/lib/util/Semaphore.js +0 -65
- package/lib/util/objectToMap.js +0 -15
- package/schemas/WebpackOptions.check.d.ts +0 -7
- package/schemas/_container.json +0 -155
- package/schemas/_sharing.json +0 -118
- package/schemas/plugins/BannerPlugin.check.d.ts +0 -7
- package/schemas/plugins/HtmlGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/HtmlParserOptions.check.d.ts +0 -7
- package/schemas/plugins/IgnorePlugin.check.d.ts +0 -7
- package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +0 -7
- package/schemas/plugins/ManifestPlugin.check.d.ts +0 -7
- package/schemas/plugins/ProgressPlugin.check.d.ts +0 -7
- package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +0 -7
- package/schemas/plugins/WatchIgnorePlugin.check.d.ts +0 -7
- package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/asset/AssetParserOptions.check.d.ts +0 -7
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/container/ContainerPlugin.check.d.ts +0 -7
- package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +0 -7
- package/schemas/plugins/container/ExternalsType.check.d.ts +0 -7
- package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +0 -7
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssParserOptions.check.d.ts +0 -7
- package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +0 -7
- package/schemas/plugins/dll/DllPlugin.check.d.ts +0 -7
- package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +0 -7
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +0 -7
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +0 -7
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +0 -7
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +0 -7
- package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +0 -7
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +0 -7
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +0 -7
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +0 -7
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +0 -7
- package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +0 -7
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +0 -7
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +0 -7
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +0 -7
- package/schemas/plugins/sharing/SharePlugin.check.d.ts +0 -7
- /package/lib/{validateSchema.js → config/validateSchema.js} +0 -0
- /package/lib/{util → css}/conventions.js +0 -0
- /package/lib/{util → css}/topologicalSort.js +0 -0
- /package/lib/dependencies/{getFunctionExpression.js → helpers/getFunctionExpression.js} +0 -0
- /package/lib/{util → externals}/extractUrlAndGlobal.js +0 -0
- /package/lib/{util → fs}/StackedCacheMap.js +0 -0
- /package/lib/{util → javascript}/StackedMap.js +0 -0
- /package/lib/{ModuleProfile.js → module/ModuleProfile.js} +0 -0
- /package/lib/{ModuleSourceTypeConstants.js → module/ModuleSourceTypeConstants.js} +0 -0
- /package/lib/{ModuleTypeConstants.js → module/ModuleTypeConstants.js} +0 -0
- /package/lib/{OptimizationStages.js → optimize/OptimizationStages.js} +0 -0
- /package/lib/{util → optimize}/Queue.js +0 -0
- /package/lib/{util → stats}/smartGrouping.js +0 -0
|
@@ -0,0 +1,1034 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Raj Aryan (based on SWC parser by Alexander Akait)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
CSS_TYPE,
|
|
10
|
+
JAVASCRIPT_TYPE
|
|
11
|
+
} = require("../module/ModuleSourceTypeConstants");
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
JAVASCRIPT_SCRIPT_TYPES,
|
|
15
|
+
JSON_SCRIPT_TYPES,
|
|
16
|
+
LEADING_NEWLINE_ELEMENTS,
|
|
17
|
+
LITERAL_TEXT_PARENTS,
|
|
18
|
+
TRANSPARENT_IMPLIED_ELEMENTS
|
|
19
|
+
} = require("./data");
|
|
20
|
+
const {
|
|
21
|
+
FLAG_FOSTER_REGION,
|
|
22
|
+
FOREIGN_ELEMENT,
|
|
23
|
+
Field,
|
|
24
|
+
Flag,
|
|
25
|
+
JSON_TYPE,
|
|
26
|
+
Namespace,
|
|
27
|
+
NodeType,
|
|
28
|
+
SVG_TYPE,
|
|
29
|
+
_CC_NUMBER_SIGN: CC_NUMBER_SIGN,
|
|
30
|
+
_S,
|
|
31
|
+
_attributeCountOf,
|
|
32
|
+
_attributeList,
|
|
33
|
+
_attributePrints,
|
|
34
|
+
_canOmitEndTag,
|
|
35
|
+
_canOmitStartTag,
|
|
36
|
+
_contentOpensOutside,
|
|
37
|
+
_dataOf,
|
|
38
|
+
_deferEmbedded,
|
|
39
|
+
_elementCloseTag,
|
|
40
|
+
_endTagOutsideSpan,
|
|
41
|
+
_endsOutsideLineBox,
|
|
42
|
+
_firstChild,
|
|
43
|
+
_formNeedsPointerReset,
|
|
44
|
+
_fosterRunMoves,
|
|
45
|
+
_fosterSourceRegion,
|
|
46
|
+
_headLeftBefore,
|
|
47
|
+
_impliedCloseTag,
|
|
48
|
+
_impliedTableGroupStartNeeded,
|
|
49
|
+
_isCssStyleElement,
|
|
50
|
+
_isRedundantAttribute,
|
|
51
|
+
_isRemovableEmptyAttribute,
|
|
52
|
+
_isRemovableEmptyElement,
|
|
53
|
+
_isSvgRoot,
|
|
54
|
+
_keepComment,
|
|
55
|
+
_minifyOpenTag,
|
|
56
|
+
_namespaceOf,
|
|
57
|
+
_nextSibling,
|
|
58
|
+
_nodeStrings,
|
|
59
|
+
_onlyTextChild,
|
|
60
|
+
_openTagSource,
|
|
61
|
+
_parentOf,
|
|
62
|
+
_printedAttributeCount,
|
|
63
|
+
_printsNothing,
|
|
64
|
+
_renderEmbeddedOrNull,
|
|
65
|
+
_rendersNow,
|
|
66
|
+
_sheetDecides,
|
|
67
|
+
_startsCharacterReference,
|
|
68
|
+
_startsOutsideLineBox,
|
|
69
|
+
_styleRunText,
|
|
70
|
+
_synthesizeOpenTag,
|
|
71
|
+
_tagNameOf,
|
|
72
|
+
_takeRenderedSheet,
|
|
73
|
+
_xmlCharacterData,
|
|
74
|
+
_xmlElementIsStyled,
|
|
75
|
+
_xmlOpenTag,
|
|
76
|
+
asciiLowercase,
|
|
77
|
+
collapseWhitespaceRuns,
|
|
78
|
+
decodeEntities,
|
|
79
|
+
escapeXmlText,
|
|
80
|
+
isAllAsciiWhitespace,
|
|
81
|
+
isAsciiAlphanumeric,
|
|
82
|
+
startsWithAsciiWhitespace,
|
|
83
|
+
stripAsciiWhitespace
|
|
84
|
+
} = require("./syntax-parser");
|
|
85
|
+
|
|
86
|
+
const NS_HTML = Namespace.HTML;
|
|
87
|
+
/** @typedef {import("./syntax-parser").EmbeddedSourceRenderer} EmbeddedSourceRenderer */
|
|
88
|
+
/** @typedef {import("./syntax-parser").DeferredEmbeddedSource} DeferredEmbeddedSource */
|
|
89
|
+
/** @typedef {import("./syntax-parser").HtmlNodeRef} HtmlNodeRef */
|
|
90
|
+
/** @typedef {import("./syntax-parser").HtmlElement} HtmlElement */
|
|
91
|
+
/** @typedef {import("./syntax-parser").HtmlDocument} HtmlDocument */
|
|
92
|
+
/** @typedef {import("./syntax-parser").HtmlDocumentFragment} HtmlDocumentFragment */
|
|
93
|
+
/** @typedef {import("./syntax-parser").HtmlNode} HtmlNode */
|
|
94
|
+
/** @typedef {import("./syntax-parser").HtmlAstSkip} HtmlAstSkip */
|
|
95
|
+
/** @typedef {import("./syntax-parser").HtmlPath} HtmlPath */
|
|
96
|
+
|
|
97
|
+
// JavaScript's two top level productions. Which one a body is decides whether
|
|
98
|
+
// `import` parses, whether it is strict, and whether `-->` opens a comment.
|
|
99
|
+
const MODULE_SCRIPT = "module";
|
|
100
|
+
const CLASSIC_SCRIPT = "script";
|
|
101
|
+
|
|
102
|
+
/** @typedef {HtmlNode | HtmlDocument | HtmlDocumentFragment} HtmlVisitableNode */
|
|
103
|
+
|
|
104
|
+
// HTML-typed views over the generic visitor machinery (`util/SourceProcessor`).
|
|
105
|
+
/**
|
|
106
|
+
* @typedef {import("../util/SourceProcessor").VisitorFn<HtmlPath>} VisitorFn
|
|
107
|
+
* @typedef {import("../util/SourceProcessor").VisitorBucket<HtmlPath>} VisitorBucket
|
|
108
|
+
* @typedef {import("../util/SourceProcessor").VisitorMap<HtmlPath>} VisitorMap
|
|
109
|
+
* @typedef {import("../util/SourceProcessor").CompiledVisitorMap<HtmlPath>} CompiledVisitorMap
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* What the minifying printer may rewrite. Every entry is on unless it is
|
|
114
|
+
* `false`, so a document one transform breaks can still be minified by the rest.
|
|
115
|
+
* @typedef {object} HtmlTransformOptions
|
|
116
|
+
* @property {(boolean | "all")=} collapseBooleanAttributes write a boolean attribute as the bare name its presence already means; `true` only the spellings the spec canonicalizes, `"all"` any value
|
|
117
|
+
* @property {(boolean | "all" | "some" | string | RegExp | ((comment: string) => boolean))=} comments which comments survive: `"some"` (the default) the ones that carry something, `true` / `"all"` every one, `false` none, or the ones a pattern matches / a predicate accepts, over the comment's own text. A comment a parser or a server reads is kept whatever this says
|
|
118
|
+
* @property {boolean=} normalizeAttributeQuotes drop or re-pick an attribute value's quotes
|
|
119
|
+
* @property {boolean=} normalizeEnumeratedAttributes fold an enumerated value to the keyword it names
|
|
120
|
+
* @property {boolean=} normalizeListAttributes normalize a space-, comma- or descriptor-separated list value (`class`, `rel`, `srcset`, `sizes`, the viewport `content`)
|
|
121
|
+
* @property {boolean=} normalizeNumericAttributes write an integer attribute the one way its rules read it
|
|
122
|
+
* @property {boolean=} normalizeUrlAttributes drop the whitespace around a URL value (`href`, `src`, `action`, …), which resolving the URL skips over
|
|
123
|
+
* @property {boolean=} removeOptionalTags leave out an optional tag other than the `<html>` / `<head>` / `<body>` shell, which is `removeImpliedTags`
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @typedef {object} HtmlProcessOptions
|
|
128
|
+
* @property {string=} fragmentContext context element tag name for fragment parsing (see `parseHtml`); the HTML analog of the CSS parser's `as` parse-mode option
|
|
129
|
+
* @property {boolean=} xml parse as XML instead of applying the HTML tree-construction rules
|
|
130
|
+
* @property {("\"" | "'")=} xmlQuote the quote an XML minifying print gives an attribute whose value costs the same in either (default `"`); `'` for a document bound for a `"`-quoted string, such as a CSS `url("data:…")`
|
|
131
|
+
* @property {HtmlAstSkip=} skip node kinds to omit from the AST for speed/memory (see `HtmlAstSkip`)
|
|
132
|
+
* @property {boolean=} minimize print the safely-minified serialization (nodes rebuilt from source, inert comments dropped, opening-tag whitespace collapsed) as `process` walks, and return it (default false = walk only, return `""`)
|
|
133
|
+
* @property {HtmlTransformOptions=} transforms which of the meaning-preserving rewrites the minifying print makes; each is on unless it is `false`
|
|
134
|
+
* @property {(boolean | "conservative" | "smart" | "all")=} collapseWhitespace collapse each run of whitespace in text to a single space, except where an ancestor renders it verbatim; `"smart"` also drops what sits against a block edge and `"all"` drops every edge (default false)
|
|
135
|
+
* @property {boolean=} removeEmptyAttributes drop an attribute whose empty value leaves it in the state its absence gives (default false)
|
|
136
|
+
* @property {boolean=} removeEmptyElements drop an element with no children and no attributes, unless its bare form is meaningful (default false)
|
|
137
|
+
* @property {boolean=} mergeStyles print a run of adjacent `<style>` elements as one sheet, which removes elements (default false)
|
|
138
|
+
* @property {boolean=} mergeScripts print a run of adjacent bare `<script>` elements whose bodies this print writes itself as one, which removes elements, hoists a later body's declarations into the ones before it, and lets a failing body end the whole run (default false)
|
|
139
|
+
* @property {boolean=} sortAttributes print an HTML or XML element's attributes commonest name first, ties by name (default false)
|
|
140
|
+
* @property {boolean=} sortTokenLists print every token list the DOM reads as a set (`class`, `rel`, `part`, …) in token order (default false)
|
|
141
|
+
* @property {(boolean | "smart" | "all")=} removeRedundantAttributes drop an attribute whose value is the element's own default; `true` is `"smart"`, and `"all"` also drops the spec defaults a selector can match, and with them a value naming no keyword where that says the same (default false)
|
|
142
|
+
* @property {(boolean | "smart" | "all")=} removeImpliedTags how much of the `<html>` / `<head>` / `<body>` shell §13.1.2.4 lets the parser imply may be left out: `"smart"` leaves out only the `<html>` start tag, `true` (or `"all"`) all six, `false` none (default `"smart"`)
|
|
143
|
+
* @property {boolean=} deferSrcdoc whether an `<iframe srcdoc>` is among what `deferEmbeddedSource` collects (default true); false for a caller that minifies them itself, which keeps the attribute on the normal path and its shorter delimiter
|
|
144
|
+
* @property {((offer: Omit<DeferredEmbeddedSource, "build">) => string | undefined)=} embeddedAnswers what a print before this one was answered for each offer, which `processAsync` passes where an answer overturned a choice made without it: a body it answers is written from it rather than deferred
|
|
145
|
+
* @property {DeferredEmbeddedSource[]=} deferEmbeddedSource collects what `renderEmbeddedSource` would be offered instead of offering it, for a caller whose renderer is asynchronous: the print leaves a marker for each and `finish` puts the answers in their place, so one parse serves both. Takes precedence over `renderEmbeddedSource`
|
|
146
|
+
* @property {EmbeddedSourceRenderer=} renderEmbeddedSource renders each nested body this document embeds — an inline `<style>`, every `style=""` (as the block's contents it is, SVG's and MathML's included), a `<script>` holding JSON or JavaScript (with `as` naming which production of it the body is — `"module"` for a `<script type=module>`, `"script"` for a classic one), every event handler attribute, with `as: "event-handler"` saying it is a function body rather than a script — the production a `return` at its top level is in, which a renderer whose engine takes only whole scripts wraps before it reads — an `<svg>` subtree, with `as: "foreign-element"` saying it is an element of this document rather than a standalone `.svg`, and the document an `<iframe srcdoc>` holds (decoded, and written back escaped). The only way any of them is minified: webpack minifies nothing here itself, and `builtinEmbeddedRenderer` is its own CSS and JSON minifiers for a caller to pass; returning anything but text leaves a body as written
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* What the HTML printer may be told, on top of the `mode` every language has:
|
|
151
|
+
* `optimization.minimize.html`, and the renderer every nested body goes through.
|
|
152
|
+
* `optimization.minimize.css` reaches inline CSS through `builtinEmbeddedRenderer`,
|
|
153
|
+
* which `htmlMinify` passes (see `lib/config/defaults.js`).
|
|
154
|
+
* @typedef {{ transforms?: HtmlTransformOptions, collapseWhitespace?: boolean | "conservative" | "smart" | "all", mergeStyles?: boolean, mergeScripts?: boolean, removeEmptyAttributes?: boolean, removeEmptyElements?: boolean, removeRedundantAttributes?: boolean | "smart" | "all", sortAttributes?: boolean, sortTokenLists?: boolean, removeImpliedTags?: boolean | "smart" | "all", renderEmbeddedSource?: EmbeddedSourceRenderer, deferEmbeddedSource?: DeferredEmbeddedSource[], embeddedAnswers?: (offer: Omit<DeferredEmbeddedSource, "build">) => string | undefined, deferSrcdoc?: boolean, xmlQuote?: "\"" | "'" }} HtmlPrintOptions
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
/** @typedef {import("../util/SourceProcessor").PrintContext<HtmlPath, HtmlNodeRef, HtmlPrintOptions>} PrintContext */
|
|
158
|
+
|
|
159
|
+
// Whether the text ends inside an unterminated character reference, so the next
|
|
160
|
+
// sibling's first characters could complete it (`a &am` + `p;`).
|
|
161
|
+
/**
|
|
162
|
+
* @param {string} s source text
|
|
163
|
+
* @returns {boolean} true when a character reference is still open at the end
|
|
164
|
+
*/
|
|
165
|
+
const _hasOpenReference = (s) => {
|
|
166
|
+
const last = s.lastIndexOf("&");
|
|
167
|
+
if (last === -1) return false;
|
|
168
|
+
// Read in place: slicing the tail off to match it against a pattern allocates
|
|
169
|
+
// a string per text node, and every one of them is thrown away here.
|
|
170
|
+
for (let i = last + 1; i < s.length; i++) {
|
|
171
|
+
const c = s.charCodeAt(i);
|
|
172
|
+
if (!isAsciiAlphanumeric(c) && c !== CC_NUMBER_SIGN) return false;
|
|
173
|
+
}
|
|
174
|
+
return true;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Whether the tag printed after this text would fuse with its tail: a `<` runs
|
|
179
|
+
* into the next tag's name, and a `</` meets that tag's `<` as a bogus comment,
|
|
180
|
+
* which consumes to the next `>` and takes the text with it.
|
|
181
|
+
* @param {string} s source text
|
|
182
|
+
* @returns {boolean} true when the text cannot be emitted as written
|
|
183
|
+
*/
|
|
184
|
+
const _tailFusesWithNextTag = (s) => {
|
|
185
|
+
const tail = s.charCodeAt(s.length - 1);
|
|
186
|
+
return tail === 60 || (tail === 47 && s.charCodeAt(s.length - 2) === 60);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Whether the `<` at `at` would leave §13.2.5.6's data state rather than stand
|
|
191
|
+
* as a character. A trailing one counts: what follows it in the output is the
|
|
192
|
+
* next sibling's first character, which this string does not hold.
|
|
193
|
+
* @param {string} s decoded text
|
|
194
|
+
* @param {number} at index of the `<`
|
|
195
|
+
* @returns {boolean} true when the `<` has to be written as a reference
|
|
196
|
+
*/
|
|
197
|
+
const _opensMarkup = (s, at) => {
|
|
198
|
+
if (at + 1 === s.length) return true;
|
|
199
|
+
const next = s.charCodeAt(at + 1);
|
|
200
|
+
return (
|
|
201
|
+
next === 0x21 ||
|
|
202
|
+
next === 0x2f ||
|
|
203
|
+
next === 0x3f ||
|
|
204
|
+
(next >= 0x41 && next <= 0x5a) ||
|
|
205
|
+
(next >= 0x61 && next <= 0x7a)
|
|
206
|
+
);
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Escape a text node's decoded data for re-serialization: `&` and `<`, which
|
|
211
|
+
* start a character reference and a tag, plus `>` outside minification, where
|
|
212
|
+
* the §13.3 serialization is followed to the letter. A CR is written as a
|
|
213
|
+
* reference either way — §13.2.3.5 rewrites a literal one to LF before the
|
|
214
|
+
* tokenizer reads it. Unlike the exported `escapeText` (which also numerically
|
|
215
|
+
* encodes newlines and U+00A0 for single-line `data:` URIs), this keeps
|
|
216
|
+
* newlines and U+00A0 literal — byte-lean and the same DOM.
|
|
217
|
+
* @param {string} s decoded text
|
|
218
|
+
* @param {boolean} minify whether the shorter (still equivalent) form is wanted
|
|
219
|
+
* @returns {string} text-content-safe string
|
|
220
|
+
*/
|
|
221
|
+
const _escapeTextContent = (s, minify) => {
|
|
222
|
+
// A bare `>` is only ever a character in text, so §13.3's escape of it buys
|
|
223
|
+
// nothing but bytes. A `<` only opens markup before what §13.2.5.6 leaves the
|
|
224
|
+
// data state for, and an `&` only sometimes starts a character reference.
|
|
225
|
+
if (minify) {
|
|
226
|
+
if (!s.includes("&") && !s.includes("<") && !s.includes("\r")) return s;
|
|
227
|
+
let out = "";
|
|
228
|
+
let last = 0;
|
|
229
|
+
for (let i = 0; i < s.length; i++) {
|
|
230
|
+
const c = s.charCodeAt(i);
|
|
231
|
+
if (c === 0x3c && _opensMarkup(s, i)) {
|
|
232
|
+
out += `${s.slice(last, i)}<`;
|
|
233
|
+
last = i + 1;
|
|
234
|
+
} else if (c === 0x26 && _startsCharacterReference(s, i)) {
|
|
235
|
+
out += `${s.slice(last, i)}&`;
|
|
236
|
+
last = i + 1;
|
|
237
|
+
} else if (c === 0x0d) {
|
|
238
|
+
// §13.2.3.5 rewrites a literal CR to LF before the tokenizer sees it,
|
|
239
|
+
// so one a character reference put in the text has to stay one.
|
|
240
|
+
out += `${s.slice(last, i)} `;
|
|
241
|
+
last = i + 1;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return last === 0 ? s : out + s.slice(last);
|
|
245
|
+
}
|
|
246
|
+
if (
|
|
247
|
+
!s.includes("&") &&
|
|
248
|
+
!s.includes("<") &&
|
|
249
|
+
!s.includes(">") &&
|
|
250
|
+
!s.includes("\r")
|
|
251
|
+
) {
|
|
252
|
+
return s;
|
|
253
|
+
}
|
|
254
|
+
return s
|
|
255
|
+
.replace(/&/g, "&")
|
|
256
|
+
.replace(/</g, "<")
|
|
257
|
+
.replace(/>/g, ">")
|
|
258
|
+
.replace(/\r/g, " ");
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Whether a text node is the whole body of an SVG or XHTML `<style>`, which a
|
|
263
|
+
* caller's renderer is offered as the stylesheet it is.
|
|
264
|
+
* @param {HtmlPath} path the accessor positioned on the text node
|
|
265
|
+
* @returns {boolean} true when the text is a stylesheet to render
|
|
266
|
+
*/
|
|
267
|
+
const _isXmlStylesheet = (path) => {
|
|
268
|
+
if (
|
|
269
|
+
_S._renderEmbeddedSource === undefined &&
|
|
270
|
+
_S._deferEmbeddedSource === undefined
|
|
271
|
+
) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
const parent = _parentOf(path.node);
|
|
275
|
+
if (parent === 0) return false;
|
|
276
|
+
const name = _tagNameOf(parent);
|
|
277
|
+
if (name !== "style" && !name.endsWith(":style")) return false;
|
|
278
|
+
// As in HTML, the attribute is optional and only `text/css` keeps it CSS.
|
|
279
|
+
const attribute = path.fieldNamed(Field.attributes, "type", parent);
|
|
280
|
+
if (attribute !== 0) {
|
|
281
|
+
const type = asciiLowercase(stripAsciiWhitespace(path.value(attribute)));
|
|
282
|
+
if (type !== "" && type !== "text/css") return false;
|
|
283
|
+
}
|
|
284
|
+
// A comment or an element beside it splits the sheet, which is left alone.
|
|
285
|
+
return (
|
|
286
|
+
_firstChild(parent) === path.node &&
|
|
287
|
+
_nextSibling(path.node) === 0 &&
|
|
288
|
+
_xmlElementIsStyled(parent)
|
|
289
|
+
);
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Print a node of a document parsed as XML. Nothing HTML's serialization does
|
|
294
|
+
* applies: no tag is implied or omitted, every value stays quoted, and text is
|
|
295
|
+
* written as character data, as the source did or in the shorter spelling.
|
|
296
|
+
* @param {HtmlPath} path the accessor positioned on the node to print
|
|
297
|
+
* @param {PrintContext} writer the print context
|
|
298
|
+
* @param {boolean} minify whether minifying
|
|
299
|
+
* @returns {string} the node's text
|
|
300
|
+
*/
|
|
301
|
+
const _printXml = (path, writer, minify) => {
|
|
302
|
+
switch (path.type()) {
|
|
303
|
+
case NodeType.Element: {
|
|
304
|
+
let inner = "";
|
|
305
|
+
for (let c = _firstChild(path.node); c !== 0; c = _nextSibling(c)) {
|
|
306
|
+
inner += writer.get(c);
|
|
307
|
+
}
|
|
308
|
+
const tag = _xmlOpenTag(path, minify);
|
|
309
|
+
// §3.1 makes `<a></a>` and `<a/>` the same element, so the shorter wins
|
|
310
|
+
// when minifying and the source's spelling is kept otherwise.
|
|
311
|
+
if (inner === "" && (minify || path.flag(Flag.selfClosing))) {
|
|
312
|
+
return `${tag.slice(0, -1)}/>`;
|
|
313
|
+
}
|
|
314
|
+
return `${tag}${inner}</${_tagNameOf(path.node)}>`;
|
|
315
|
+
}
|
|
316
|
+
case NodeType.Text: {
|
|
317
|
+
const raw = path.source();
|
|
318
|
+
const data = _dataOf(path.node);
|
|
319
|
+
if (minify && _isXmlStylesheet(path)) {
|
|
320
|
+
return data.trim() === ""
|
|
321
|
+
? raw
|
|
322
|
+
: _S._deferEmbeddedSource === undefined
|
|
323
|
+
? _xmlCharacterData(_renderEmbedded(data, CSS_TYPE))
|
|
324
|
+
: _deferEmbedded(data, CSS_TYPE, (rendered) =>
|
|
325
|
+
_xmlCharacterData(
|
|
326
|
+
typeof rendered === "string" ? rendered : data
|
|
327
|
+
)
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
// A CDATA section the input ran out in would hold the end tags after it.
|
|
331
|
+
if (!minify) {
|
|
332
|
+
return raw.includes("<![CDATA[") && !raw.endsWith("]]>")
|
|
333
|
+
? escapeXmlText(data)
|
|
334
|
+
: raw;
|
|
335
|
+
}
|
|
336
|
+
let escaped = escapeXmlText(data);
|
|
337
|
+
if (
|
|
338
|
+
escaped.length > data.length + 12 &&
|
|
339
|
+
!data.includes("]]>") &&
|
|
340
|
+
!data.includes("\r")
|
|
341
|
+
) {
|
|
342
|
+
escaped = `<![CDATA[${data}]]>`;
|
|
343
|
+
}
|
|
344
|
+
// The source's own spelling when shorter: a declared entity reference, or
|
|
345
|
+
// a `>` it left bare. A `<` in it is a CDATA section, never kept as is.
|
|
346
|
+
return raw.length < escaped.length && !raw.includes("<") ? raw : escaped;
|
|
347
|
+
}
|
|
348
|
+
case NodeType.Comment: {
|
|
349
|
+
const source = path.source();
|
|
350
|
+
if (minify && !_keepComment(_dataOf(path.node), source, path.start())) {
|
|
351
|
+
return "";
|
|
352
|
+
}
|
|
353
|
+
// Closed if the input ran out in it, or it would hold the end tags after it.
|
|
354
|
+
return source.startsWith("<!--") && !source.endsWith("-->")
|
|
355
|
+
? `${source}-->`
|
|
356
|
+
: source;
|
|
357
|
+
}
|
|
358
|
+
// A DOCTYPE's internal subset declares what the references read, and an
|
|
359
|
+
// instruction is addressed to a consumer: both print as written. XML has
|
|
360
|
+
// no fragment or template, so nothing else reaches the printer.
|
|
361
|
+
default:
|
|
362
|
+
return path.source();
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* `_renderEmbeddedOrNull` with the body left exactly as written where the
|
|
368
|
+
* renderer declines it, deferred to the caller's where one collects.
|
|
369
|
+
* @param {string} source the nested body
|
|
370
|
+
* @param {string} type its language, e.g. `"css"` / `"javascript"` / `"svg"`
|
|
371
|
+
* @param {string=} as which production of that language it is, for one with more than one
|
|
372
|
+
* @param {((rendered: string | undefined) => boolean)=} decides whether a deferred answer overturns a choice this print made without it
|
|
373
|
+
* @returns {string} the rendered body, or the original
|
|
374
|
+
*/
|
|
375
|
+
const _renderEmbedded = (source, type, as, decides) => {
|
|
376
|
+
if (_S._deferEmbeddedSource !== undefined) {
|
|
377
|
+
const escape = _S._escapeEmbedded;
|
|
378
|
+
return _deferEmbedded(
|
|
379
|
+
source,
|
|
380
|
+
type,
|
|
381
|
+
(rendered) => {
|
|
382
|
+
const text = typeof rendered === "string" ? rendered : source;
|
|
383
|
+
return escape ? _escapeTextContent(text, true) : text;
|
|
384
|
+
},
|
|
385
|
+
as,
|
|
386
|
+
decides
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
const rendered = _renderEmbeddedOrNull(source, type, as);
|
|
390
|
+
return rendered === null ? source : rendered;
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Offer a `<style>` body to the renderer, blank text kept as written. Webpack
|
|
395
|
+
* minifies no CSS here itself: `builtinEmbeddedRenderer` is what a caller
|
|
396
|
+
* passes for that.
|
|
397
|
+
* @param {string} css the element's text
|
|
398
|
+
* @returns {string} the rendered text, the marker standing for it, or the text as written
|
|
399
|
+
*/
|
|
400
|
+
const _minifyStyleBody = (css) => {
|
|
401
|
+
if (css.trim() === "") return css;
|
|
402
|
+
// Through the emptiness check's memo, which may have rendered it already.
|
|
403
|
+
if (_rendersNow()) return _takeRenderedSheet(css);
|
|
404
|
+
return _renderEmbedded(css, CSS_TYPE, undefined, _sheetDecides());
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* A `<script>`'s lowercased `type`, or `""` when it has none.
|
|
409
|
+
* @param {HtmlPath} path the accessor
|
|
410
|
+
* @param {HtmlElement} element the `<script>` element
|
|
411
|
+
* @returns {string} the type
|
|
412
|
+
*/
|
|
413
|
+
const _scriptType = (path, element) => {
|
|
414
|
+
for (const attribute of _attributeList(element)) {
|
|
415
|
+
if (attribute.name === "type") {
|
|
416
|
+
// The value the spec matches is the one the parser read, so a reference
|
|
417
|
+
// is decoded first: `text/javascript` runs, it is not a data block.
|
|
418
|
+
return asciiLowercase(
|
|
419
|
+
stripAsciiWhitespace(decodeEntities(attribute.value, true))
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return "";
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
const _JSON_SUBTYPE_REGEXP =
|
|
427
|
+
/^[!#$%&'*+.^_`|~\w-]+\/[!#$%&'*+.^_`|~\w-]*\+json$/;
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Offer a JSON `<script>` body to the renderer, blank text kept as written;
|
|
431
|
+
* `stripJsonWhitespace` is what webpack's own answers with.
|
|
432
|
+
* @param {string} json a `<script>` body
|
|
433
|
+
* @returns {string} the rendered body, the marker standing for it, or the body as written
|
|
434
|
+
*/
|
|
435
|
+
const _minifyInlineJson = (json) =>
|
|
436
|
+
json.trim() === "" ? json : _renderEmbedded(json, JSON_TYPE);
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* The text the first `<style>` of a run prints: every sheet in it joined and
|
|
440
|
+
* offered as one, the rest of the run marked absorbed so their tags and text
|
|
441
|
+
* print as nothing. A sheet after the first carrying `@import` (or `@charset` /
|
|
442
|
+
* `@namespace`) is not joined, since it would stop applying.
|
|
443
|
+
* @param {HtmlPath} path the accessor
|
|
444
|
+
* @param {HtmlElement} element the run's first `<style>`
|
|
445
|
+
* @param {string} css its own text
|
|
446
|
+
* @returns {string} the run's text
|
|
447
|
+
*/
|
|
448
|
+
const _mergedStyleRun = (path, element, css) =>
|
|
449
|
+
_minifyStyleBody(_styleRunText(path, element, css, true));
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Whether a script body ends where another can be appended after it. A body
|
|
453
|
+
* still inside a string, template or block comment would swallow the next one;
|
|
454
|
+
* a trailing line comment is fine because the join writes a newline first. The
|
|
455
|
+
* body is read rather than parsed, so a regex literal can be taken for a string
|
|
456
|
+
* or a comment — the answer holds for a body that parses, and one that does not
|
|
457
|
+
* takes its whole run with it however this reads.
|
|
458
|
+
* @param {string} js the script's text
|
|
459
|
+
* @returns {boolean} true when nothing is left open
|
|
460
|
+
*/
|
|
461
|
+
const _scriptEndsClean = (js) => {
|
|
462
|
+
let state = 0; // 0 none, 1 line comment, 2 block comment, 3 ' 4 " 5 `
|
|
463
|
+
// Read by code unit: a body is scanned whole, and `js[i]` would allocate a
|
|
464
|
+
// one-character string at every position of it.
|
|
465
|
+
for (let i = 0; i < js.length; i++) {
|
|
466
|
+
const c = js.charCodeAt(i);
|
|
467
|
+
if (state === 0) {
|
|
468
|
+
if (c === 47 /* / */) {
|
|
469
|
+
const next = js.charCodeAt(i + 1);
|
|
470
|
+
if (next === 47) {
|
|
471
|
+
state = 1;
|
|
472
|
+
i++;
|
|
473
|
+
} else if (next === 42 /* * */) {
|
|
474
|
+
state = 2;
|
|
475
|
+
i++;
|
|
476
|
+
}
|
|
477
|
+
} else if (c === 39 /* ' */) {
|
|
478
|
+
state = 3;
|
|
479
|
+
} else if (c === 34 /* " */) {
|
|
480
|
+
state = 4;
|
|
481
|
+
} else if (c === 96 /* ` */) {
|
|
482
|
+
state = 5;
|
|
483
|
+
}
|
|
484
|
+
} else if (state === 1) {
|
|
485
|
+
// Every line terminator ends a line comment, not just the two HTML
|
|
486
|
+
// normalizes text to — a `"` past one really does open a string.
|
|
487
|
+
if (c === 10 || c === 13 || c === 0x2028 || c === 0x2029) state = 0;
|
|
488
|
+
} else if (state === 2) {
|
|
489
|
+
if (c === 42 && js.charCodeAt(i + 1) === 47) {
|
|
490
|
+
state = 0;
|
|
491
|
+
i++;
|
|
492
|
+
}
|
|
493
|
+
} else if (c === 92 /* \\ */) {
|
|
494
|
+
i++;
|
|
495
|
+
} else if (
|
|
496
|
+
(state === 3 && c === 39) ||
|
|
497
|
+
(state === 4 && c === 34) ||
|
|
498
|
+
(state === 5 && c === 96)
|
|
499
|
+
) {
|
|
500
|
+
state = 0;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
return state === 0 || state === 1;
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
// ECMAScript's own whitespace and line terminators, which are wider than the
|
|
507
|
+
// HTML ones: a BOM, a form feed and U+2028 all sit before a directive.
|
|
508
|
+
const JS_WHITESPACE_REGEXP = /\s/;
|
|
509
|
+
const JS_LINE_TERMINATOR_REGEXP = /[\n\r\u2028\u2029]/;
|
|
510
|
+
const BOM_REGEXP = /^\uFEFF/;
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Whether a script body opens with what only a script's own start carries: a
|
|
514
|
+
* hashbang, or a directive prologue — the leading string `"use strict"` is one.
|
|
515
|
+
* Appended after another body neither means that any more.
|
|
516
|
+
* @param {string} js the script's text
|
|
517
|
+
* @returns {boolean} true when the body must start a script of its own
|
|
518
|
+
*/
|
|
519
|
+
const _opensAScript = (js) => {
|
|
520
|
+
// A hashbang is only one at the very start, a BOM aside.
|
|
521
|
+
if (js.replace(BOM_REGEXP, "").startsWith("#!")) return true;
|
|
522
|
+
let i = 0;
|
|
523
|
+
while (i < js.length) {
|
|
524
|
+
const c = js[i];
|
|
525
|
+
if (JS_WHITESPACE_REGEXP.test(c)) {
|
|
526
|
+
i++;
|
|
527
|
+
} else if (c === "/" && js[i + 1] === "/") {
|
|
528
|
+
i += 2;
|
|
529
|
+
while (i < js.length && !JS_LINE_TERMINATOR_REGEXP.test(js[i])) i++;
|
|
530
|
+
} else if (c === "/" && js[i + 1] === "*") {
|
|
531
|
+
const end = js.indexOf("*/", i + 2);
|
|
532
|
+
if (end === -1) return true;
|
|
533
|
+
i = end + 2;
|
|
534
|
+
} else {
|
|
535
|
+
break;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return js[i] === '"' || js[i] === "'";
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Whether a body opens with `-->` still on its first line. That is a single
|
|
543
|
+
* line comment only where nothing but whitespace and same-line comments comes
|
|
544
|
+
* before it on the line, which an appended body no longer begins.
|
|
545
|
+
* @param {string} js the script's text
|
|
546
|
+
* @returns {boolean} true when appending the body would change what `-->` means
|
|
547
|
+
*/
|
|
548
|
+
const _opensWithHtmlCloseComment = (js) => {
|
|
549
|
+
let i = 0;
|
|
550
|
+
while (i < js.length) {
|
|
551
|
+
const c = js[i];
|
|
552
|
+
if (JS_LINE_TERMINATOR_REGEXP.test(c)) return false;
|
|
553
|
+
if (JS_WHITESPACE_REGEXP.test(c)) {
|
|
554
|
+
i++;
|
|
555
|
+
} else if (c === "/" && js[i + 1] === "*") {
|
|
556
|
+
const end = js.indexOf("*/", i + 2);
|
|
557
|
+
// One spanning a line terminator ends the line it opened, so what
|
|
558
|
+
// follows starts a line of its own.
|
|
559
|
+
if (end === -1 || JS_LINE_TERMINATOR_REGEXP.test(js.slice(i + 2, end))) {
|
|
560
|
+
return false;
|
|
561
|
+
}
|
|
562
|
+
i = end + 2;
|
|
563
|
+
} else {
|
|
564
|
+
return js.startsWith("-->", i);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return false;
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* The `<script>` that may be folded into `element`: the next sibling, when only
|
|
572
|
+
* whitespace lies between them and neither carries a single attribute. Bare is
|
|
573
|
+
* the whole test — a `src`, `type`, `nonce`, `async` or `id` all say the two
|
|
574
|
+
* elements are not interchangeable with one.
|
|
575
|
+
* @param {HtmlPath} path the accessor
|
|
576
|
+
* @param {HtmlElement} element a `<script>` element
|
|
577
|
+
* @returns {HtmlElement} the next `<script>` of the run, or 0
|
|
578
|
+
*/
|
|
579
|
+
const _mergeableScriptAfter = (path, element) => {
|
|
580
|
+
if (_printedAttributeCount(path, element) !== 0) return 0;
|
|
581
|
+
for (
|
|
582
|
+
let next = _S._nodeNextSiblings[element];
|
|
583
|
+
next !== 0;
|
|
584
|
+
next = _S._nodeNextSiblings[next]
|
|
585
|
+
) {
|
|
586
|
+
const type = _S._nodeTypes[next];
|
|
587
|
+
if (type === NodeType.Text) {
|
|
588
|
+
if (!isAllAsciiWhitespace(_nodeStrings[next])) return 0;
|
|
589
|
+
continue;
|
|
590
|
+
}
|
|
591
|
+
// A comment this print drops leaves the two adjacent, so it is not what
|
|
592
|
+
// stands between them; one it keeps still is.
|
|
593
|
+
if (type === NodeType.Comment) {
|
|
594
|
+
if (_printsNothing(path, next)) continue;
|
|
595
|
+
return 0;
|
|
596
|
+
}
|
|
597
|
+
return type === NodeType.Element &&
|
|
598
|
+
_namespaceOf(next) === NS_HTML &&
|
|
599
|
+
_tagNameOf(next) === "script" &&
|
|
600
|
+
_printedAttributeCount(path, next) === 0 &&
|
|
601
|
+
_onlyTextChild(next) !== 0
|
|
602
|
+
? next
|
|
603
|
+
: 0;
|
|
604
|
+
}
|
|
605
|
+
return 0;
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* The text the first `<script>` of a run prints: every body in it, joined by a
|
|
610
|
+
* newline and a `;`. The newline ends a trailing line comment and the `;` keeps
|
|
611
|
+
* the next body from continuing the last statement — `var a = 1` followed by
|
|
612
|
+
* `(f)()` is one call without it.
|
|
613
|
+
* @param {HtmlPath} path the accessor
|
|
614
|
+
* @param {HtmlElement} element the run's first `<script>`
|
|
615
|
+
* @param {string} js its own text
|
|
616
|
+
* @returns {string} the run's text
|
|
617
|
+
*/
|
|
618
|
+
const _mergedScriptRun = (path, element, js) => {
|
|
619
|
+
// A deferred body is a stand-in the caller swaps out after the print, so the
|
|
620
|
+
// text read here is neither the code that runs nor what a guard can judge.
|
|
621
|
+
if (_S._deferEmbeddedSource !== undefined) return js;
|
|
622
|
+
// Asked before the body is scanned: a lone `<script>` is the common case and
|
|
623
|
+
// scanning it whole to then find nothing to fold into is the whole cost.
|
|
624
|
+
const first = _mergeableScriptAfter(path, element);
|
|
625
|
+
if (first === 0) return js;
|
|
626
|
+
// A prologue reaches whatever is appended after it, so a strict first body
|
|
627
|
+
// would put the rest of the run in strict mode too.
|
|
628
|
+
if (!_scriptEndsClean(js) || _opensAScript(js)) return js;
|
|
629
|
+
let out = js;
|
|
630
|
+
for (let next = first; next !== 0; next = _mergeableScriptAfter(path, next)) {
|
|
631
|
+
const body =
|
|
632
|
+
_nodeStrings[/** @type {HtmlNodeRef} */ (_onlyTextChild(next))];
|
|
633
|
+
if (
|
|
634
|
+
!_scriptEndsClean(body) ||
|
|
635
|
+
_opensAScript(body) ||
|
|
636
|
+
_opensWithHtmlCloseComment(body)
|
|
637
|
+
) {
|
|
638
|
+
break;
|
|
639
|
+
}
|
|
640
|
+
if (_S._absorbed === null) _S._absorbed = new Set();
|
|
641
|
+
_S._absorbed.add(next);
|
|
642
|
+
out += `\n;${body}`;
|
|
643
|
+
}
|
|
644
|
+
return out;
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* An element's open tag as the printer would emit it; the source tag it was
|
|
649
|
+
* read from is left in `_elementOpenSource`.
|
|
650
|
+
* @param {HtmlPath} path positioned on the element
|
|
651
|
+
* @param {boolean} minify whether minifying
|
|
652
|
+
* @returns {string} the printed open tag
|
|
653
|
+
*/
|
|
654
|
+
const _elementOpenTag = (path, minify) => {
|
|
655
|
+
const source = _openTagSource(path);
|
|
656
|
+
return minify && source !== "" ? _minifyOpenTag(path, source) : source;
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* Whether this element is one the settled runs concern — the parent a run was
|
|
661
|
+
* fostered into, or the table it goes back inside. Every other element composes
|
|
662
|
+
* its children the way it always did.
|
|
663
|
+
* @param {HtmlNodeRef} node the element
|
|
664
|
+
* @returns {boolean} true when it has to read the run
|
|
665
|
+
*/
|
|
666
|
+
const _fosterTouches = (node) =>
|
|
667
|
+
(_S._fosterVerbatim !== null && _S._fosterVerbatim.has(node)) ||
|
|
668
|
+
/** @type {Set<HtmlNodeRef>} */ (_S._fosterHolders).has(node) ||
|
|
669
|
+
/** @type {Map<HtmlNodeRef, HtmlNodeRef[]>} */ (_S._fosteredRuns).has(node);
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* The body a literal-text element (`script` / `style` / …) prints, minified
|
|
673
|
+
* where the mode and the element's type allow it.
|
|
674
|
+
* @param {HtmlPath} path the path the walk is at
|
|
675
|
+
* @param {number} parent the literal-text element holding this text node
|
|
676
|
+
* @param {string} data the text node's data
|
|
677
|
+
* @param {boolean} minify whether the print is minifying
|
|
678
|
+
* @returns {string} the body to print
|
|
679
|
+
*/
|
|
680
|
+
const _literalTextBody = (path, parent, data, minify) => {
|
|
681
|
+
if (!minify) return data;
|
|
682
|
+
const literalName = _tagNameOf(parent);
|
|
683
|
+
if (literalName === "style") {
|
|
684
|
+
if (!_isCssStyleElement(path, parent)) return data;
|
|
685
|
+
if (!_S._mergeStyles) {
|
|
686
|
+
const minified = _minifyStyleBody(data);
|
|
687
|
+
return minified === null ? data : minified;
|
|
688
|
+
}
|
|
689
|
+
// The run's first sheet prints the whole run; the rest printed
|
|
690
|
+
// into it here, before their own text or tags are reached.
|
|
691
|
+
return _S._absorbed !== null && _S._absorbed.has(parent)
|
|
692
|
+
? ""
|
|
693
|
+
: _mergedStyleRun(path, parent, data);
|
|
694
|
+
}
|
|
695
|
+
if (literalName === "script") {
|
|
696
|
+
const type = _scriptType(path, parent);
|
|
697
|
+
if (JSON_SCRIPT_TYPES.has(type) || _JSON_SUBTYPE_REGEXP.test(type)) {
|
|
698
|
+
return _minifyInlineJson(data);
|
|
699
|
+
}
|
|
700
|
+
// A bare `<script>` is the classic one a run may fold into, and
|
|
701
|
+
// the run's first prints all of it — the rest printed into it here.
|
|
702
|
+
let body = data;
|
|
703
|
+
if (_S._mergeScripts && _printedAttributeCount(path, parent) === 0) {
|
|
704
|
+
if (_S._absorbed !== null && _S._absorbed.has(parent)) return "";
|
|
705
|
+
body = _mergedScriptRun(path, parent, data);
|
|
706
|
+
}
|
|
707
|
+
// Webpack ships no JS minifier, so an inline script is touched only
|
|
708
|
+
// by a caller's renderer; the built-in declines it.
|
|
709
|
+
if (JAVASCRIPT_SCRIPT_TYPES.has(type) && body.trim() !== "") {
|
|
710
|
+
return _renderEmbedded(
|
|
711
|
+
body,
|
|
712
|
+
JAVASCRIPT_TYPE,
|
|
713
|
+
type === MODULE_SCRIPT ? MODULE_SCRIPT : CLASSIC_SCRIPT
|
|
714
|
+
);
|
|
715
|
+
}
|
|
716
|
+
return body;
|
|
717
|
+
}
|
|
718
|
+
return data;
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* An element's children's text when this document foster parented something: a
|
|
723
|
+
* run that moves prints inside the table it was written in rather than where the
|
|
724
|
+
* tree holds it, interleaved with the table's own children in source order —
|
|
725
|
+
* which is the order they were written in, so the parser fosters them right back
|
|
726
|
+
* out to where they are now.
|
|
727
|
+
* @param {HtmlPath} path the accessor positioned on the element
|
|
728
|
+
* @param {PrintContext} writer the print context
|
|
729
|
+
* @returns {string} the children's text
|
|
730
|
+
*/
|
|
731
|
+
const _composeAroundFoster = (path, writer) => {
|
|
732
|
+
const node = path.node;
|
|
733
|
+
const fostered = /** @type {Map<HtmlNodeRef, HtmlNodeRef>} */ (
|
|
734
|
+
_S._fosteredNodes
|
|
735
|
+
);
|
|
736
|
+
const run = _fosterRunMoves(path, node)
|
|
737
|
+
? /** @type {Map<HtmlNodeRef, HtmlNodeRef[]>} */ (_S._fosteredRuns).get(
|
|
738
|
+
node
|
|
739
|
+
)
|
|
740
|
+
: undefined;
|
|
741
|
+
/** @type {HtmlNodeRef[]} */
|
|
742
|
+
const order = run === undefined ? [] : [...run];
|
|
743
|
+
const moved = order.length !== 0;
|
|
744
|
+
for (let c = _firstChild(path.node); c !== 0; c = _nextSibling(c)) {
|
|
745
|
+
const from = fostered.get(c);
|
|
746
|
+
if (from !== undefined && _fosterRunMoves(path, from)) continue;
|
|
747
|
+
order.push(c);
|
|
748
|
+
}
|
|
749
|
+
if (moved) order.sort((a, b) => path.start(a) - path.start(b));
|
|
750
|
+
if (
|
|
751
|
+
(_S._nodeFlags[node] & FLAG_FOSTER_REGION) !== 0 &&
|
|
752
|
+
/** @type {Set<HtmlNodeRef>} */ (_S._fosterVerbatim).has(node)
|
|
753
|
+
) {
|
|
754
|
+
return _fosterSourceRegion(path, node);
|
|
755
|
+
}
|
|
756
|
+
let inner = "";
|
|
757
|
+
for (let i = 0; i < order.length; i++) inner += writer.get(order[i]);
|
|
758
|
+
return inner;
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* A comment or processing instruction as written, closed where the input ran
|
|
763
|
+
* out inside it (§13.2.5): left open, the end tags printed after it are read as
|
|
764
|
+
* part of it. A `<!--` one reads a `>` as data unless `--` or `--!` precedes it,
|
|
765
|
+
* so it is rebuilt from its data; the rest end at their first `>` and get one.
|
|
766
|
+
* @param {HtmlPath} path the accessor positioned on the node
|
|
767
|
+
* @returns {string} the node's source, closed
|
|
768
|
+
*/
|
|
769
|
+
const _closedCommentSource = (path) => {
|
|
770
|
+
const source = path.source();
|
|
771
|
+
if (path.end() !== _S.source.length) return source;
|
|
772
|
+
if (source.startsWith("<!--")) {
|
|
773
|
+
return source.endsWith("-->") || source.endsWith("--!>")
|
|
774
|
+
? source
|
|
775
|
+
: `<!--${_dataOf(path.node)}-->`;
|
|
776
|
+
}
|
|
777
|
+
return source.endsWith(">") ? source : `${source}>`;
|
|
778
|
+
};
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* The default HTML node printer — passed to the `SourceProcessor` and fired per
|
|
782
|
+
* node once its children are printed (a developer could supply their own). It
|
|
783
|
+
* takes the same `path` a visitor gets plus the print context as its `writer`,
|
|
784
|
+
* and knows nothing of the walk: it switches on `path.type()`, serializes the node
|
|
785
|
+
* — opening tags kept verbatim from source (attribute quoting / spacing
|
|
786
|
+
* preserved), end tags generated, text re-escaped from its decoded value — pulling
|
|
787
|
+
* its children's already-printed text from `writer.get`, and **returns** it. This
|
|
788
|
+
* is the WHATWG serialization, so the output re-parses to the same DOM (text-node
|
|
789
|
+
* offsets can overrun end tags, so source slices can't be used for text). The
|
|
790
|
+
* minify transforms are dropping inert comments and collapsing the whitespace
|
|
791
|
+
* between an opening tag's attributes; DOM-absent whitespace (between the
|
|
792
|
+
* doctype and `<html>`, etc.) naturally falls away.
|
|
793
|
+
* @param {HtmlPath} path the accessor positioned on the finished node
|
|
794
|
+
* @param {PrintContext} writer the print context (children's printed text)
|
|
795
|
+
* @returns {string} the node's serialized text
|
|
796
|
+
* @experimental exposed as `webpack.html.syntax.printer`; unstable API
|
|
797
|
+
*/
|
|
798
|
+
const printer = (path, writer) => {
|
|
799
|
+
const minify = writer.options.mode === "minify";
|
|
800
|
+
if (_S._xmlMode) return _printXml(path, writer, minify);
|
|
801
|
+
switch (path.type()) {
|
|
802
|
+
case NodeType.Element: {
|
|
803
|
+
// Folded into the `<style>` before it, which printed the whole run, or
|
|
804
|
+
// carrying nothing at all.
|
|
805
|
+
if (
|
|
806
|
+
minify &&
|
|
807
|
+
((_S._absorbed !== null && _S._absorbed.has(path.node)) ||
|
|
808
|
+
_isRemovableEmptyElement(path, path.node))
|
|
809
|
+
) {
|
|
810
|
+
return "";
|
|
811
|
+
}
|
|
812
|
+
// Minifying rewrites the tag (attribute spacing / quoting) but never its
|
|
813
|
+
// `/>`-ness, which the end-tag decision below reads off the source.
|
|
814
|
+
const tag = _elementOpenTag(path, minify);
|
|
815
|
+
const open = _S._elementOpenSource;
|
|
816
|
+
// The whole subtree goes to the renderer, its nested bodies already
|
|
817
|
+
// rendered — children print before their parent.
|
|
818
|
+
const svgRoot =
|
|
819
|
+
minify &&
|
|
820
|
+
(_S._renderEmbeddedSource !== undefined ||
|
|
821
|
+
_S._deferEmbeddedSource !== undefined) &&
|
|
822
|
+
_isSvgRoot(path);
|
|
823
|
+
// Void / self-closing elements have no children and no end tag; a
|
|
824
|
+
// tag-less one (`<image>` → img, `</br>` → br) is rebuilt, not dropped.
|
|
825
|
+
if (path.flag(Flag.selfClosing)) {
|
|
826
|
+
const selfClosed = open !== "" ? tag : _synthesizeOpenTag(path);
|
|
827
|
+
return svgRoot
|
|
828
|
+
? _renderEmbedded(selfClosed, SVG_TYPE, FOREIGN_ELEMENT)
|
|
829
|
+
: selfClosed;
|
|
830
|
+
}
|
|
831
|
+
// `<template>` holds its children in a content fragment, not the child
|
|
832
|
+
// chain; every other element reconstructs from its children in order.
|
|
833
|
+
const tc = path.field(0, Field.content);
|
|
834
|
+
let inner = "";
|
|
835
|
+
if (tc !== 0) {
|
|
836
|
+
inner = writer.get(tc);
|
|
837
|
+
} else {
|
|
838
|
+
if (_S._fosteredRuns !== null && _fosterTouches(path.node)) {
|
|
839
|
+
inner = _composeAroundFoster(path, writer);
|
|
840
|
+
} else {
|
|
841
|
+
for (let c = _firstChild(path.node); c !== 0; c = _nextSibling(c)) {
|
|
842
|
+
inner += writer.get(c);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
// Round-trip the parser's leading-newline strip (`<pre>` / `<textarea>`
|
|
846
|
+
// / `<listing>`) so a value that starts with one survives re-parsing.
|
|
847
|
+
if (
|
|
848
|
+
inner.charCodeAt(0) === 10 &&
|
|
849
|
+
_namespaceOf(path.node) === NS_HTML &&
|
|
850
|
+
LEADING_NEWLINE_ELEMENTS.has(_tagNameOf(path.node))
|
|
851
|
+
) {
|
|
852
|
+
inner = `\n${inner}`;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
const name = _tagNameOf(path.node);
|
|
856
|
+
// The end tag is handled by the optional-end-tag rules like any other.
|
|
857
|
+
if (minify && _canOmitStartTag(path, name, path.node, open)) {
|
|
858
|
+
const implied = _canOmitEndTag(path, name, path.node)
|
|
859
|
+
? ""
|
|
860
|
+
: `</${name}>`;
|
|
861
|
+
return inner + implied;
|
|
862
|
+
}
|
|
863
|
+
if (open === "") {
|
|
864
|
+
// A parser-implied structural element stays transparent — the parser
|
|
865
|
+
// re-implies it — but only when attribute-less (repeated `<html>` /
|
|
866
|
+
// `<body>` tags merge attributes onto the implied element).
|
|
867
|
+
if (
|
|
868
|
+
_attributeCountOf(path.node) === 0 &&
|
|
869
|
+
TRANSPARENT_IMPLIED_ELEMENTS.has(name)
|
|
870
|
+
) {
|
|
871
|
+
// Leading whitespace only survives re-parsing once `<body>` has
|
|
872
|
+
// started: before that the insertion modes drop it. Materializing
|
|
873
|
+
// the tag is the cheapest way to keep the text node intact.
|
|
874
|
+
if (
|
|
875
|
+
(name === "body" || name === "html") &&
|
|
876
|
+
(startsWithAsciiWhitespace(inner) ||
|
|
877
|
+
_contentOpensOutside(path.node))
|
|
878
|
+
) {
|
|
879
|
+
return `<${name}>${inner}`;
|
|
880
|
+
}
|
|
881
|
+
// §4.13 lets the start tag go only when the group before it kept
|
|
882
|
+
// its end tag, or that one would take these columns over.
|
|
883
|
+
if (_impliedTableGroupStartNeeded(path, name, path.node)) {
|
|
884
|
+
return `<${name}>${inner}`;
|
|
885
|
+
}
|
|
886
|
+
// The parser re-implies the start tag, but not the end tag the
|
|
887
|
+
// source carried: without it whatever follows moves inside.
|
|
888
|
+
return inner + _impliedCloseTag(path, name, path.node);
|
|
889
|
+
}
|
|
890
|
+
// Anything else tag-less (adoption-agency clone, reconstructed
|
|
891
|
+
// formatting element) must materialize or its formatting is lost.
|
|
892
|
+
return `${_synthesizeOpenTag(path) + inner}</${name}>`;
|
|
893
|
+
}
|
|
894
|
+
const composed =
|
|
895
|
+
(name === "form" && _formNeedsPointerReset(path) ? "</form>" : "") +
|
|
896
|
+
tag +
|
|
897
|
+
inner +
|
|
898
|
+
// Its content came out of the source unchanged, so an end tag the
|
|
899
|
+
// source never wrote would leave the parser somewhere else.
|
|
900
|
+
((_S._nodeFlags[path.node] & FLAG_FOSTER_REGION) !== 0 &&
|
|
901
|
+
!_endTagOutsideSpan(path)
|
|
902
|
+
? ""
|
|
903
|
+
: _elementCloseTag(path, name, open, inner === "", minify));
|
|
904
|
+
return svgRoot
|
|
905
|
+
? _renderEmbedded(composed, SVG_TYPE, FOREIGN_ELEMENT)
|
|
906
|
+
: composed;
|
|
907
|
+
}
|
|
908
|
+
case NodeType.Text: {
|
|
909
|
+
const data = _dataOf(path.node);
|
|
910
|
+
// Literal-text elements (`script` / `style` / …) keep their body raw;
|
|
911
|
+
// every other text node is escaped (the WHATWG text split).
|
|
912
|
+
const parent = _parentOf(path.node);
|
|
913
|
+
if (parent !== 0 && LITERAL_TEXT_PARENTS.has(_tagNameOf(parent))) {
|
|
914
|
+
const foreign = _namespaceOf(parent) !== NS_HTML;
|
|
915
|
+
const outer = _S._escapeEmbedded;
|
|
916
|
+
_S._escapeEmbedded = foreign;
|
|
917
|
+
const body = _literalTextBody(path, parent, data, minify);
|
|
918
|
+
_S._escapeEmbedded = outer;
|
|
919
|
+
// WHY: those same names in a foreign subtree hold character data
|
|
920
|
+
// rather than raw text, so the body is still the CSS or JavaScript
|
|
921
|
+
// to minify but is written back escaped — printed raw there, a `<`
|
|
922
|
+
// in it opens a tag the source never wrote, and `</style>` ends the
|
|
923
|
+
// element early.
|
|
924
|
+
// A deferred body is a placeholder here, which escaping leaves
|
|
925
|
+
// alone — its own answer is escaped as it lands.
|
|
926
|
+
return foreign ? _escapeTextContent(body, minify) : body;
|
|
927
|
+
}
|
|
928
|
+
// Whitespace directly under `<head>` or `<html>` is outside any block
|
|
929
|
+
// formatting context, so nothing ever renders it — the same inert-node
|
|
930
|
+
// reasoning that drops comments. `<body>`'s whitespace does render.
|
|
931
|
+
if (
|
|
932
|
+
minify &&
|
|
933
|
+
parent !== 0 &&
|
|
934
|
+
_namespaceOf(parent) === NS_HTML &&
|
|
935
|
+
(_tagNameOf(parent) === "head" || _tagNameOf(parent) === "html") &&
|
|
936
|
+
isAllAsciiWhitespace(data) &&
|
|
937
|
+
!_headLeftBefore(path, path.node, parent, _tagNameOf(parent))
|
|
938
|
+
) {
|
|
939
|
+
return "";
|
|
940
|
+
}
|
|
941
|
+
// A `<` puts the node on the source-passthrough path below, which is what
|
|
942
|
+
// keeps `<%= x %>` off the escaper — worth more than the whitespace.
|
|
943
|
+
if (minify && _S._collapseWhitespace !== "none" && !data.includes("<")) {
|
|
944
|
+
// Only elements rendering whitespace verbatim without any CSS are
|
|
945
|
+
// excluded — by ancestor, since `white-space` inherits.
|
|
946
|
+
let preformatted = false;
|
|
947
|
+
for (
|
|
948
|
+
let ancestor = parent;
|
|
949
|
+
ancestor !== 0;
|
|
950
|
+
ancestor = _parentOf(ancestor)
|
|
951
|
+
) {
|
|
952
|
+
if (
|
|
953
|
+
_namespaceOf(ancestor) === NS_HTML &&
|
|
954
|
+
LEADING_NEWLINE_ELEMENTS.has(_tagNameOf(ancestor))
|
|
955
|
+
) {
|
|
956
|
+
preformatted = true;
|
|
957
|
+
break;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
if (!preformatted) {
|
|
961
|
+
let collapsed = collapseWhitespaceRuns(data);
|
|
962
|
+
// Past `"conservative"`, whitespace against a boundary no line box
|
|
963
|
+
// reaches is dropped rather than kept as one space.
|
|
964
|
+
if (_S._collapseWhitespace !== "conservative") {
|
|
965
|
+
const all = _S._collapseWhitespace === "all";
|
|
966
|
+
if (all || _startsOutsideLineBox(path, path.node, parent)) {
|
|
967
|
+
collapsed = collapsed.replace(/^ /, "");
|
|
968
|
+
}
|
|
969
|
+
if (all || _endsOutsideLineBox(path, path.node, parent)) {
|
|
970
|
+
collapsed = collapsed.replace(/ $/, "");
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
if (collapsed !== data) return _escapeTextContent(collapsed, minify);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
const raw = path.source();
|
|
977
|
+
// WHY: off-spec workaround. §13.3 escapes `<` and `>` in text, which
|
|
978
|
+
// would rewrite `<%= x %>` to `<%= x %>` in HTML webpack only passes
|
|
979
|
+
// through, so text that decoded to itself is emitted as its source bytes.
|
|
980
|
+
// The guards keep that equivalence: a character reference is at least two
|
|
981
|
+
// characters longer than what it decodes to, so equal lengths mean nothing
|
|
982
|
+
// decoded, while unequal ones mean the node was merged or foster-parented
|
|
983
|
+
// and its range no longer describes `data`. The tail is checked separately
|
|
984
|
+
// as the one place concatenation can change tokenization — a `<`, or a `&`
|
|
985
|
+
// still open on a reference, fuses with the next sibling once a comment
|
|
986
|
+
// between them is dropped. A CR is the rewrite the length test cannot see,
|
|
987
|
+
// preprocessing mapping a lone one to LF, so it is excluded by name.
|
|
988
|
+
if (
|
|
989
|
+
raw.length === data.length &&
|
|
990
|
+
!_tailFusesWithNextTag(raw) &&
|
|
991
|
+
!(_S.inputHasCr && raw.includes("\r")) &&
|
|
992
|
+
!_hasOpenReference(raw)
|
|
993
|
+
) {
|
|
994
|
+
return raw;
|
|
995
|
+
}
|
|
996
|
+
return _escapeTextContent(data, minify);
|
|
997
|
+
}
|
|
998
|
+
case NodeType.Doctype: {
|
|
999
|
+
// A leaf with no children, so its source is already tight. Parsing
|
|
1000
|
+
// ASCII-lowercases the keyword and the name; the identifiers behind them
|
|
1001
|
+
// are case-sensitive strings and stay as written.
|
|
1002
|
+
const source = path.source();
|
|
1003
|
+
if (!minify) return source;
|
|
1004
|
+
const head = /^<!doctype[\t\n\f\r ]+([^\t\n\f\r >]+)/i.exec(source);
|
|
1005
|
+
return head === null
|
|
1006
|
+
? source
|
|
1007
|
+
: `<!doctype ${asciiLowercase(head[1])}${source.slice(head[0].length)}`;
|
|
1008
|
+
}
|
|
1009
|
+
case NodeType.Comment:
|
|
1010
|
+
return minify &&
|
|
1011
|
+
!_keepComment(_dataOf(path.node), path.source(), path.start())
|
|
1012
|
+
? ""
|
|
1013
|
+
: _closedCommentSource(path);
|
|
1014
|
+
case NodeType.ProcessingInstruction:
|
|
1015
|
+
// A leaf whose source is already tight, and unlike a comment it carries
|
|
1016
|
+
// instructions for a consumer, so minification never drops it.
|
|
1017
|
+
return _closedCommentSource(path);
|
|
1018
|
+
default: {
|
|
1019
|
+
// Document / DocumentFragment: concatenate children in order.
|
|
1020
|
+
if (_S._fosteredRuns !== null && _fosterTouches(path.node)) {
|
|
1021
|
+
return _composeAroundFoster(path, writer);
|
|
1022
|
+
}
|
|
1023
|
+
let out = "";
|
|
1024
|
+
for (let c = _firstChild(path.node); c !== 0; c = _nextSibling(c)) {
|
|
1025
|
+
out += writer.get(c);
|
|
1026
|
+
}
|
|
1027
|
+
return out;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
|
|
1032
|
+
module.exports.CLASSIC_SCRIPT = CLASSIC_SCRIPT;
|
|
1033
|
+
module.exports.MODULE_SCRIPT = MODULE_SCRIPT;
|
|
1034
|
+
module.exports.printer = printer;
|