webpack 5.111.0 → 5.112.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 +1 -1
- package/lib/Chunk.js +3 -966
- package/lib/Compilation.js +237 -138
- package/lib/Compiler.js +23 -24
- package/lib/Dependency.js +3 -551
- package/lib/DependencyTemplate.js +3 -69
- 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 +43 -24
- package/lib/NormalModule.js +3 -2190
- 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 +15 -9
- package/lib/asset/AssetBytesParser.js +3 -3
- package/lib/asset/AssetGenerator.js +61 -38
- 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 +15 -9
- 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 +6 -6
- package/lib/cache/MemoryWithGcCachePlugin.js +9 -10
- package/lib/cache/PackFileCacheStrategy.js +11 -28
- package/lib/cache/ResolverCachePlugin.js +8 -4
- package/lib/cache/getLazyHashedEtag.js +3 -5
- 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 +3 -9
- package/lib/{cli.js → config/cli.js} +5 -158
- package/lib/config/defaults.js +192 -122
- package/lib/config/getClaimedAssetTypes.js +28 -21
- package/lib/config/normalization.js +18 -7
- package/lib/config/target.js +13 -4
- 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/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
- package/lib/{ContextModule.js → context/ContextModule.js} +50 -36
- package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +25 -24
- package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
- package/lib/css/CssGenerator.js +57 -42
- 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 +700 -311
- package/lib/css/CssServerStylesRuntimeModule.js +3 -3
- package/lib/css/cssMinify.js +130 -54
- package/lib/css/data.js +7017 -4648
- package/lib/css/syntax-parser.js +19873 -0
- package/lib/css/syntax-printer.js +6037 -0
- package/lib/css/syntax.js +37 -17370
- package/lib/debug/ProfilingPlugin.js +55 -23
- package/lib/{DefinePlugin.js → define/DefinePlugin.js} +407 -41
- package/lib/{DotenvPlugin.js → define/DotenvPlugin.js} +25 -29
- 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} +176 -44
- 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} +39 -35
- 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} +19 -20
- 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} +34 -18
- 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} +375 -100
- package/lib/dependencies/{CssIcssImportDependency.js → css/CssIcssImportDependency.js} +26 -22
- 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} +26 -21
- 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} +40 -41
- package/lib/dependencies/{HarmonyDetectionParserPlugin.js → esm/ESMDetectionParserPlugin.js} +22 -21
- package/lib/dependencies/{HarmonyEvaluatedImportSpecifierDependency.js → esm/ESMEvaluatedImportSpecifierDependency.js} +33 -30
- package/lib/dependencies/{HarmonyExportDependencyParserPlugin.js → esm/ESMExportDependencyParserPlugin.js} +62 -93
- package/lib/dependencies/{HarmonyExportExpressionDependency.js → esm/ESMExportExpressionDependency.js} +83 -49
- 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} +136 -122
- package/lib/dependencies/{HarmonyExportInitFragment.js → esm/ESMExportInitFragment.js} +68 -43
- package/lib/dependencies/{HarmonyExportSpecifierDependency.js → esm/ESMExportSpecifierDependency.js} +68 -65
- 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} +199 -97
- package/lib/dependencies/{HarmonyImportGuard.js → esm/ESMImportGuard.js} +26 -29
- package/lib/dependencies/{HarmonyImportSideEffectDependency.js → esm/ESMImportSideEffectDependency.js} +86 -43
- package/lib/dependencies/{HarmonyImportSpecifierDependency.js → esm/ESMImportSpecifierDependency.js} +110 -61
- 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 +8 -9
- 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} +125 -243
- package/lib/dependencies/{HtmlInlineHtmlDependency.js → html/HtmlInlineHtmlDependency.js} +13 -12
- package/lib/dependencies/{HtmlInlineScriptDependency.js → html/HtmlInlineScriptDependency.js} +72 -23
- package/lib/dependencies/{HtmlInlineStyleDependency.js → html/HtmlInlineStyleDependency.js} +53 -19
- 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} +126 -107
- 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} +34 -25
- package/lib/{url → dependencies/url}/URLParserPlugin.js +22 -26
- 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} +46 -54
- package/lib/dependencies/{WorkerDependency.js → worker/WorkerDependency.js} +28 -20
- package/lib/dependencies/{WorkletDependency.js → worker/WorkletDependency.js} +25 -27
- 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} +207 -129
- 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/errors/ErrorHelpers.js +222 -0
- package/lib/errors/ExternalStarReexportError.js +2 -2
- package/lib/{library → errors}/FalseIIFEUmdWarning.js +1 -1
- package/lib/errors/HookWebpackError.js +6 -5
- 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} +85 -63
- 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} +151 -99
- package/lib/{HotUpdateChunk.js → graph/HotUpdateChunk.js} +8 -0
- package/lib/{ModuleGraph.js → graph/ModuleGraph.js} +36 -39
- package/lib/{ModuleGraphConnection.js → graph/ModuleGraphConnection.js} +2 -2
- package/lib/{buildChunkGraph.js → graph/buildChunkGraph.js} +163 -72
- package/lib/{util → graph}/findGraphRoots.js +20 -21
- package/lib/graph/isDependencyKind.js +23 -0
- package/lib/hmr/HotModuleReplacement.runtime.js +2 -2
- package/lib/{HotModuleReplacementPlugin.js → hmr/HotModuleReplacementPlugin.js} +49 -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 +34 -26
- package/lib/html/HtmlGenerator.js +168 -125
- package/lib/html/HtmlModule.js +6 -2
- package/lib/html/HtmlModulesPlugin.js +260 -215
- package/lib/html/HtmlParser.js +598 -292
- package/lib/html/builtinEmbeddedRenderer.js +60 -13
- package/lib/html/data.js +23 -1
- package/lib/html/htmlMinify.js +120 -51
- package/lib/html/syntax-parser.js +15796 -0
- package/lib/html/syntax-printer.js +1034 -0
- package/lib/html/syntax.js +37 -14062
- 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 +348 -99
- package/lib/{APIPlugin.js → javascript/APIPlugin.js} +29 -30
- 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} +10 -11
- package/lib/{ConstPlugin.js → javascript/ConstPlugin.js} +90 -139
- package/lib/{ExportsInfoApiPlugin.js → javascript/ExportsInfoApiPlugin.js} +5 -5
- package/lib/{dependencies → javascript}/ExportsInfoDependency.js +10 -9
- package/lib/javascript/JavascriptGenerator.js +25 -18
- package/lib/{JavascriptMetaInfoPlugin.js → javascript/JavascriptMetaInfoPlugin.js} +7 -7
- package/lib/javascript/JavascriptModule.js +4 -3
- package/lib/javascript/JavascriptModulesPlugin.js +458 -256
- package/lib/javascript/JavascriptParser.js +916 -287
- 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 -10946
- package/lib/json/JsonData.js +1 -1
- package/lib/{dependencies → json}/JsonExportsDependency.js +8 -7
- package/lib/json/JsonGenerator.js +17 -11
- 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 +207 -285
- 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 +27 -2
- package/lib/loaders/LoaderRunner.js +160 -22
- 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} +38 -14
- package/lib/{Module.js → module/Module.js} +122 -54
- 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 +61 -15
- 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 +5 -7
- package/lib/optimize/AggressiveSplittingPlugin.js +12 -8
- package/lib/{CircularModulesPlugin.js → optimize/CircularModulesPlugin.js} +13 -13
- package/lib/optimize/ConcatenatedModule.js +305 -309
- 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} +25 -30
- package/lib/{FlagDependencyUsagePlugin.js → optimize/FlagDependencyUsagePlugin.js} +26 -30
- package/lib/{FlagEntryExportAsUsedPlugin.js → optimize/FlagEntryExportAsUsedPlugin.js} +2 -2
- package/lib/optimize/FlagIncludedChunksPlugin.js +5 -13
- package/lib/optimize/InlineExports.js +11 -3
- package/lib/optimize/InnerGraph.js +5 -13
- package/lib/optimize/InnerGraphPlugin.js +17 -23
- package/lib/optimize/LazyBarrels.js +584 -0
- package/lib/{util → optimize}/LazyBucketSortedSet.js +2 -2
- package/lib/optimize/LimitChunkCountPlugin.js +21 -15
- package/lib/optimize/MangleExportsPlugin.js +8 -9
- package/lib/optimize/MergeDuplicateChunksPlugin.js +7 -6
- package/lib/optimize/MinChunkSizePlugin.js +9 -6
- package/lib/optimize/ModuleConcatenationPlugin.js +23 -16
- 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 +25 -37
- package/lib/optimize/SplitChunksPlugin.js +715 -159
- package/lib/{util → optimize}/TupleQueue.js +9 -9
- package/lib/optimize/chunkSetIntersections.js +437 -0
- package/lib/{util → optimize}/deterministicGrouping.js +25 -30
- 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 +5 -7
- 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 +13 -16
- 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 +7 -9
- 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 +82 -65
- package/lib/prefetch/ResourceHintRuntimeModule.js +3 -3
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +10 -13
- 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 +10 -9
- 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 +9 -10
- 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 +5 -7
- 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 +135 -102
- 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 +4 -7
- package/lib/schemes/HttpUriPlugin.js +67 -11
- package/lib/schemes/VirtualUrlPlugin.js +50 -16
- package/lib/serialization/AggregateErrorSerializer.js +2 -2
- package/lib/serialization/BinaryMiddleware.js +9 -9
- package/lib/serialization/FileMiddleware.js +19 -19
- package/lib/serialization/ObjectMiddleware.js +77 -49
- 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 +19 -19
- package/lib/sharing/utils.js +59 -2
- package/lib/stats/DefaultStatsFactoryPlugin.js +25 -23
- 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} +178 -106
- package/lib/{Template.js → template/Template.js} +13 -11
- package/lib/{TemplatedPathPlugin.js → template/TemplatedPathPlugin.js} +35 -82
- package/lib/typescript/TypeScriptPlugin.js +5 -6
- package/lib/util/LocConverter.js +4 -7
- package/lib/util/RequestShortener.js +44 -0
- package/lib/util/SortableSet.js +87 -22
- package/lib/util/SourceProcessor.js +364 -66
- 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 +32 -151
- package/lib/util/createHooksRegistry.js +1 -2
- package/lib/util/createMappings.js +111 -0
- package/lib/util/dataURL.js +96 -18
- 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/hash/wasm-hash.js +3 -4
- package/lib/util/identifier.js +117 -1
- package/lib/util/implicitTypeLoaderFallback.js +6 -4
- package/lib/util/internalSerializables.js +295 -103
- 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 +11 -6
- package/lib/{wasm-async → wasm}/AsyncWebAssemblyJavascriptGenerator.js +16 -11
- 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 +11 -12
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -3
- package/lib/wasm-sync/WebAssemblyGenerator.js +15 -9
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +19 -16
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +9 -7
- package/lib/wasm-sync/WebAssemblyParser.js +6 -6
- package/lib/wasm-sync/WebAssemblyUtils.js +8 -9
- 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 +70 -40
- 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 +13915 -8414
- package/lib/ErrorHelpers.js +0 -107
- 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 -71
- package/lib/javascript/grammar.js +0 -5546
- package/lib/javascript/parser.js +0 -1494
- 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
|
@@ -6,10 +6,9 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const { HookMap, SyncBailHook } = require("tapable");
|
|
9
|
-
const NormalModule = require("../NormalModule");
|
|
10
|
-
const Parser = require("../Parser");
|
|
11
9
|
const WebpackError = require("../WebpackError");
|
|
12
|
-
const
|
|
10
|
+
const Parser = require("../module/Parser");
|
|
11
|
+
const binarySearchBounds = require("../util/binarySearchBounds");
|
|
13
12
|
const {
|
|
14
13
|
CompilerHintNotationRegExp,
|
|
15
14
|
createMagicCommentContext,
|
|
@@ -17,16 +16,24 @@ const {
|
|
|
17
16
|
parseCommentOptionsInRange
|
|
18
17
|
} = require("../util/magicComment");
|
|
19
18
|
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|
19
|
+
const StackedMap = require("./StackedMap");
|
|
20
|
+
const { nonASCIIwhitespace } = require("./syntax-parser");
|
|
20
21
|
const {
|
|
22
|
+
BLOCK_DECLARATIONS,
|
|
23
|
+
HOISTED_DECLARATIONS,
|
|
21
24
|
LEGACY_ASSERT_ATTRIBUTES,
|
|
25
|
+
MAX_MASKED_INDEX,
|
|
26
|
+
MODULE_DECLARATIONS,
|
|
22
27
|
WebpackParser,
|
|
23
28
|
buildLineStarts,
|
|
29
|
+
declaresIntoBlock,
|
|
24
30
|
hasOctalEscape,
|
|
25
31
|
isIdentifierChar,
|
|
32
|
+
overflowFrom,
|
|
26
33
|
positionAt
|
|
27
|
-
} = require("./syntax");
|
|
34
|
+
} = require("./syntax-parser");
|
|
28
35
|
|
|
29
|
-
/** @import { EcmaVersion, ParserOptions, ParserPlugin } from "./syntax" */
|
|
36
|
+
/** @import { EcmaVersion, ParserOptions, ParserPlugin } from "./syntax-parser" */
|
|
30
37
|
/**
|
|
31
38
|
* @import {
|
|
32
39
|
* AssignmentExpression,
|
|
@@ -101,42 +108,50 @@ const {
|
|
|
101
108
|
* MaybeNamedClassDeclaration
|
|
102
109
|
* } from "estree"
|
|
103
110
|
*/
|
|
104
|
-
/** @import { DependencyLocation } from "../Dependency" */
|
|
111
|
+
/** @import { DependencyLocation } from "../graph/Dependency" */
|
|
112
|
+
/** @import { MagicCommentOptions } from "../util/magicComment" */
|
|
105
113
|
/** @typedef {import("estree").Comment & { start: number, end: number, loc?: SourceLocation | null }} Comment */
|
|
106
114
|
/**
|
|
107
115
|
* Defines the shared type used by this module.
|
|
108
116
|
* @template T
|
|
109
117
|
* @typedef {import("tapable").AsArray<T>} AsArray<T>
|
|
110
118
|
*/
|
|
111
|
-
/** @import { ParserState, PreparsedAst } from "../Parser" */
|
|
119
|
+
/** @import { ParserState, PreparsedAst } from "../module/Parser" */
|
|
112
120
|
|
|
113
|
-
/** @import LocalModule from "../dependencies/LocalModule" */
|
|
121
|
+
/** @import LocalModule from "../dependencies/amd/LocalModule" */
|
|
114
122
|
/**
|
|
115
123
|
* @import {
|
|
116
|
-
*
|
|
117
|
-
* } from "../dependencies/
|
|
124
|
+
* ESMStarExportsList
|
|
125
|
+
* } from "../dependencies/esm/ESMExportImportedSpecifierDependency"
|
|
118
126
|
*/
|
|
119
127
|
|
|
120
128
|
/**
|
|
121
129
|
* Defines the known javascript parser state type used by this module.
|
|
130
|
+
* The `harmony*` properties forward to their `esm*` namesake.
|
|
122
131
|
* @typedef {object} KnownJavascriptParserState
|
|
123
|
-
* @property {Set<string>=}
|
|
124
|
-
* @property {InstanceType<
|
|
125
|
-
* @property {number=}
|
|
132
|
+
* @property {Set<string>=} esmNamedExports
|
|
133
|
+
* @property {InstanceType<ESMStarExportsList>=} esmStarExports
|
|
134
|
+
* @property {number=} lastESMImportOrder
|
|
126
135
|
* @property {LocalModule[]=} localModules
|
|
136
|
+
* @property {Set<string>=} harmonyNamedExports deprecated, use `esmNamedExports`
|
|
137
|
+
* @property {InstanceType<ESMStarExportsList>=} harmonyStarExports deprecated, use `esmStarExports`
|
|
138
|
+
* @property {number=} lastHarmonyImportOrder deprecated, use `lastESMImportOrder`
|
|
127
139
|
*/
|
|
128
140
|
|
|
129
141
|
/** @typedef {ParserState & KnownJavascriptParserState} JavascriptParserState */
|
|
130
142
|
|
|
131
143
|
/** @import Compilation from "../Compilation" */
|
|
132
|
-
/** @import Module from "../Module" */
|
|
144
|
+
/** @import Module from "../module/Module" */
|
|
133
145
|
|
|
134
146
|
/** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => Members, getMembersOptionals: () => MembersOptionals, getMemberRanges: () => MemberRanges }} GetInfoResult */
|
|
135
|
-
/** @typedef {{ consequent?:
|
|
147
|
+
/** @typedef {{ consequent?: GuardFrame, alternate?: GuardFrame }} GuardCollection per-branch guard frames pushed onto the parser state guard stack */
|
|
136
148
|
/** @typedef {Statement | ModuleDeclaration | Expression | MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration} StatementPathItem */
|
|
137
149
|
/** @typedef {(ident: string) => void} OnIdentString */
|
|
138
150
|
/** @typedef {(ident: string, identifier: Identifier) => void} OnIdent */
|
|
139
151
|
/** @typedef {StatementPathItem[]} StatementPath */
|
|
152
|
+
/** @typedef {(Statement | ModuleDeclaration)[]} HoistedDeclarations the declarations one scope hoists, in source order */
|
|
153
|
+
/** @typedef {(ModuleDeclaration | Statement | undefined)[]} ModuleDeclarations the program's import and re-export declarations in source order, each followed by the statement written before it */
|
|
154
|
+
/** @typedef {number | number[]} BlockDeclarations which statements of one list declare into its block scope: a mask of their indices, or the indices themselves once one is too large to mask */
|
|
140
155
|
|
|
141
156
|
/** @typedef {Set<DestructuringAssignmentProperty>} DestructuringAssignmentProperties */
|
|
142
157
|
|
|
@@ -145,6 +160,32 @@ const {
|
|
|
145
160
|
|
|
146
161
|
/** @type {string[]} */
|
|
147
162
|
const EMPTY_ARRAY = [];
|
|
163
|
+
/** @type {HoistedDeclarations} */
|
|
164
|
+
const EMPTY_HOISTED_DECLARATIONS = [];
|
|
165
|
+
// what the module pass reports; `export default` is the block pass's
|
|
166
|
+
const MODULE_STATEMENT_TYPES = new Set([
|
|
167
|
+
"ImportDeclaration",
|
|
168
|
+
"ExportNamedDeclaration",
|
|
169
|
+
"ExportAllDeclaration"
|
|
170
|
+
]);
|
|
171
|
+
// what the parser records per scope, and so what the hoisting pass reaches
|
|
172
|
+
const RECORDED_STATEMENT_TYPES = new Set([
|
|
173
|
+
"VariableDeclaration",
|
|
174
|
+
"FunctionDeclaration",
|
|
175
|
+
"ClassDeclaration"
|
|
176
|
+
]);
|
|
177
|
+
/** @type {ModuleDeclarations} */
|
|
178
|
+
const EMPTY_MODULE_DECLARATIONS = [];
|
|
179
|
+
// what the parser records per statement list, and so what the block pass
|
|
180
|
+
// reaches. An expression statement is recorded only when it assigns to an
|
|
181
|
+
// object pattern, so a tap on that type is not served from the list.
|
|
182
|
+
const BLOCK_DECLARATION_TYPES = new Set([
|
|
183
|
+
"VariableDeclaration",
|
|
184
|
+
"ClassDeclaration",
|
|
185
|
+
"ExportNamedDeclaration",
|
|
186
|
+
"ExportDefaultDeclaration"
|
|
187
|
+
]);
|
|
188
|
+
|
|
148
189
|
/** @type {MembersOptionals} */
|
|
149
190
|
const EMPTY_MEMBERS_OPTIONALS = [];
|
|
150
191
|
|
|
@@ -237,7 +278,10 @@ const getImportAttributes = (node) => {
|
|
|
237
278
|
result[key] = /** @type {string} */ (attribute.value.value);
|
|
238
279
|
}
|
|
239
280
|
|
|
240
|
-
if (
|
|
281
|
+
if (
|
|
282
|
+
/** @type {typeof node.attributes & { [LEGACY_ASSERT_ATTRIBUTES]?: boolean }} */
|
|
283
|
+
(node.attributes)[LEGACY_ASSERT_ATTRIBUTES]
|
|
284
|
+
) {
|
|
241
285
|
result._isLegacyAssert = true;
|
|
242
286
|
}
|
|
243
287
|
|
|
@@ -329,19 +373,20 @@ class VariableInfo {
|
|
|
329
373
|
|
|
330
374
|
/**
|
|
331
375
|
* @import {
|
|
332
|
-
*
|
|
333
|
-
* } from "../dependencies/
|
|
376
|
+
* ESMSettings
|
|
377
|
+
* } from "../dependencies/esm/ESMImportDependencyParserPlugin"
|
|
334
378
|
*/
|
|
335
|
-
/** @import { ImportSettings } from "../dependencies/ImportParserPlugin" */
|
|
379
|
+
/** @import { ImportSettings } from "../dependencies/import/ImportParserPlugin" */
|
|
380
|
+
/** @import { GuardFrame } from "../dependencies/esm/ESMImportGuard" */
|
|
336
381
|
/**
|
|
337
382
|
* @import {
|
|
338
383
|
* CommonJsImportSettings
|
|
339
|
-
* } from "../dependencies/CommonJsImportsParserPlugin"
|
|
384
|
+
* } from "../dependencies/commonjs/CommonJsImportsParserPlugin"
|
|
340
385
|
*/
|
|
341
|
-
/** @import { CompatibilitySettings } from "
|
|
386
|
+
/** @import { CompatibilitySettings } from "./CompatibilityPlugin" */
|
|
342
387
|
/** @import { TopLevelSymbol } from "../optimize/InnerGraph" */
|
|
343
388
|
|
|
344
|
-
/** @typedef {
|
|
389
|
+
/** @typedef {ESMSettings | ImportSettings | CommonJsImportSettings | TopLevelSymbol | CompatibilitySettings} KnownTagData */
|
|
345
390
|
/** @typedef {KnownTagData | Record<string, EXPECTED_ANY>} TagData */
|
|
346
391
|
|
|
347
392
|
/**
|
|
@@ -354,6 +399,7 @@ class VariableInfo {
|
|
|
354
399
|
|
|
355
400
|
/** @typedef {string[]} CalleeMembers */
|
|
356
401
|
/** @typedef {string[]} Members */
|
|
402
|
+
/** @typedef {UpdateExpression | ForInStatement | ForOfStatement | AssignmentExpression} WriteStatement a construct that writes to the reference it carries */
|
|
357
403
|
/** @typedef {boolean[]} MembersOptionals */
|
|
358
404
|
/** @typedef {Range[]} MemberRanges */
|
|
359
405
|
|
|
@@ -517,123 +563,138 @@ const valueAsExpression = (value, expr, sideEffects) => {
|
|
|
517
563
|
};
|
|
518
564
|
|
|
519
565
|
// The constant operators, shared so evaluating `a - b` allocates no handler.
|
|
566
|
+
// JavaScript coerces any operand; each cast only lets TypeScript type the operator.
|
|
567
|
+
|
|
568
|
+
/** @typedef {ReturnType<BasicEvaluatedExpression["asCompileTimeValue"]>} CompileTimeValue */
|
|
520
569
|
|
|
521
570
|
/**
|
|
522
|
-
* @param {
|
|
523
|
-
* @param {
|
|
524
|
-
* @returns {
|
|
571
|
+
* @param {CompileTimeValue} l left operand
|
|
572
|
+
* @param {CompileTimeValue} r right operand
|
|
573
|
+
* @returns {number | bigint} the result
|
|
525
574
|
*/
|
|
526
|
-
const SUBTRACT = (l, r) =>
|
|
575
|
+
const SUBTRACT = (l, r) =>
|
|
576
|
+
/** @type {number} */ (l) - /** @type {number} */ (r);
|
|
527
577
|
|
|
528
578
|
/**
|
|
529
|
-
* @param {
|
|
530
|
-
* @param {
|
|
531
|
-
* @returns {
|
|
579
|
+
* @param {CompileTimeValue} l left operand
|
|
580
|
+
* @param {CompileTimeValue} r right operand
|
|
581
|
+
* @returns {number | bigint} the result
|
|
532
582
|
*/
|
|
533
|
-
const MULTIPLY = (l, r) =>
|
|
583
|
+
const MULTIPLY = (l, r) =>
|
|
584
|
+
/** @type {number} */ (l) * /** @type {number} */ (r);
|
|
534
585
|
|
|
535
586
|
/**
|
|
536
|
-
* @param {
|
|
537
|
-
* @param {
|
|
538
|
-
* @returns {
|
|
587
|
+
* @param {CompileTimeValue} l left operand
|
|
588
|
+
* @param {CompileTimeValue} r right operand
|
|
589
|
+
* @returns {number | bigint} the result
|
|
539
590
|
*/
|
|
540
|
-
const DIVIDE = (l, r) => l / r;
|
|
591
|
+
const DIVIDE = (l, r) => /** @type {number} */ (l) / /** @type {number} */ (r);
|
|
541
592
|
|
|
542
593
|
/**
|
|
543
|
-
* @param {
|
|
544
|
-
* @param {
|
|
545
|
-
* @returns {
|
|
594
|
+
* @param {CompileTimeValue} l left operand
|
|
595
|
+
* @param {CompileTimeValue} r right operand
|
|
596
|
+
* @returns {number | bigint} the result
|
|
546
597
|
*/
|
|
547
|
-
const POWER = (l, r) => l ** r;
|
|
598
|
+
const POWER = (l, r) => /** @type {number} */ (l) ** /** @type {number} */ (r);
|
|
548
599
|
|
|
549
600
|
/**
|
|
550
|
-
* @param {
|
|
551
|
-
* @param {
|
|
552
|
-
* @returns {
|
|
601
|
+
* @param {CompileTimeValue} l left operand
|
|
602
|
+
* @param {CompileTimeValue} r right operand
|
|
603
|
+
* @returns {number | bigint} the result
|
|
553
604
|
*/
|
|
554
|
-
const BITWISE_AND = (l, r) =>
|
|
605
|
+
const BITWISE_AND = (l, r) =>
|
|
606
|
+
/** @type {number} */ (l) & /** @type {number} */ (r);
|
|
555
607
|
|
|
556
608
|
/**
|
|
557
|
-
* @param {
|
|
558
|
-
* @param {
|
|
559
|
-
* @returns {
|
|
609
|
+
* @param {CompileTimeValue} l left operand
|
|
610
|
+
* @param {CompileTimeValue} r right operand
|
|
611
|
+
* @returns {number | bigint} the result
|
|
560
612
|
*/
|
|
561
|
-
const BITWISE_OR = (l, r) =>
|
|
613
|
+
const BITWISE_OR = (l, r) =>
|
|
614
|
+
/** @type {number} */ (l) | /** @type {number} */ (r);
|
|
562
615
|
|
|
563
616
|
/**
|
|
564
|
-
* @param {
|
|
565
|
-
* @param {
|
|
566
|
-
* @returns {
|
|
617
|
+
* @param {CompileTimeValue} l left operand
|
|
618
|
+
* @param {CompileTimeValue} r right operand
|
|
619
|
+
* @returns {number | bigint} the result
|
|
567
620
|
*/
|
|
568
|
-
const BITWISE_XOR = (l, r) =>
|
|
621
|
+
const BITWISE_XOR = (l, r) =>
|
|
622
|
+
/** @type {number} */ (l) ^ /** @type {number} */ (r);
|
|
569
623
|
|
|
570
624
|
/**
|
|
571
|
-
* @param {
|
|
572
|
-
* @param {
|
|
573
|
-
* @returns {
|
|
625
|
+
* @param {CompileTimeValue} l left operand
|
|
626
|
+
* @param {CompileTimeValue} r right operand
|
|
627
|
+
* @returns {number} the result
|
|
574
628
|
*/
|
|
575
|
-
const UNSIGNED_SHIFT_RIGHT = (l, r) =>
|
|
629
|
+
const UNSIGNED_SHIFT_RIGHT = (l, r) =>
|
|
630
|
+
/** @type {number} */ (l) >>> /** @type {number} */ (r);
|
|
576
631
|
|
|
577
632
|
/**
|
|
578
|
-
* @param {
|
|
579
|
-
* @param {
|
|
580
|
-
* @returns {
|
|
633
|
+
* @param {CompileTimeValue} l left operand
|
|
634
|
+
* @param {CompileTimeValue} r right operand
|
|
635
|
+
* @returns {number | bigint} the result
|
|
581
636
|
*/
|
|
582
|
-
const SHIFT_RIGHT = (l, r) =>
|
|
637
|
+
const SHIFT_RIGHT = (l, r) =>
|
|
638
|
+
/** @type {number} */ (l) >> /** @type {number} */ (r);
|
|
583
639
|
|
|
584
640
|
/**
|
|
585
|
-
* @param {
|
|
586
|
-
* @param {
|
|
587
|
-
* @returns {
|
|
641
|
+
* @param {CompileTimeValue} l left operand
|
|
642
|
+
* @param {CompileTimeValue} r right operand
|
|
643
|
+
* @returns {number | bigint} the result
|
|
588
644
|
*/
|
|
589
|
-
const SHIFT_LEFT = (l, r) =>
|
|
645
|
+
const SHIFT_LEFT = (l, r) =>
|
|
646
|
+
/** @type {number} */ (l) << /** @type {number} */ (r);
|
|
590
647
|
|
|
591
648
|
/**
|
|
592
|
-
* @param {
|
|
593
|
-
* @param {
|
|
594
|
-
* @returns {
|
|
649
|
+
* @param {CompileTimeValue} l left operand
|
|
650
|
+
* @param {CompileTimeValue} r right operand
|
|
651
|
+
* @returns {boolean} the result
|
|
595
652
|
*/
|
|
596
|
-
const LESS_THAN = (l, r) =>
|
|
653
|
+
const LESS_THAN = (l, r) =>
|
|
654
|
+
/** @type {number} */ (l) < /** @type {number} */ (r);
|
|
597
655
|
|
|
598
656
|
/**
|
|
599
|
-
* @param {
|
|
600
|
-
* @param {
|
|
601
|
-
* @returns {
|
|
657
|
+
* @param {CompileTimeValue} l left operand
|
|
658
|
+
* @param {CompileTimeValue} r right operand
|
|
659
|
+
* @returns {boolean} the result
|
|
602
660
|
*/
|
|
603
|
-
const GREATER_THAN = (l, r) =>
|
|
661
|
+
const GREATER_THAN = (l, r) =>
|
|
662
|
+
/** @type {number} */ (l) > /** @type {number} */ (r);
|
|
604
663
|
|
|
605
664
|
/**
|
|
606
|
-
* @param {
|
|
607
|
-
* @param {
|
|
608
|
-
* @returns {
|
|
665
|
+
* @param {CompileTimeValue} l left operand
|
|
666
|
+
* @param {CompileTimeValue} r right operand
|
|
667
|
+
* @returns {boolean} the result
|
|
609
668
|
*/
|
|
610
|
-
const LESS_THAN_OR_EQUAL = (l, r) =>
|
|
669
|
+
const LESS_THAN_OR_EQUAL = (l, r) =>
|
|
670
|
+
/** @type {number} */ (l) <= /** @type {number} */ (r);
|
|
611
671
|
|
|
612
672
|
/**
|
|
613
|
-
* @param {
|
|
614
|
-
* @param {
|
|
615
|
-
* @returns {
|
|
673
|
+
* @param {CompileTimeValue} l left operand
|
|
674
|
+
* @param {CompileTimeValue} r right operand
|
|
675
|
+
* @returns {boolean} the result
|
|
616
676
|
*/
|
|
617
|
-
const GREATER_THAN_OR_EQUAL = (l, r) =>
|
|
677
|
+
const GREATER_THAN_OR_EQUAL = (l, r) =>
|
|
678
|
+
/** @type {number} */ (l) >= /** @type {number} */ (r);
|
|
618
679
|
|
|
619
680
|
/**
|
|
620
|
-
* @param {
|
|
621
|
-
* @returns {
|
|
681
|
+
* @param {CompileTimeValue} v operand
|
|
682
|
+
* @returns {number | bigint} the result
|
|
622
683
|
*/
|
|
623
|
-
const BITWISE_NOT = (v) => ~v;
|
|
684
|
+
const BITWISE_NOT = (v) => ~(/** @type {number} */ (v));
|
|
624
685
|
|
|
625
686
|
/**
|
|
626
|
-
* @param {
|
|
627
|
-
* @returns {
|
|
687
|
+
* @param {CompileTimeValue} v operand
|
|
688
|
+
* @returns {number} the result
|
|
628
689
|
*/
|
|
629
690
|
// eslint-disable-next-line no-implicit-coercion
|
|
630
|
-
const TO_NUMBER = (v) => +v;
|
|
691
|
+
const TO_NUMBER = (v) => +(/** @type {number} */ (v));
|
|
631
692
|
|
|
632
693
|
/**
|
|
633
|
-
* @param {
|
|
634
|
-
* @returns {
|
|
694
|
+
* @param {CompileTimeValue} v operand
|
|
695
|
+
* @returns {number | bigint} the result
|
|
635
696
|
*/
|
|
636
|
-
const NEGATE = (v) => -v;
|
|
697
|
+
const NEGATE = (v) => -(/** @type {number} */ (v));
|
|
637
698
|
|
|
638
699
|
/**
|
|
639
700
|
* Evaluates a binary expression if and only if it is a const operation (e.g. 1 + 2, "a" + "b", etc.).
|
|
@@ -922,6 +983,195 @@ const evaluateAstCaches = new WeakMap();
|
|
|
922
983
|
// The inner map is strong while the compilation lives, so cap it
|
|
923
984
|
const EVALUATE_AST_CACHE_LIMIT = 4096;
|
|
924
985
|
|
|
986
|
+
/**
|
|
987
|
+
* Add one declaration, starting the list at the first — most scopes declare
|
|
988
|
+
* nothing, and the shared empty list spares them an array.
|
|
989
|
+
* @param {HoistedDeclarations} hoisted the list so far
|
|
990
|
+
* @param {Statement | ModuleDeclaration} declaration what to add
|
|
991
|
+
* @returns {HoistedDeclarations} the list holding it
|
|
992
|
+
*/
|
|
993
|
+
const addHoistedDeclaration = (hoisted, declaration) => {
|
|
994
|
+
if (hoisted === EMPTY_HOISTED_DECLARATIONS) return [declaration];
|
|
995
|
+
hoisted.push(declaration);
|
|
996
|
+
return hoisted;
|
|
997
|
+
};
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* Collect the declarations that hoist to one scope, for an AST that did not
|
|
1001
|
+
* come from webpack's parser and so carries no record of its own.
|
|
1002
|
+
* @param {(Statement | ModuleDeclaration)[]} statements the scope's statements
|
|
1003
|
+
* @param {HoistedDeclarations} hoisted the list so far
|
|
1004
|
+
* @returns {HoistedDeclarations} the list holding what they declare
|
|
1005
|
+
*/
|
|
1006
|
+
const collectHoistedDeclarations = (statements, hoisted) => {
|
|
1007
|
+
for (let index = 0, len = statements.length; index < len; index++) {
|
|
1008
|
+
hoisted = collectHoistedDeclaration(statements[index], hoisted);
|
|
1009
|
+
}
|
|
1010
|
+
return hoisted;
|
|
1011
|
+
};
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* Collect from one statement, descending exactly as far as a `var` reaches:
|
|
1015
|
+
* through blocks and loop bodies, never into another function.
|
|
1016
|
+
* @param {Statement | ModuleDeclaration} statement the statement
|
|
1017
|
+
* @param {HoistedDeclarations} hoisted the list so far
|
|
1018
|
+
* @returns {HoistedDeclarations} the list holding what it declares
|
|
1019
|
+
*/
|
|
1020
|
+
const collectHoistedDeclaration = (statement, hoisted) => {
|
|
1021
|
+
switch (statement.type) {
|
|
1022
|
+
case "VariableDeclaration":
|
|
1023
|
+
if (statement.kind === "var") {
|
|
1024
|
+
hoisted = addHoistedDeclaration(hoisted, statement);
|
|
1025
|
+
}
|
|
1026
|
+
break;
|
|
1027
|
+
case "FunctionDeclaration":
|
|
1028
|
+
case "ClassDeclaration":
|
|
1029
|
+
hoisted = addHoistedDeclaration(hoisted, statement);
|
|
1030
|
+
break;
|
|
1031
|
+
case "BlockStatement":
|
|
1032
|
+
hoisted = collectHoistedDeclarations(statement.body, hoisted);
|
|
1033
|
+
break;
|
|
1034
|
+
case "IfStatement":
|
|
1035
|
+
hoisted = collectHoistedDeclaration(statement.consequent, hoisted);
|
|
1036
|
+
if (statement.alternate) {
|
|
1037
|
+
hoisted = collectHoistedDeclaration(statement.alternate, hoisted);
|
|
1038
|
+
}
|
|
1039
|
+
break;
|
|
1040
|
+
case "ForStatement":
|
|
1041
|
+
if (statement.init && statement.init.type === "VariableDeclaration") {
|
|
1042
|
+
hoisted = collectHoistedDeclaration(statement.init, hoisted);
|
|
1043
|
+
}
|
|
1044
|
+
hoisted = collectHoistedDeclaration(statement.body, hoisted);
|
|
1045
|
+
break;
|
|
1046
|
+
case "ForInStatement":
|
|
1047
|
+
case "ForOfStatement":
|
|
1048
|
+
if (statement.left.type === "VariableDeclaration") {
|
|
1049
|
+
hoisted = collectHoistedDeclaration(statement.left, hoisted);
|
|
1050
|
+
}
|
|
1051
|
+
hoisted = collectHoistedDeclaration(statement.body, hoisted);
|
|
1052
|
+
break;
|
|
1053
|
+
case "WhileStatement":
|
|
1054
|
+
case "DoWhileStatement":
|
|
1055
|
+
case "LabeledStatement":
|
|
1056
|
+
case "WithStatement":
|
|
1057
|
+
hoisted = collectHoistedDeclaration(statement.body, hoisted);
|
|
1058
|
+
break;
|
|
1059
|
+
case "TryStatement":
|
|
1060
|
+
hoisted = collectHoistedDeclaration(statement.block, hoisted);
|
|
1061
|
+
if (statement.handler) {
|
|
1062
|
+
hoisted = collectHoistedDeclaration(statement.handler.body, hoisted);
|
|
1063
|
+
}
|
|
1064
|
+
if (statement.finalizer) {
|
|
1065
|
+
hoisted = collectHoistedDeclaration(statement.finalizer, hoisted);
|
|
1066
|
+
}
|
|
1067
|
+
break;
|
|
1068
|
+
case "SwitchStatement": {
|
|
1069
|
+
const cases = statement.cases;
|
|
1070
|
+
for (let index = 0, len = cases.length; index < len; index++) {
|
|
1071
|
+
hoisted = collectHoistedDeclarations(cases[index].consequent, hoisted);
|
|
1072
|
+
}
|
|
1073
|
+
break;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
return hoisted;
|
|
1077
|
+
};
|
|
1078
|
+
|
|
1079
|
+
/**
|
|
1080
|
+
* What the program imports and re-exports: the parser's own record, or a scan
|
|
1081
|
+
* of the top-level statements for an AST some other parser built.
|
|
1082
|
+
* @param {Program} ast the program
|
|
1083
|
+
* @param {boolean} trusted whether the parser's own record may be read
|
|
1084
|
+
* @returns {ModuleDeclarations} the declarations, in source order
|
|
1085
|
+
*/
|
|
1086
|
+
const moduleDeclarationsOf = (ast, trusted) => {
|
|
1087
|
+
if (trusted) {
|
|
1088
|
+
const recorded =
|
|
1089
|
+
/** @type {Program & { [MODULE_DECLARATIONS]?: ModuleDeclarations }} */
|
|
1090
|
+
(ast)[MODULE_DECLARATIONS];
|
|
1091
|
+
if (recorded !== undefined) return recorded;
|
|
1092
|
+
}
|
|
1093
|
+
/** @type {ModuleDeclarations} */
|
|
1094
|
+
let declarations = EMPTY_MODULE_DECLARATIONS;
|
|
1095
|
+
const body = ast.body;
|
|
1096
|
+
for (let index = 0, len = body.length; index < len; index++) {
|
|
1097
|
+
const statement = body[index];
|
|
1098
|
+
if (MODULE_STATEMENT_TYPES.has(statement.type)) {
|
|
1099
|
+
if (declarations === EMPTY_MODULE_DECLARATIONS) declarations = [];
|
|
1100
|
+
declarations.push(statement, index === 0 ? undefined : body[index - 1]);
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
return declarations;
|
|
1104
|
+
};
|
|
1105
|
+
|
|
1106
|
+
/**
|
|
1107
|
+
* What hoists to the scope the node opens: the parser's own record, or a walk
|
|
1108
|
+
* of the body for an AST some other parser built.
|
|
1109
|
+
* @param {Program | BlockStatement} node the node owning the scope
|
|
1110
|
+
* @param {boolean} trusted whether the parser's own record may be read
|
|
1111
|
+
* @returns {HoistedDeclarations} the declarations, in source order
|
|
1112
|
+
*/
|
|
1113
|
+
const hoistedDeclarationsOf = (node, trusted) => {
|
|
1114
|
+
if (trusted) {
|
|
1115
|
+
const recorded =
|
|
1116
|
+
/** @type {(Program | BlockStatement) & { [HOISTED_DECLARATIONS]?: HoistedDeclarations }} */
|
|
1117
|
+
(node)[HOISTED_DECLARATIONS];
|
|
1118
|
+
if (recorded !== undefined) return recorded;
|
|
1119
|
+
}
|
|
1120
|
+
return collectHoistedDeclarations(node.body, EMPTY_HOISTED_DECLARATIONS);
|
|
1121
|
+
};
|
|
1122
|
+
|
|
1123
|
+
/**
|
|
1124
|
+
* Which statements of a list declare into its block scope, scanned for an AST
|
|
1125
|
+
* some other parser built. The parser's own record is read instead when there
|
|
1126
|
+
* is one.
|
|
1127
|
+
* @param {(Statement | ModuleDeclaration)[]} statements the list
|
|
1128
|
+
* @returns {BlockDeclarations} their indices, in source order
|
|
1129
|
+
*/
|
|
1130
|
+
const collectBlockDeclarations = (statements) => {
|
|
1131
|
+
let mask = 0;
|
|
1132
|
+
/** @type {number[] | undefined} */
|
|
1133
|
+
let overflow;
|
|
1134
|
+
for (let index = 0, len = statements.length; index < len; index++) {
|
|
1135
|
+
if (!declaresIntoBlock(statements[index])) continue;
|
|
1136
|
+
if (overflow !== undefined) overflow.push(index);
|
|
1137
|
+
else if (index <= MAX_MASKED_INDEX) mask |= 1 << index;
|
|
1138
|
+
else overflow = overflowFrom(mask, index);
|
|
1139
|
+
}
|
|
1140
|
+
return overflow === undefined ? mask : overflow;
|
|
1141
|
+
};
|
|
1142
|
+
|
|
1143
|
+
/**
|
|
1144
|
+
* @param {Comment} comment comment to compare
|
|
1145
|
+
* @param {number} position source offset
|
|
1146
|
+
* @returns {number} comparison of the comment end with the offset
|
|
1147
|
+
*/
|
|
1148
|
+
const compareCommentEnd = (comment, position) =>
|
|
1149
|
+
/** @type {Range} */ (comment.range)[1] - position;
|
|
1150
|
+
|
|
1151
|
+
/**
|
|
1152
|
+
* Whether the source between two offsets is whitespace only.
|
|
1153
|
+
* @param {string} source the module source
|
|
1154
|
+
* @param {number} start where to start
|
|
1155
|
+
* @param {number} end where to stop
|
|
1156
|
+
* @returns {boolean} whether nothing but whitespace lies between them
|
|
1157
|
+
*/
|
|
1158
|
+
const onlyWhitespaceBetween = (source, start, end) => {
|
|
1159
|
+
for (let index = start; index < end; index++) {
|
|
1160
|
+
const code = source.charCodeAt(index);
|
|
1161
|
+
// the classification `skipSpace` uses: anything else is a token, and a
|
|
1162
|
+
// token means the run of comments before the statement has ended
|
|
1163
|
+
if (
|
|
1164
|
+
code !== 32 &&
|
|
1165
|
+
code !== 160 &&
|
|
1166
|
+
!(code > 8 && code < 14) &&
|
|
1167
|
+
!(code >= 5760 && nonASCIIwhitespace.test(source[index]))
|
|
1168
|
+
) {
|
|
1169
|
+
return false;
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
return true;
|
|
1173
|
+
};
|
|
1174
|
+
|
|
925
1175
|
const CLASS_NAME = "JavascriptParser";
|
|
926
1176
|
|
|
927
1177
|
// Reserved words in strict mode, so unusable as binding names there (12.7.2).
|
|
@@ -984,17 +1234,33 @@ class JavascriptParser extends Parser {
|
|
|
984
1234
|
isPure: new HookMap(
|
|
985
1235
|
() => new SyncBailHook(["expression", "commentsStartPosition"])
|
|
986
1236
|
),
|
|
987
|
-
/**
|
|
1237
|
+
/**
|
|
1238
|
+
* Every statement the hoisting pass reads, which a tap on this turns
|
|
1239
|
+
* back into a walk of them all. Tap `preStatementByType` instead.
|
|
1240
|
+
* @type {SyncBailHook<[Statement | ModuleDeclaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration], boolean | void>}
|
|
1241
|
+
* @deprecated TODO in the next major release: remove, with the statement walk it turns on
|
|
1242
|
+
*/
|
|
988
1243
|
preStatement: new SyncBailHook(["statement"]),
|
|
989
1244
|
/**
|
|
1245
|
+
* Each declaration the parser records: a variable, function or class
|
|
1246
|
+
* one. Any other type turns the pass back into a walk of every
|
|
1247
|
+
* statement, and goes away with that walk in the next major release.
|
|
990
1248
|
* @type {HookMap<SyncBailHook<[Statement | ModuleDeclaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration], boolean | void>>}
|
|
991
1249
|
* @since 5.109.0
|
|
992
1250
|
*/
|
|
993
1251
|
preStatementByType: new HookMap(() => new SyncBailHook(["statement"])),
|
|
994
1252
|
|
|
995
|
-
/**
|
|
1253
|
+
/**
|
|
1254
|
+
* Every statement the block pass reads, which a tap on this turns back
|
|
1255
|
+
* into a walk of them all. Tap `blockPreStatementByType` instead.
|
|
1256
|
+
* @type {SyncBailHook<[Statement | ModuleDeclaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration], boolean | void>}
|
|
1257
|
+
* @deprecated TODO in the next major release: remove, with the statement walk it turns on
|
|
1258
|
+
*/
|
|
996
1259
|
blockPreStatement: new SyncBailHook(["declaration"]),
|
|
997
1260
|
/**
|
|
1261
|
+
* Each statement the parser records for the block pass: a variable, class
|
|
1262
|
+
* or export declaration. Any other type turns the pass back into a walk
|
|
1263
|
+
* of every statement, and goes away with that walk in the next major release.
|
|
998
1264
|
* @type {HookMap<SyncBailHook<[Statement | ModuleDeclaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration], boolean | void>>}
|
|
999
1265
|
* @since 5.109.0
|
|
1000
1266
|
*/
|
|
@@ -1092,6 +1358,12 @@ class JavascriptParser extends Parser {
|
|
|
1092
1358
|
rename: new HookMap(() => new SyncBailHook(["initExpression"])),
|
|
1093
1359
|
/** @type {HookMap<SyncBailHook<[AssignmentExpression], boolean | void>>} */
|
|
1094
1360
|
assign: new HookMap(() => new SyncBailHook(["expression"])),
|
|
1361
|
+
/** @type {HookMap<SyncBailHook<[WriteStatement], boolean | void>>} */
|
|
1362
|
+
write: new HookMap(() => new SyncBailHook(["node"])),
|
|
1363
|
+
/** @type {HookMap<SyncBailHook<[WriteStatement, Members], boolean | void>>} */
|
|
1364
|
+
writeMemberChain: new HookMap(
|
|
1365
|
+
() => new SyncBailHook(["node", "members"])
|
|
1366
|
+
),
|
|
1095
1367
|
/** @type {HookMap<SyncBailHook<[AssignmentExpression, Members], boolean | void>>} */
|
|
1096
1368
|
assignMemberChain: new HookMap(
|
|
1097
1369
|
() => new SyncBailHook(["expression", "members"])
|
|
@@ -1201,6 +1473,37 @@ class JavascriptParser extends Parser {
|
|
|
1201
1473
|
this.statementPath = undefined;
|
|
1202
1474
|
/** @type {Statement | ModuleDeclaration | Expression | MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration | undefined} */
|
|
1203
1475
|
this.prevStatement = undefined;
|
|
1476
|
+
/** @type {boolean} */
|
|
1477
|
+
this._hasParserRecord = false;
|
|
1478
|
+
// BACKWARD-COMPAT START
|
|
1479
|
+
|
|
1480
|
+
// WHY: the hoisting pass reaches declarations alone, so a tap that
|
|
1481
|
+
// expects every statement would quietly stop seeing most of them. Such a
|
|
1482
|
+
// tap turns the pass back into the walk it used to be, which no build
|
|
1483
|
+
// webpack's own plugins drive ever asks for.
|
|
1484
|
+
/** @type {boolean} */
|
|
1485
|
+
this._needsFullPreWalk = false;
|
|
1486
|
+
this.hooks.preStatementByType.intercept({
|
|
1487
|
+
factory: (type, hook) => {
|
|
1488
|
+
if (!RECORDED_STATEMENT_TYPES.has(type)) {
|
|
1489
|
+
this._needsFullPreWalk = true;
|
|
1490
|
+
}
|
|
1491
|
+
return hook;
|
|
1492
|
+
}
|
|
1493
|
+
});
|
|
1494
|
+
|
|
1495
|
+
// The same for the block pass, over the types the parser records for it.
|
|
1496
|
+
/** @type {boolean} */
|
|
1497
|
+
this._needsFullBlockPreWalk = false;
|
|
1498
|
+
this.hooks.blockPreStatementByType.intercept({
|
|
1499
|
+
factory: (type, hook) => {
|
|
1500
|
+
if (!BLOCK_DECLARATION_TYPES.has(type)) {
|
|
1501
|
+
this._needsFullBlockPreWalk = true;
|
|
1502
|
+
}
|
|
1503
|
+
return hook;
|
|
1504
|
+
}
|
|
1505
|
+
});
|
|
1506
|
+
// BACKWARD-COMPAT END
|
|
1204
1507
|
/** @type {WeakMap<Expression, DestructuringAssignmentProperties> | undefined} */
|
|
1205
1508
|
this.destructuringAssignmentProperties = undefined;
|
|
1206
1509
|
/** @type {TagData | undefined} */
|
|
@@ -1835,7 +2138,7 @@ class JavascriptParser extends Parser {
|
|
|
1835
2138
|
const info = this.getVariableInfo(/** @type {Identifier} */ (expr).name);
|
|
1836
2139
|
if (
|
|
1837
2140
|
typeof info === "string" ||
|
|
1838
|
-
(info
|
|
2141
|
+
(JavascriptParser.isVariableInfo(info) &&
|
|
1839
2142
|
(info.isFree() ||
|
|
1840
2143
|
info.isTagged() ||
|
|
1841
2144
|
// Walk `tagInfo` in `callHooksForInfo` if tagInfo is present.
|
|
@@ -1854,7 +2157,8 @@ class JavascriptParser extends Parser {
|
|
|
1854
2157
|
const info = this.getVariableInfo("this");
|
|
1855
2158
|
if (
|
|
1856
2159
|
typeof info === "string" ||
|
|
1857
|
-
(
|
|
2160
|
+
(JavascriptParser.isVariableInfo(info) &&
|
|
2161
|
+
(info.isFree() || info.isTagged()))
|
|
1858
2162
|
) {
|
|
1859
2163
|
return {
|
|
1860
2164
|
name: info,
|
|
@@ -2378,12 +2682,19 @@ class JavascriptParser extends Parser {
|
|
|
2378
2682
|
}
|
|
2379
2683
|
|
|
2380
2684
|
/**
|
|
2381
|
-
*
|
|
2382
|
-
*
|
|
2685
|
+
* Report what the program imports and re-exports, before anything reads a
|
|
2686
|
+
* name. The list is what the parser recorded, in source order.
|
|
2687
|
+
* @param {ModuleDeclarations} declarations the program's module declarations
|
|
2383
2688
|
*/
|
|
2384
|
-
|
|
2385
|
-
for (let index = 0, len =
|
|
2386
|
-
const statement =
|
|
2689
|
+
_modulePreWalkDeclarations(declarations) {
|
|
2690
|
+
for (let index = 0, len = declarations.length; index < len; index += 2) {
|
|
2691
|
+
const statement =
|
|
2692
|
+
/** @type {ModuleDeclaration} */
|
|
2693
|
+
(declarations[index]);
|
|
2694
|
+
// what precedes it decides whether removing it joins two statements
|
|
2695
|
+
this.prevStatement =
|
|
2696
|
+
/** @type {Statement | undefined} */
|
|
2697
|
+
(declarations[index + 1]);
|
|
2387
2698
|
/** @type {StatementPath} */
|
|
2388
2699
|
(this.statementPath).push(statement);
|
|
2389
2700
|
switch (statement.type) {
|
|
@@ -2404,19 +2715,212 @@ class JavascriptParser extends Parser {
|
|
|
2404
2715
|
}
|
|
2405
2716
|
|
|
2406
2717
|
/**
|
|
2407
|
-
*
|
|
2718
|
+
* Declare what the scope the node opens hoists, before anything reads a
|
|
2719
|
+
* name in it.
|
|
2720
|
+
* @param {Program | BlockStatement} node the node owning the scope
|
|
2721
|
+
*/
|
|
2722
|
+
_preWalkScope(node) {
|
|
2723
|
+
// BACKWARD-COMPAT START
|
|
2724
|
+
if (this._needsFullPreWalk || this.hooks.preStatement.taps.length !== 0) {
|
|
2725
|
+
if (node.type === "Program") this.preWalkStatements(node.body);
|
|
2726
|
+
else this.preWalkStatement(node);
|
|
2727
|
+
return;
|
|
2728
|
+
}
|
|
2729
|
+
// BACKWARD-COMPAT END
|
|
2730
|
+
this._preWalkHoistedDeclarations(
|
|
2731
|
+
hoistedDeclarationsOf(node, this._hasParserRecord)
|
|
2732
|
+
);
|
|
2733
|
+
}
|
|
2734
|
+
|
|
2735
|
+
/**
|
|
2736
|
+
* Declare what hoists to the scope being entered, from what the parser
|
|
2737
|
+
* recorded while reading it. `prevStatement` is not available here.
|
|
2738
|
+
* @param {HoistedDeclarations} hoisted what the scope declares
|
|
2739
|
+
*/
|
|
2740
|
+
_preWalkHoistedDeclarations(hoisted) {
|
|
2741
|
+
for (let index = 0, len = hoisted.length; index < len; index++) {
|
|
2742
|
+
// WHY: the statements between two declarations are not read here, so
|
|
2743
|
+
// the one before this declaration is unknown rather than the previous
|
|
2744
|
+
// declaration. A tap needing it taps `preStatement`, which walks.
|
|
2745
|
+
this.prevStatement = undefined;
|
|
2746
|
+
this.preWalkStatement(hoisted[index]);
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
|
|
2750
|
+
// BACKWARD-COMPAT START
|
|
2751
|
+
/**
|
|
2752
|
+
* Walk every statement of a scope to declare what hoists to it. Only a tap
|
|
2753
|
+
* on the deprecated `preStatement` hook asks for this.
|
|
2408
2754
|
* @param {(Statement | ModuleDeclaration)[]} statements statements
|
|
2755
|
+
* @deprecated TODO in the next major release: remove, with the `preStatement` hook
|
|
2409
2756
|
*/
|
|
2410
2757
|
preWalkStatements(statements) {
|
|
2758
|
+
for (let index = 0, len = statements.length; index < len; index++) {
|
|
2759
|
+
this.preWalkStatement(statements[index]);
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2763
|
+
/**
|
|
2764
|
+
* Pre walk block statement.
|
|
2765
|
+
* @param {BlockStatement} statement block statement
|
|
2766
|
+
* @deprecated TODO in the next major release: remove, with the `preStatement` hook
|
|
2767
|
+
*/
|
|
2768
|
+
preWalkBlockStatement(statement) {
|
|
2769
|
+
this.preWalkStatements(statement.body);
|
|
2770
|
+
}
|
|
2771
|
+
|
|
2772
|
+
/**
|
|
2773
|
+
* Pre walk if statement.
|
|
2774
|
+
* @param {IfStatement} statement if statement
|
|
2775
|
+
* @deprecated TODO in the next major release: remove, with the `preStatement` hook
|
|
2776
|
+
*/
|
|
2777
|
+
preWalkIfStatement(statement) {
|
|
2778
|
+
this.preWalkStatement(statement.consequent);
|
|
2779
|
+
if (statement.alternate) {
|
|
2780
|
+
this.preWalkStatement(statement.alternate);
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
|
|
2784
|
+
/**
|
|
2785
|
+
* Pre walk labeled statement.
|
|
2786
|
+
* @param {LabeledStatement} statement labeled statement
|
|
2787
|
+
* @deprecated TODO in the next major release: remove, with the `preStatement` hook
|
|
2788
|
+
*/
|
|
2789
|
+
preWalkLabeledStatement(statement) {
|
|
2790
|
+
this.preWalkStatement(statement.body);
|
|
2791
|
+
}
|
|
2792
|
+
|
|
2793
|
+
/**
|
|
2794
|
+
* Pre walk with statement.
|
|
2795
|
+
* @param {WithStatement} statement with statement
|
|
2796
|
+
* @deprecated TODO in the next major release: remove, with the `preStatement` hook
|
|
2797
|
+
*/
|
|
2798
|
+
preWalkWithStatement(statement) {
|
|
2799
|
+
this.preWalkStatement(statement.body);
|
|
2800
|
+
}
|
|
2801
|
+
|
|
2802
|
+
/**
|
|
2803
|
+
* Pre walk switch statement.
|
|
2804
|
+
* @param {SwitchStatement} statement switch statement
|
|
2805
|
+
* @deprecated TODO in the next major release: remove, with the `preStatement` hook
|
|
2806
|
+
*/
|
|
2807
|
+
preWalkSwitchStatement(statement) {
|
|
2808
|
+
this.preWalkSwitchCases(statement.cases);
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2811
|
+
/**
|
|
2812
|
+
* Pre walk switch cases.
|
|
2813
|
+
* @param {SwitchCase[]} switchCases switch cases
|
|
2814
|
+
* @deprecated TODO in the next major release: remove, with the `preStatement` hook
|
|
2815
|
+
*/
|
|
2816
|
+
preWalkSwitchCases(switchCases) {
|
|
2817
|
+
for (let index = 0, len = switchCases.length; index < len; index++) {
|
|
2818
|
+
this.preWalkStatements(switchCases[index].consequent);
|
|
2819
|
+
}
|
|
2820
|
+
}
|
|
2821
|
+
|
|
2822
|
+
/**
|
|
2823
|
+
* Pre walk try statement.
|
|
2824
|
+
* @param {TryStatement} statement try statement
|
|
2825
|
+
* @deprecated TODO in the next major release: remove, with the `preStatement` hook
|
|
2826
|
+
*/
|
|
2827
|
+
preWalkTryStatement(statement) {
|
|
2828
|
+
this.preWalkStatement(statement.block);
|
|
2829
|
+
if (statement.handler) this.preWalkCatchClause(statement.handler);
|
|
2830
|
+
if (statement.finalizer) this.preWalkStatement(statement.finalizer);
|
|
2831
|
+
}
|
|
2832
|
+
|
|
2833
|
+
/**
|
|
2834
|
+
* Pre walk catch clause.
|
|
2835
|
+
* @param {CatchClause} catchClause catch clause
|
|
2836
|
+
* @deprecated TODO in the next major release: remove, with the `preStatement` hook
|
|
2837
|
+
*/
|
|
2838
|
+
preWalkCatchClause(catchClause) {
|
|
2839
|
+
this.preWalkStatement(catchClause.body);
|
|
2840
|
+
}
|
|
2841
|
+
|
|
2842
|
+
/**
|
|
2843
|
+
* Pre walk while statement.
|
|
2844
|
+
* @param {WhileStatement} statement while statement
|
|
2845
|
+
* @deprecated TODO in the next major release: remove, with the `preStatement` hook
|
|
2846
|
+
*/
|
|
2847
|
+
preWalkWhileStatement(statement) {
|
|
2848
|
+
this.preWalkStatement(statement.body);
|
|
2849
|
+
}
|
|
2850
|
+
|
|
2851
|
+
/**
|
|
2852
|
+
* Pre walk do while statement.
|
|
2853
|
+
* @param {DoWhileStatement} statement do while statement
|
|
2854
|
+
* @deprecated TODO in the next major release: remove, with the `preStatement` hook
|
|
2855
|
+
*/
|
|
2856
|
+
preWalkDoWhileStatement(statement) {
|
|
2857
|
+
this.preWalkStatement(statement.body);
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2860
|
+
/**
|
|
2861
|
+
* Pre walk for statement.
|
|
2862
|
+
* @param {ForStatement} statement for statement
|
|
2863
|
+
* @deprecated TODO in the next major release: remove, with the `preStatement` hook
|
|
2864
|
+
*/
|
|
2865
|
+
preWalkForStatement(statement) {
|
|
2866
|
+
if (statement.init && statement.init.type === "VariableDeclaration") {
|
|
2867
|
+
this.preWalkStatement(statement.init);
|
|
2868
|
+
}
|
|
2869
|
+
this.preWalkStatement(statement.body);
|
|
2870
|
+
}
|
|
2871
|
+
|
|
2872
|
+
/**
|
|
2873
|
+
* Pre walk for in statement.
|
|
2874
|
+
* @param {ForInStatement} statement for in statement
|
|
2875
|
+
* @deprecated TODO in the next major release: remove, with the `preStatement` hook
|
|
2876
|
+
*/
|
|
2877
|
+
preWalkForInStatement(statement) {
|
|
2878
|
+
if (statement.left.type === "VariableDeclaration") {
|
|
2879
|
+
this.preWalkStatement(statement.left);
|
|
2880
|
+
}
|
|
2881
|
+
this.preWalkStatement(statement.body);
|
|
2882
|
+
}
|
|
2883
|
+
|
|
2884
|
+
/**
|
|
2885
|
+
* Pre walk for of statement. `for await` is reported by the walk, not here.
|
|
2886
|
+
* @param {ForOfStatement} statement for of statement
|
|
2887
|
+
* @deprecated TODO in the next major release: remove, with the `preStatement` hook
|
|
2888
|
+
*/
|
|
2889
|
+
preWalkForOfStatement(statement) {
|
|
2890
|
+
if (statement.left.type === "VariableDeclaration") {
|
|
2891
|
+
this.preWalkStatement(statement.left);
|
|
2892
|
+
}
|
|
2893
|
+
this.preWalkStatement(statement.body);
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2896
|
+
/**
|
|
2897
|
+
* Scan every top-level statement for the program's module declarations.
|
|
2898
|
+
* The parser records them now, so nothing inside webpack scans for them.
|
|
2899
|
+
* @deprecated TODO in the next major release: remove
|
|
2900
|
+
* @param {(Statement | ModuleDeclaration)[]} statements statements
|
|
2901
|
+
*/
|
|
2902
|
+
modulePreWalkStatements(statements) {
|
|
2903
|
+
/** @type {ModuleDeclarations} */
|
|
2904
|
+
const declarations = [];
|
|
2411
2905
|
for (let index = 0, len = statements.length; index < len; index++) {
|
|
2412
2906
|
const statement = statements[index];
|
|
2413
|
-
|
|
2907
|
+
if (MODULE_STATEMENT_TYPES.has(statement.type)) {
|
|
2908
|
+
declarations.push(
|
|
2909
|
+
statement,
|
|
2910
|
+
index === 0 ? undefined : statements[index - 1]
|
|
2911
|
+
);
|
|
2912
|
+
}
|
|
2414
2913
|
}
|
|
2914
|
+
this._modulePreWalkDeclarations(declarations);
|
|
2415
2915
|
}
|
|
2916
|
+
// BACKWARD-COMPAT END
|
|
2416
2917
|
|
|
2918
|
+
// BACKWARD-COMPAT START
|
|
2417
2919
|
/**
|
|
2418
|
-
*
|
|
2920
|
+
* Walk every statement of a list to declare what it binds. Only a tap on the
|
|
2921
|
+
* deprecated `blockPreStatement` hook asks for this.
|
|
2419
2922
|
* @param {(Statement | ModuleDeclaration)[]} statements statements
|
|
2923
|
+
* @deprecated TODO in the next major release: remove, with the `blockPreStatement` hook
|
|
2420
2924
|
*/
|
|
2421
2925
|
blockPreWalkStatements(statements) {
|
|
2422
2926
|
for (let index = 0, len = statements.length; index < len; index++) {
|
|
@@ -2424,6 +2928,70 @@ class JavascriptParser extends Parser {
|
|
|
2424
2928
|
this.blockPreWalkStatement(statement);
|
|
2425
2929
|
}
|
|
2426
2930
|
}
|
|
2931
|
+
// BACKWARD-COMPAT END
|
|
2932
|
+
|
|
2933
|
+
/**
|
|
2934
|
+
* Declare what the statement list binds into its own block scope, before any
|
|
2935
|
+
* of it is walked. The list is what the parser recorded while reading it.
|
|
2936
|
+
* @param {Program | BlockStatement | StaticBlock | SwitchCase} node the node owning the list
|
|
2937
|
+
* @param {(Statement | ModuleDeclaration)[]} statements the list it holds
|
|
2938
|
+
*/
|
|
2939
|
+
_blockPreWalkScope(node, statements) {
|
|
2940
|
+
// BACKWARD-COMPAT START
|
|
2941
|
+
if (
|
|
2942
|
+
this._needsFullBlockPreWalk ||
|
|
2943
|
+
this.hooks.blockPreStatement.taps.length !== 0
|
|
2944
|
+
) {
|
|
2945
|
+
this.blockPreWalkStatements(statements);
|
|
2946
|
+
return;
|
|
2947
|
+
}
|
|
2948
|
+
// BACKWARD-COMPAT END
|
|
2949
|
+
/** @type {BlockDeclarations | undefined} */
|
|
2950
|
+
let recorded;
|
|
2951
|
+
if (this._hasParserRecord) {
|
|
2952
|
+
recorded =
|
|
2953
|
+
/** @type {typeof node & { [BLOCK_DECLARATIONS]?: BlockDeclarations }} */
|
|
2954
|
+
(node)[BLOCK_DECLARATIONS];
|
|
2955
|
+
// 72.8% of the lists a build reads declare nothing, and saying so is
|
|
2956
|
+
// the whole pass for them
|
|
2957
|
+
if (recorded === 0) return;
|
|
2958
|
+
}
|
|
2959
|
+
if (recorded === undefined) {
|
|
2960
|
+
recorded = collectBlockDeclarations(statements);
|
|
2961
|
+
if (recorded === 0) return;
|
|
2962
|
+
}
|
|
2963
|
+
this._blockPreWalkDeclarations(statements, recorded);
|
|
2964
|
+
}
|
|
2965
|
+
|
|
2966
|
+
/**
|
|
2967
|
+
* Declare what the recorded statements of the list bind, in source order.
|
|
2968
|
+
* @param {(Statement | ModuleDeclaration)[]} statements the whole list
|
|
2969
|
+
* @param {BlockDeclarations} declarations which of them declare
|
|
2970
|
+
*/
|
|
2971
|
+
_blockPreWalkDeclarations(statements, declarations) {
|
|
2972
|
+
if (typeof declarations === "number") {
|
|
2973
|
+
for (let bits = declarations; bits !== 0; bits &= bits - 1) {
|
|
2974
|
+
this._blockPreWalkAt(statements, 31 - Math.clz32(bits & -bits));
|
|
2975
|
+
}
|
|
2976
|
+
return;
|
|
2977
|
+
}
|
|
2978
|
+
for (let index = 0, len = declarations.length; index < len; index++) {
|
|
2979
|
+
this._blockPreWalkAt(statements, declarations[index]);
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
|
|
2983
|
+
/**
|
|
2984
|
+
* Declare what one statement of the list binds, with the statement written
|
|
2985
|
+
* before it, so a tap reading `prevStatement` sees what the walk would show.
|
|
2986
|
+
* @param {(Statement | ModuleDeclaration)[]} statements the whole list
|
|
2987
|
+
* @param {number} index which statement declares
|
|
2988
|
+
*/
|
|
2989
|
+
_blockPreWalkAt(statements, index) {
|
|
2990
|
+
// the first statement of the list has nothing before it, and leaves
|
|
2991
|
+
// whatever the caller set standing, as walking the whole list did
|
|
2992
|
+
if (index !== 0) this.prevStatement = statements[index - 1];
|
|
2993
|
+
this.blockPreWalkStatement(statements[index]);
|
|
2994
|
+
}
|
|
2427
2995
|
|
|
2428
2996
|
/**
|
|
2429
2997
|
* Walking iterates the statements and expressions and processes them
|
|
@@ -2473,21 +3041,22 @@ class JavascriptParser extends Parser {
|
|
|
2473
3041
|
(this.statementPath).pop();
|
|
2474
3042
|
return;
|
|
2475
3043
|
}
|
|
2476
|
-
//
|
|
2477
|
-
//
|
|
3044
|
+
// a class declaration reaches here for the typed hook alone: defining it
|
|
3045
|
+
// is the block pass's. The rest are only walked into by the deprecated
|
|
3046
|
+
// statement walk, which a tap expecting every statement turns back on.
|
|
2478
3047
|
switch (statement.type) {
|
|
2479
3048
|
case "VariableDeclaration":
|
|
2480
3049
|
this.preWalkVariableDeclaration(statement);
|
|
2481
3050
|
break;
|
|
3051
|
+
case "FunctionDeclaration":
|
|
3052
|
+
this.preWalkFunctionDeclaration(statement);
|
|
3053
|
+
break;
|
|
2482
3054
|
case "IfStatement":
|
|
2483
3055
|
this.preWalkIfStatement(statement);
|
|
2484
3056
|
break;
|
|
2485
3057
|
case "BlockStatement":
|
|
2486
3058
|
this.preWalkBlockStatement(statement);
|
|
2487
3059
|
break;
|
|
2488
|
-
case "FunctionDeclaration":
|
|
2489
|
-
this.preWalkFunctionDeclaration(statement);
|
|
2490
|
-
break;
|
|
2491
3060
|
case "ForStatement":
|
|
2492
3061
|
this.preWalkForStatement(statement);
|
|
2493
3062
|
break;
|
|
@@ -2660,13 +3229,6 @@ class JavascriptParser extends Parser {
|
|
|
2660
3229
|
}
|
|
2661
3230
|
|
|
2662
3231
|
// Real Statements
|
|
2663
|
-
/**
|
|
2664
|
-
* Pre walk block statement.
|
|
2665
|
-
* @param {BlockStatement} statement block statement
|
|
2666
|
-
*/
|
|
2667
|
-
preWalkBlockStatement(statement) {
|
|
2668
|
-
this.preWalkStatements(statement.body);
|
|
2669
|
-
}
|
|
2670
3232
|
|
|
2671
3233
|
/**
|
|
2672
3234
|
* Walk block statement.
|
|
@@ -2676,7 +3238,7 @@ class JavascriptParser extends Parser {
|
|
|
2676
3238
|
const oldScope = this._enterBlockScope();
|
|
2677
3239
|
const body = statement.body;
|
|
2678
3240
|
const prev = this.prevStatement;
|
|
2679
|
-
this.
|
|
3241
|
+
this._blockPreWalkScope(statement, body);
|
|
2680
3242
|
this.prevStatement = prev;
|
|
2681
3243
|
this.walkStatements(body);
|
|
2682
3244
|
|
|
@@ -2691,21 +3253,10 @@ class JavascriptParser extends Parser {
|
|
|
2691
3253
|
this.walkExpression(statement.expression);
|
|
2692
3254
|
}
|
|
2693
3255
|
|
|
2694
|
-
/**
|
|
2695
|
-
* Pre walk if statement.
|
|
2696
|
-
* @param {IfStatement} statement if statement
|
|
2697
|
-
*/
|
|
2698
|
-
preWalkIfStatement(statement) {
|
|
2699
|
-
this.preWalkStatement(statement.consequent);
|
|
2700
|
-
if (statement.alternate) {
|
|
2701
|
-
this.preWalkStatement(statement.alternate);
|
|
2702
|
-
}
|
|
2703
|
-
}
|
|
2704
|
-
|
|
2705
3256
|
/**
|
|
2706
3257
|
* Walks a conditional branch with its guard frame (if any) pushed onto the
|
|
2707
3258
|
* parser-state guard stack for the duration of the branch body.
|
|
2708
|
-
* @param {
|
|
3259
|
+
* @param {GuardFrame | undefined | null} frame guard frame, or falsy when the branch is unguarded
|
|
2709
3260
|
* @param {() => void} walk branch walk
|
|
2710
3261
|
* @returns {void}
|
|
2711
3262
|
*/
|
|
@@ -2768,14 +3319,6 @@ class JavascriptParser extends Parser {
|
|
|
2768
3319
|
}
|
|
2769
3320
|
}
|
|
2770
3321
|
|
|
2771
|
-
/**
|
|
2772
|
-
* Pre walk labeled statement.
|
|
2773
|
-
* @param {LabeledStatement} statement with statement
|
|
2774
|
-
*/
|
|
2775
|
-
preWalkLabeledStatement(statement) {
|
|
2776
|
-
this.preWalkStatement(statement.body);
|
|
2777
|
-
}
|
|
2778
|
-
|
|
2779
3322
|
/**
|
|
2780
3323
|
* Walk labeled statement.
|
|
2781
3324
|
* @param {LabeledStatement} statement with statement
|
|
@@ -2792,14 +3335,6 @@ class JavascriptParser extends Parser {
|
|
|
2792
3335
|
this._exitBlockScope(oldScope, false);
|
|
2793
3336
|
}
|
|
2794
3337
|
|
|
2795
|
-
/**
|
|
2796
|
-
* Pre walk with statement.
|
|
2797
|
-
* @param {WithStatement} statement with statement
|
|
2798
|
-
*/
|
|
2799
|
-
preWalkWithStatement(statement) {
|
|
2800
|
-
this.preWalkStatement(statement.body);
|
|
2801
|
-
}
|
|
2802
|
-
|
|
2803
3338
|
/**
|
|
2804
3339
|
* Walk with statement.
|
|
2805
3340
|
* @param {WithStatement} statement with statement
|
|
@@ -2818,14 +3353,6 @@ class JavascriptParser extends Parser {
|
|
|
2818
3353
|
this._exitBlockScope(oldScope, false);
|
|
2819
3354
|
}
|
|
2820
3355
|
|
|
2821
|
-
/**
|
|
2822
|
-
* Pre walk switch statement.
|
|
2823
|
-
* @param {SwitchStatement} statement switch statement
|
|
2824
|
-
*/
|
|
2825
|
-
preWalkSwitchStatement(statement) {
|
|
2826
|
-
this.preWalkSwitchCases(statement.cases);
|
|
2827
|
-
}
|
|
2828
|
-
|
|
2829
3356
|
/**
|
|
2830
3357
|
* Walk switch statement.
|
|
2831
3358
|
* @param {SwitchStatement} statement switch statement
|
|
@@ -2867,16 +3394,6 @@ class JavascriptParser extends Parser {
|
|
|
2867
3394
|
this.walkTerminatingStatement(statement);
|
|
2868
3395
|
}
|
|
2869
3396
|
|
|
2870
|
-
/**
|
|
2871
|
-
* Pre walk try statement.
|
|
2872
|
-
* @param {TryStatement} statement try statement
|
|
2873
|
-
*/
|
|
2874
|
-
preWalkTryStatement(statement) {
|
|
2875
|
-
this.preWalkStatement(statement.block);
|
|
2876
|
-
if (statement.handler) this.preWalkCatchClause(statement.handler);
|
|
2877
|
-
if (statement.finalizer) this.preWalkStatement(statement.finalizer);
|
|
2878
|
-
}
|
|
2879
|
-
|
|
2880
3397
|
/**
|
|
2881
3398
|
* Walk try statement.
|
|
2882
3399
|
* @param {TryStatement} statement try statement
|
|
@@ -2915,14 +3432,6 @@ class JavascriptParser extends Parser {
|
|
|
2915
3432
|
}
|
|
2916
3433
|
}
|
|
2917
3434
|
|
|
2918
|
-
/**
|
|
2919
|
-
* Pre walk while statement.
|
|
2920
|
-
* @param {WhileStatement} statement while statement
|
|
2921
|
-
*/
|
|
2922
|
-
preWalkWhileStatement(statement) {
|
|
2923
|
-
this.preWalkStatement(statement.body);
|
|
2924
|
-
}
|
|
2925
|
-
|
|
2926
3435
|
/**
|
|
2927
3436
|
* Walk while statement.
|
|
2928
3437
|
* @param {WhileStatement} statement while statement
|
|
@@ -2935,14 +3444,6 @@ class JavascriptParser extends Parser {
|
|
|
2935
3444
|
this._exitBlockScope(oldScope, false);
|
|
2936
3445
|
}
|
|
2937
3446
|
|
|
2938
|
-
/**
|
|
2939
|
-
* Pre walk do while statement.
|
|
2940
|
-
* @param {DoWhileStatement} statement do while statement
|
|
2941
|
-
*/
|
|
2942
|
-
preWalkDoWhileStatement(statement) {
|
|
2943
|
-
this.preWalkStatement(statement.body);
|
|
2944
|
-
}
|
|
2945
|
-
|
|
2946
3447
|
/**
|
|
2947
3448
|
* Walk do while statement.
|
|
2948
3449
|
* @param {DoWhileStatement} statement do while statement
|
|
@@ -2955,17 +3456,6 @@ class JavascriptParser extends Parser {
|
|
|
2955
3456
|
this._exitBlockScope(oldScope, false);
|
|
2956
3457
|
}
|
|
2957
3458
|
|
|
2958
|
-
/**
|
|
2959
|
-
* Pre walk for statement.
|
|
2960
|
-
* @param {ForStatement} statement for statement
|
|
2961
|
-
*/
|
|
2962
|
-
preWalkForStatement(statement) {
|
|
2963
|
-
if (statement.init && statement.init.type === "VariableDeclaration") {
|
|
2964
|
-
this.preWalkStatement(statement.init);
|
|
2965
|
-
}
|
|
2966
|
-
this.preWalkStatement(statement.body);
|
|
2967
|
-
}
|
|
2968
|
-
|
|
2969
3459
|
/**
|
|
2970
3460
|
* Walk for statement.
|
|
2971
3461
|
* @param {ForStatement} statement for statement
|
|
@@ -2993,7 +3483,7 @@ class JavascriptParser extends Parser {
|
|
|
2993
3483
|
if (body.type === "BlockStatement") {
|
|
2994
3484
|
// no need to add additional scope
|
|
2995
3485
|
const prev = this.prevStatement;
|
|
2996
|
-
this.
|
|
3486
|
+
this._blockPreWalkScope(body, body.body);
|
|
2997
3487
|
this.prevStatement = prev;
|
|
2998
3488
|
this.walkStatements(body.body);
|
|
2999
3489
|
} else {
|
|
@@ -3003,17 +3493,6 @@ class JavascriptParser extends Parser {
|
|
|
3003
3493
|
this._exitBlockScope(oldScope, false);
|
|
3004
3494
|
}
|
|
3005
3495
|
|
|
3006
|
-
/**
|
|
3007
|
-
* Pre walk for in statement.
|
|
3008
|
-
* @param {ForInStatement} statement for statement
|
|
3009
|
-
*/
|
|
3010
|
-
preWalkForInStatement(statement) {
|
|
3011
|
-
if (statement.left.type === "VariableDeclaration") {
|
|
3012
|
-
this.preWalkVariableDeclaration(statement.left);
|
|
3013
|
-
}
|
|
3014
|
-
this.preWalkStatement(statement.body);
|
|
3015
|
-
}
|
|
3016
|
-
|
|
3017
3496
|
/**
|
|
3018
3497
|
* Walk for in statement.
|
|
3019
3498
|
* @param {ForInStatement} statement for statement
|
|
@@ -3023,7 +3502,7 @@ class JavascriptParser extends Parser {
|
|
|
3023
3502
|
if (statement.left.type === "VariableDeclaration") {
|
|
3024
3503
|
this.blockPreWalkVariableDeclaration(statement.left);
|
|
3025
3504
|
this.walkVariableDeclaration(statement.left);
|
|
3026
|
-
} else {
|
|
3505
|
+
} else if (!this._walkWriteTarget(statement.left, statement)) {
|
|
3027
3506
|
this.walkPattern(statement.left);
|
|
3028
3507
|
}
|
|
3029
3508
|
|
|
@@ -3034,7 +3513,7 @@ class JavascriptParser extends Parser {
|
|
|
3034
3513
|
if (body.type === "BlockStatement") {
|
|
3035
3514
|
// no need to add additional scope
|
|
3036
3515
|
const prev = this.prevStatement;
|
|
3037
|
-
this.
|
|
3516
|
+
this._blockPreWalkScope(body, body.body);
|
|
3038
3517
|
this.prevStatement = prev;
|
|
3039
3518
|
this.walkStatements(body.body);
|
|
3040
3519
|
} else {
|
|
@@ -3044,30 +3523,19 @@ class JavascriptParser extends Parser {
|
|
|
3044
3523
|
this._exitBlockScope(oldScope, false);
|
|
3045
3524
|
}
|
|
3046
3525
|
|
|
3047
|
-
/**
|
|
3048
|
-
* Pre walk for of statement.
|
|
3049
|
-
* @param {ForOfStatement} statement statement
|
|
3050
|
-
*/
|
|
3051
|
-
preWalkForOfStatement(statement) {
|
|
3052
|
-
if (statement.await && this.scope.topLevelScope === true) {
|
|
3053
|
-
this.hooks.topLevelAwait.call(statement);
|
|
3054
|
-
}
|
|
3055
|
-
if (statement.left.type === "VariableDeclaration") {
|
|
3056
|
-
this.preWalkVariableDeclaration(statement.left);
|
|
3057
|
-
}
|
|
3058
|
-
this.preWalkStatement(statement.body);
|
|
3059
|
-
}
|
|
3060
|
-
|
|
3061
3526
|
/**
|
|
3062
3527
|
* Walk for of statement.
|
|
3063
3528
|
* @param {ForOfStatement} statement for statement
|
|
3064
3529
|
*/
|
|
3065
3530
|
walkForOfStatement(statement) {
|
|
3531
|
+
if (statement.await && this.scope.topLevelScope === true) {
|
|
3532
|
+
this.hooks.topLevelAwait.call(statement);
|
|
3533
|
+
}
|
|
3066
3534
|
const oldScope = this._enterBlockScope();
|
|
3067
3535
|
if (statement.left.type === "VariableDeclaration") {
|
|
3068
3536
|
this.blockPreWalkVariableDeclaration(statement.left);
|
|
3069
3537
|
this.walkVariableDeclaration(statement.left);
|
|
3070
|
-
} else {
|
|
3538
|
+
} else if (!this._walkWriteTarget(statement.left, statement)) {
|
|
3071
3539
|
this.walkPattern(statement.left);
|
|
3072
3540
|
}
|
|
3073
3541
|
|
|
@@ -3078,7 +3546,7 @@ class JavascriptParser extends Parser {
|
|
|
3078
3546
|
if (body.type === "BlockStatement") {
|
|
3079
3547
|
// no need to add additional scope
|
|
3080
3548
|
const prev = this.prevStatement;
|
|
3081
|
-
this.
|
|
3549
|
+
this._blockPreWalkScope(body, body.body);
|
|
3082
3550
|
this.prevStatement = prev;
|
|
3083
3551
|
this.walkStatements(body.body);
|
|
3084
3552
|
} else {
|
|
@@ -3120,7 +3588,7 @@ class JavascriptParser extends Parser {
|
|
|
3120
3588
|
|
|
3121
3589
|
const prev = this.prevStatement;
|
|
3122
3590
|
|
|
3123
|
-
this.
|
|
3591
|
+
this._preWalkScope(statement.body);
|
|
3124
3592
|
this.prevStatement = prev;
|
|
3125
3593
|
this.walkStatement(statement.body);
|
|
3126
3594
|
|
|
@@ -3698,17 +4166,6 @@ class JavascriptParser extends Parser {
|
|
|
3698
4166
|
this.walkClass(statement);
|
|
3699
4167
|
}
|
|
3700
4168
|
|
|
3701
|
-
/**
|
|
3702
|
-
* Pre walk switch cases.
|
|
3703
|
-
* @param {SwitchCase[]} switchCases switch statement
|
|
3704
|
-
*/
|
|
3705
|
-
preWalkSwitchCases(switchCases) {
|
|
3706
|
-
for (let index = 0, len = switchCases.length; index < len; index++) {
|
|
3707
|
-
const switchCase = switchCases[index];
|
|
3708
|
-
this.preWalkStatements(switchCase.consequent);
|
|
3709
|
-
}
|
|
3710
|
-
}
|
|
3711
|
-
|
|
3712
4169
|
/**
|
|
3713
4170
|
* Processes the provided switch case.
|
|
3714
4171
|
* @param {SwitchCase[]} switchCases switch statement
|
|
@@ -3724,7 +4181,7 @@ class JavascriptParser extends Parser {
|
|
|
3724
4181
|
|
|
3725
4182
|
if (switchCase.consequent.length > 0) {
|
|
3726
4183
|
const prev = this.prevStatement;
|
|
3727
|
-
this.
|
|
4184
|
+
this._blockPreWalkScope(switchCase, switchCase.consequent);
|
|
3728
4185
|
this.prevStatement = prev;
|
|
3729
4186
|
}
|
|
3730
4187
|
}
|
|
@@ -3745,14 +4202,6 @@ class JavascriptParser extends Parser {
|
|
|
3745
4202
|
this._exitBlockScope(oldScope, false);
|
|
3746
4203
|
}
|
|
3747
4204
|
|
|
3748
|
-
/**
|
|
3749
|
-
* Pre walk catch clause.
|
|
3750
|
-
* @param {CatchClause} catchClause catch clause
|
|
3751
|
-
*/
|
|
3752
|
-
preWalkCatchClause(catchClause) {
|
|
3753
|
-
this.preWalkStatement(catchClause.body);
|
|
3754
|
-
}
|
|
3755
|
-
|
|
3756
4205
|
/**
|
|
3757
4206
|
* Processes the provided catch clause.
|
|
3758
4207
|
* @param {CatchClause} catchClause catch clause
|
|
@@ -4081,7 +4530,7 @@ class JavascriptParser extends Parser {
|
|
|
4081
4530
|
|
|
4082
4531
|
const prev = this.prevStatement;
|
|
4083
4532
|
|
|
4084
|
-
this.
|
|
4533
|
+
this._preWalkScope(expression.body);
|
|
4085
4534
|
this.prevStatement = prev;
|
|
4086
4535
|
this.walkStatement(expression.body);
|
|
4087
4536
|
|
|
@@ -4106,7 +4555,7 @@ class JavascriptParser extends Parser {
|
|
|
4106
4555
|
if (expression.body.type === "BlockStatement") {
|
|
4107
4556
|
this.detectMode(expression.body.body);
|
|
4108
4557
|
const prev = this.prevStatement;
|
|
4109
|
-
this.
|
|
4558
|
+
this._preWalkScope(expression.body);
|
|
4110
4559
|
this.prevStatement = prev;
|
|
4111
4560
|
this.walkStatement(expression.body);
|
|
4112
4561
|
} else {
|
|
@@ -4167,9 +4616,98 @@ class JavascriptParser extends Parser {
|
|
|
4167
4616
|
) {
|
|
4168
4617
|
this._checkStrictModeAssignTarget(expression.argument.name, expression);
|
|
4169
4618
|
}
|
|
4619
|
+
if (this._walkWriteTarget(expression.argument, expression)) return;
|
|
4170
4620
|
this.walkExpression(expression.argument);
|
|
4171
4621
|
}
|
|
4172
4622
|
|
|
4623
|
+
/**
|
|
4624
|
+
* Offers a write that is not an assignment's left side — an update's target
|
|
4625
|
+
* or a loop's binding — to the taps that care, `assign` carrying only an
|
|
4626
|
+
* AssignmentExpression.
|
|
4627
|
+
* @param {Expression | Pattern} target the written reference
|
|
4628
|
+
* @param {WriteStatement} node the construct performing the write
|
|
4629
|
+
* @returns {boolean} true when a tap rendered the write itself
|
|
4630
|
+
*/
|
|
4631
|
+
_walkWriteTarget(target, node) {
|
|
4632
|
+
if (target.type === "Identifier") {
|
|
4633
|
+
return Boolean(
|
|
4634
|
+
this._callHooksForName1(this.hooks.write, target.name, node)
|
|
4635
|
+
);
|
|
4636
|
+
}
|
|
4637
|
+
if (target.type.endsWith("Pattern")) {
|
|
4638
|
+
this.enterPattern(/** @type {Pattern} */ (target), (name) => {
|
|
4639
|
+
this._callHooksForName1(this.hooks.write, name, node);
|
|
4640
|
+
});
|
|
4641
|
+
this._walkPatternWriteMembers(target, node);
|
|
4642
|
+
return false;
|
|
4643
|
+
}
|
|
4644
|
+
return Boolean(
|
|
4645
|
+
target.type === "MemberExpression" &&
|
|
4646
|
+
this._callWriteMemberChain(target, node)
|
|
4647
|
+
);
|
|
4648
|
+
}
|
|
4649
|
+
|
|
4650
|
+
/**
|
|
4651
|
+
* Offers the member expressions a destructuring target writes to the
|
|
4652
|
+
* `writeMemberChain` taps, which `enterPattern` passes over because they
|
|
4653
|
+
* bind no name.
|
|
4654
|
+
* @param {Pattern | Expression | null} pattern the destructuring target
|
|
4655
|
+
* @param {WriteStatement} node the construct performing the write
|
|
4656
|
+
* @returns {void}
|
|
4657
|
+
*/
|
|
4658
|
+
_walkPatternWriteMembers(pattern, node) {
|
|
4659
|
+
if (!pattern) return;
|
|
4660
|
+
switch (pattern.type) {
|
|
4661
|
+
case "MemberExpression":
|
|
4662
|
+
this._callWriteMemberChain(pattern, node);
|
|
4663
|
+
break;
|
|
4664
|
+
case "ObjectPattern":
|
|
4665
|
+
for (const property of pattern.properties) {
|
|
4666
|
+
this._walkPatternWriteMembers(
|
|
4667
|
+
property.type === "RestElement"
|
|
4668
|
+
? property.argument
|
|
4669
|
+
: /** @type {Pattern} */ (property.value),
|
|
4670
|
+
node
|
|
4671
|
+
);
|
|
4672
|
+
}
|
|
4673
|
+
break;
|
|
4674
|
+
case "ArrayPattern":
|
|
4675
|
+
for (const element of pattern.elements) {
|
|
4676
|
+
this._walkPatternWriteMembers(element, node);
|
|
4677
|
+
}
|
|
4678
|
+
break;
|
|
4679
|
+
case "AssignmentPattern":
|
|
4680
|
+
this._walkPatternWriteMembers(pattern.left, node);
|
|
4681
|
+
break;
|
|
4682
|
+
case "RestElement":
|
|
4683
|
+
this._walkPatternWriteMembers(pattern.argument, node);
|
|
4684
|
+
break;
|
|
4685
|
+
}
|
|
4686
|
+
}
|
|
4687
|
+
|
|
4688
|
+
/**
|
|
4689
|
+
* Offers a written member expression to the `writeMemberChain` taps.
|
|
4690
|
+
* @param {MemberExpression} target the written member expression
|
|
4691
|
+
* @param {WriteStatement} node the construct performing the write
|
|
4692
|
+
* @returns {boolean} true when a tap rendered the write itself
|
|
4693
|
+
*/
|
|
4694
|
+
_callWriteMemberChain(target, node) {
|
|
4695
|
+
return Boolean(
|
|
4696
|
+
this._resolveMemberExpression(target, ALLOWED_MEMBER_TYPES_EXPRESSION) ===
|
|
4697
|
+
1 &&
|
|
4698
|
+
this._hasHooksForInfo(
|
|
4699
|
+
this.hooks.writeMemberChain,
|
|
4700
|
+
/** @type {string | VariableInfo} */ (this._memberRootInfo)
|
|
4701
|
+
) &&
|
|
4702
|
+
this.callHooksForInfo(
|
|
4703
|
+
this.hooks.writeMemberChain,
|
|
4704
|
+
/** @type {string | VariableInfo} */ (this._memberRootInfo),
|
|
4705
|
+
node,
|
|
4706
|
+
this._members
|
|
4707
|
+
)
|
|
4708
|
+
);
|
|
4709
|
+
}
|
|
4710
|
+
|
|
4173
4711
|
/**
|
|
4174
4712
|
* Reports `arguments.callee` / `arguments.caller` — both throw a TypeError
|
|
4175
4713
|
* once the module runs in strict-mode ESM output.
|
|
@@ -4418,6 +4956,7 @@ class JavascriptParser extends Parser {
|
|
|
4418
4956
|
this.defineVariable(name);
|
|
4419
4957
|
}
|
|
4420
4958
|
});
|
|
4959
|
+
this._walkPatternWriteMembers(expression.left, expression);
|
|
4421
4960
|
this.walkPattern(expression.left);
|
|
4422
4961
|
} else if (expression.left.type === "MemberExpression") {
|
|
4423
4962
|
if (
|
|
@@ -4641,7 +5180,7 @@ class JavascriptParser extends Parser {
|
|
|
4641
5180
|
if (functionExpression.body.type === "BlockStatement") {
|
|
4642
5181
|
this.detectMode(functionExpression.body.body);
|
|
4643
5182
|
const prev = this.prevStatement;
|
|
4644
|
-
this.
|
|
5183
|
+
this._preWalkScope(functionExpression.body);
|
|
4645
5184
|
this.prevStatement = prev;
|
|
4646
5185
|
this.walkStatement(functionExpression.body);
|
|
4647
5186
|
} else {
|
|
@@ -4931,11 +5470,9 @@ class JavascriptParser extends Parser {
|
|
|
4931
5470
|
onUnhandled
|
|
4932
5471
|
) {
|
|
4933
5472
|
if (expression.object.type === "MemberExpression") {
|
|
4934
|
-
//
|
|
4935
|
-
//
|
|
4936
|
-
//
|
|
4937
|
-
// extractMemberExpressionChain) since the AST node may be a
|
|
4938
|
-
// TemplateLiteral, which has neither .name nor .value.
|
|
5473
|
+
// A nested MemberExpression keeps its info by calling walkMemberExpression
|
|
5474
|
+
// directly. The property comes from `members` rather than the node, which
|
|
5475
|
+
// may be a TemplateLiteral and carry neither `.name` nor `.value`.
|
|
4939
5476
|
const property = members[members.length - 1];
|
|
4940
5477
|
name = name.slice(0, -property.length - 1);
|
|
4941
5478
|
members.pop();
|
|
@@ -5102,7 +5639,7 @@ class JavascriptParser extends Parser {
|
|
|
5102
5639
|
if (typeof info === "string") {
|
|
5103
5640
|
name = info;
|
|
5104
5641
|
} else {
|
|
5105
|
-
if (!(info
|
|
5642
|
+
if (!JavascriptParser.isVariableInfo(info)) {
|
|
5106
5643
|
if (defined !== undefined) {
|
|
5107
5644
|
return defined();
|
|
5108
5645
|
}
|
|
@@ -5148,7 +5685,7 @@ class JavascriptParser extends Parser {
|
|
|
5148
5685
|
*/
|
|
5149
5686
|
_hasHooksForInfo(hookMap, info) {
|
|
5150
5687
|
if (typeof info === "string") return hookMap.get(info) !== undefined;
|
|
5151
|
-
if (!(info
|
|
5688
|
+
if (!JavascriptParser.isVariableInfo(info)) return false;
|
|
5152
5689
|
let tagInfo = info.tagInfo;
|
|
5153
5690
|
while (tagInfo !== undefined) {
|
|
5154
5691
|
if (hookMap.get(tagInfo.tag) !== undefined) return true;
|
|
@@ -5212,7 +5749,7 @@ class JavascriptParser extends Parser {
|
|
|
5212
5749
|
if (typeof info === "string") {
|
|
5213
5750
|
name = info;
|
|
5214
5751
|
} else {
|
|
5215
|
-
if (!(info
|
|
5752
|
+
if (!JavascriptParser.isVariableInfo(info)) {
|
|
5216
5753
|
return;
|
|
5217
5754
|
}
|
|
5218
5755
|
let tagInfo = info.tagInfo;
|
|
@@ -5389,6 +5926,37 @@ class JavascriptParser extends Parser {
|
|
|
5389
5926
|
return oldScope;
|
|
5390
5927
|
}
|
|
5391
5928
|
|
|
5929
|
+
/**
|
|
5930
|
+
* The directive a statement spells, or `undefined` when it is not one. An
|
|
5931
|
+
* AST webpack did not parse may leave the metadata off a directive, so the
|
|
5932
|
+
* spelling is recovered from the literal itself there.
|
|
5933
|
+
* @param {Directive | Statement | ModuleDeclaration} statement statement
|
|
5934
|
+
* @returns {string | undefined} the spelling between the quotes
|
|
5935
|
+
*/
|
|
5936
|
+
getDirective(statement) {
|
|
5937
|
+
if (statement.type !== "ExpressionStatement") return undefined;
|
|
5938
|
+
const directive = /** @type {Directive} */ (statement).directive;
|
|
5939
|
+
if (directive !== undefined || this._hasParserRecord) return directive;
|
|
5940
|
+
const expression = statement.expression;
|
|
5941
|
+
if (expression.type !== "Literal" || typeof expression.value !== "string") {
|
|
5942
|
+
return undefined;
|
|
5943
|
+
}
|
|
5944
|
+
// a parenthesized string is an expression rather than a directive, and
|
|
5945
|
+
// only the statement says so — the literal starts inside the parentheses
|
|
5946
|
+
if (
|
|
5947
|
+
statement.range !== undefined &&
|
|
5948
|
+
expression.range !== undefined &&
|
|
5949
|
+
statement.range[0] !== expression.range[0]
|
|
5950
|
+
) {
|
|
5951
|
+
return undefined;
|
|
5952
|
+
}
|
|
5953
|
+
// the raw text keeps an escape unexpanded, which is what separates a
|
|
5954
|
+
// directive from a string that merely reads like one
|
|
5955
|
+
return expression.raw === undefined
|
|
5956
|
+
? expression.value
|
|
5957
|
+
: expression.raw.slice(1, -1);
|
|
5958
|
+
}
|
|
5959
|
+
|
|
5392
5960
|
/**
|
|
5393
5961
|
* Processes the provided statement.
|
|
5394
5962
|
* @param {(Directive | Statement | ModuleDeclaration)[]} statements statements
|
|
@@ -5403,11 +5971,17 @@ class JavascriptParser extends Parser {
|
|
|
5403
5971
|
return;
|
|
5404
5972
|
}
|
|
5405
5973
|
const value = /** @type {Literal} */ (statement.expression).value;
|
|
5406
|
-
if (value === "use
|
|
5407
|
-
this.scope.isStrict = true;
|
|
5408
|
-
} else if (value === "use asm") {
|
|
5974
|
+
if (value === "use asm") {
|
|
5409
5975
|
this.scope.isAsmJs = true;
|
|
5410
5976
|
}
|
|
5977
|
+
for (const directiveStatement of statements) {
|
|
5978
|
+
const directive = this.getDirective(directiveStatement);
|
|
5979
|
+
if (directive === undefined) break;
|
|
5980
|
+
if (directive === "use strict") {
|
|
5981
|
+
this.scope.isStrict = true;
|
|
5982
|
+
break;
|
|
5983
|
+
}
|
|
5984
|
+
}
|
|
5411
5985
|
}
|
|
5412
5986
|
|
|
5413
5987
|
/**
|
|
@@ -5716,6 +6290,13 @@ class JavascriptParser extends Parser {
|
|
|
5716
6290
|
const oldStrictInModuleOutput = this._strictInModuleOutput;
|
|
5717
6291
|
const oldSource = this._source;
|
|
5718
6292
|
const oldLineStarts = this._lineStarts;
|
|
6293
|
+
const oldHasParserRecord = this._hasParserRecord;
|
|
6294
|
+
// WHY: the parser's record of each scope is only the truth for a tree it
|
|
6295
|
+
// just built. A loader's AST, and whatever `module.parser.javascript.parse`
|
|
6296
|
+
// returns, may have been edited after it was read — or built by something
|
|
6297
|
+
// else entirely — so both are collected from instead of trusted.
|
|
6298
|
+
this._hasParserRecord =
|
|
6299
|
+
typeof source !== "object" && typeof this.options.parse !== "function";
|
|
5719
6300
|
// a preparsed AST carries no text, but the build passes the module
|
|
5720
6301
|
// source in the state — offsets still map for it
|
|
5721
6302
|
this._source =
|
|
@@ -5763,11 +6344,13 @@ class JavascriptParser extends Parser {
|
|
|
5763
6344
|
if (this._strictInModuleOutput && this.scope.isStrict) {
|
|
5764
6345
|
this._strictInModuleOutput = false;
|
|
5765
6346
|
}
|
|
5766
|
-
this.
|
|
6347
|
+
this._modulePreWalkDeclarations(
|
|
6348
|
+
moduleDeclarationsOf(ast, this._hasParserRecord)
|
|
6349
|
+
);
|
|
5767
6350
|
this.prevStatement = undefined;
|
|
5768
|
-
this.
|
|
6351
|
+
this._preWalkScope(ast);
|
|
5769
6352
|
this.prevStatement = undefined;
|
|
5770
|
-
this.
|
|
6353
|
+
this._blockPreWalkScope(ast, ast.body);
|
|
5771
6354
|
this.prevStatement = undefined;
|
|
5772
6355
|
this.walkStatements(ast.body);
|
|
5773
6356
|
this.destructuringAssignmentProperties = undefined;
|
|
@@ -5784,6 +6367,7 @@ class JavascriptParser extends Parser {
|
|
|
5784
6367
|
// release — these retain the whole source string and its line table
|
|
5785
6368
|
this._source = oldSource;
|
|
5786
6369
|
this._lineStarts = oldLineStarts;
|
|
6370
|
+
this._hasParserRecord = oldHasParserRecord;
|
|
5787
6371
|
return state;
|
|
5788
6372
|
}
|
|
5789
6373
|
|
|
@@ -5902,10 +6486,9 @@ class JavascriptParser extends Parser {
|
|
|
5902
6486
|
});
|
|
5903
6487
|
}
|
|
5904
6488
|
case "TemplateLiteral":
|
|
5905
|
-
// Thread `commentsStartPos` through the interpolations so a
|
|
5906
|
-
//
|
|
5907
|
-
// the
|
|
5908
|
-
// the inner expression's purity is evaluated.
|
|
6489
|
+
// Thread `commentsStartPos` through the interpolations, so a
|
|
6490
|
+
// `/*#__PURE__*/` inside `${ … }`, or before the first one, is within
|
|
6491
|
+
// the range scanned when the inner expression's purity is judged.
|
|
5909
6492
|
return expr.expressions.every((e) => {
|
|
5910
6493
|
const pureFlag = this.isPure(e, commentsStartPos);
|
|
5911
6494
|
commentsStartPos = /** @type {Range} */ (e.range)[1];
|
|
@@ -5959,17 +6542,13 @@ class JavascriptParser extends Parser {
|
|
|
5959
6542
|
return this.isPure(expr.expression, commentsStartPos);
|
|
5960
6543
|
|
|
5961
6544
|
case "UnaryExpression":
|
|
5962
|
-
//
|
|
5963
|
-
//
|
|
5964
|
-
//
|
|
5965
|
-
//
|
|
5966
|
-
//
|
|
5967
|
-
//
|
|
5968
|
-
//
|
|
5969
|
-
// any user code (objects → true, etc.).
|
|
5970
|
-
// Other operators (`+`, `-`, `~`, `delete`) fall through to
|
|
5971
|
-
// the generic evaluator which can still recognize literal
|
|
5972
|
-
// cases (e.g. `-1`, `+5`).
|
|
6545
|
+
// WHY: these three produce their result without invoking user code on
|
|
6546
|
+
// the operand. `typeof` returns a type tag and never throws, even for an
|
|
6547
|
+
// undeclared identifier, and coerces nothing; `void` evaluates the
|
|
6548
|
+
// operand and discards it, so it is pure exactly when the operand is; and
|
|
6549
|
+
// `!` coerces through ToBoolean, which is defined to call no user code.
|
|
6550
|
+
// `+`, `-`, `~` and `delete` fall through to the generic evaluator, which
|
|
6551
|
+
// still recognizes literal cases such as `-1` and `+5`.
|
|
5973
6552
|
if (
|
|
5974
6553
|
expr.operator === "typeof" ||
|
|
5975
6554
|
expr.operator === "void" ||
|
|
@@ -5983,12 +6562,12 @@ class JavascriptParser extends Parser {
|
|
|
5983
6562
|
return true;
|
|
5984
6563
|
|
|
5985
6564
|
case "BinaryExpression":
|
|
5986
|
-
//
|
|
5987
|
-
//
|
|
5988
|
-
//
|
|
5989
|
-
// `
|
|
5990
|
-
//
|
|
5991
|
-
//
|
|
6565
|
+
// WHY: strict (in)equality compares without coercion and never invokes user
|
|
6566
|
+
// code on its operands, so the result is pure where both sides are. Every
|
|
6567
|
+
// other binary operator may invoke `valueOf`, `toString`,
|
|
6568
|
+
// `[Symbol.hasInstance]` or a Proxy trap, and falls through to the generic
|
|
6569
|
+
// evaluator, which still recognizes the cases where both sides evaluate
|
|
6570
|
+
// to known primitive literals.
|
|
5992
6571
|
if (expr.operator === "===" || expr.operator === "!==") {
|
|
5993
6572
|
return (
|
|
5994
6573
|
this.isPure(expr.left, commentsStartPos) &&
|
|
@@ -6145,6 +6724,50 @@ class JavascriptParser extends Parser {
|
|
|
6145
6724
|
);
|
|
6146
6725
|
}
|
|
6147
6726
|
|
|
6727
|
+
/**
|
|
6728
|
+
* Where the comments written for `statement` begin: the run of comments
|
|
6729
|
+
* before it that whitespace alone separates from it and from each other.
|
|
6730
|
+
* @param {StatementPathItem} statement the statement they belong to
|
|
6731
|
+
* @returns {number} the offset the run starts at, or the statement's own
|
|
6732
|
+
*/
|
|
6733
|
+
getAttachedCommentsStart(statement) {
|
|
6734
|
+
let position = /** @type {Range} */ (statement.range)[0];
|
|
6735
|
+
// what precedes `export function f() {}` is written for the export, and
|
|
6736
|
+
// the export keyword is the token the run would otherwise stop at
|
|
6737
|
+
const path = this.statementPath;
|
|
6738
|
+
if (path !== undefined && path.length > 1) {
|
|
6739
|
+
const outer = path[path.length - 2];
|
|
6740
|
+
if (
|
|
6741
|
+
(outer.type === "ExportNamedDeclaration" ||
|
|
6742
|
+
outer.type === "ExportDefaultDeclaration") &&
|
|
6743
|
+
outer.declaration === statement
|
|
6744
|
+
) {
|
|
6745
|
+
position = /** @type {Range} */ (outer.range)[0];
|
|
6746
|
+
}
|
|
6747
|
+
}
|
|
6748
|
+
const comments = this.comments;
|
|
6749
|
+
if (comments === undefined) return position;
|
|
6750
|
+
const source = this._source;
|
|
6751
|
+
for (
|
|
6752
|
+
let index = binarySearchBounds.le(comments, position, compareCommentEnd);
|
|
6753
|
+
index >= 0;
|
|
6754
|
+
index--
|
|
6755
|
+
) {
|
|
6756
|
+
const range = /** @type {Range} */ (comments[index].range);
|
|
6757
|
+
if (range[1] > position) continue;
|
|
6758
|
+
// with no source to read, nothing can be ruled out, so the run is
|
|
6759
|
+
// taken to reach as far as the comments themselves do
|
|
6760
|
+
if (
|
|
6761
|
+
source !== undefined &&
|
|
6762
|
+
!onlyWhitespaceBetween(source, range[1], position)
|
|
6763
|
+
) {
|
|
6764
|
+
break;
|
|
6765
|
+
}
|
|
6766
|
+
position = range[0];
|
|
6767
|
+
}
|
|
6768
|
+
return position;
|
|
6769
|
+
}
|
|
6770
|
+
|
|
6148
6771
|
/**
|
|
6149
6772
|
* Reports whether `identifier` may occur as a word in the source text of
|
|
6150
6773
|
* `range`. A conservative pre-filter for expensive AST scans: `false` means
|
|
@@ -6327,7 +6950,7 @@ class JavascriptParser extends Parser {
|
|
|
6327
6950
|
*/
|
|
6328
6951
|
getTagData(name, tag) {
|
|
6329
6952
|
const info = this.scope.definitions.get(name);
|
|
6330
|
-
if (info
|
|
6953
|
+
if (JavascriptParser.isVariableInfo(info)) {
|
|
6331
6954
|
let tagInfo = info.tagInfo;
|
|
6332
6955
|
while (tagInfo !== undefined) {
|
|
6333
6956
|
if (tagInfo.tag === tag) return tagInfo.data;
|
|
@@ -6353,7 +6976,7 @@ class JavascriptParser extends Parser {
|
|
|
6353
6976
|
data,
|
|
6354
6977
|
next: undefined
|
|
6355
6978
|
});
|
|
6356
|
-
} else if (oldInfo
|
|
6979
|
+
} else if (JavascriptParser.isVariableInfo(oldInfo)) {
|
|
6357
6980
|
newInfo = new VariableInfo(
|
|
6358
6981
|
oldInfo.declaredScope,
|
|
6359
6982
|
oldInfo.name,
|
|
@@ -6383,7 +7006,7 @@ class JavascriptParser extends Parser {
|
|
|
6383
7006
|
const oldInfo = this.scope.definitions.get(name);
|
|
6384
7007
|
// Don't redefine variable in same scope to keep existing tags
|
|
6385
7008
|
if (
|
|
6386
|
-
oldInfo
|
|
7009
|
+
JavascriptParser.isVariableInfo(oldInfo) &&
|
|
6387
7010
|
oldInfo.declaredScope === this.scope
|
|
6388
7011
|
) {
|
|
6389
7012
|
return;
|
|
@@ -6409,7 +7032,7 @@ class JavascriptParser extends Parser {
|
|
|
6409
7032
|
isVariableDefined(name) {
|
|
6410
7033
|
const info = this.scope.definitions.get(name);
|
|
6411
7034
|
if (info === undefined) return false;
|
|
6412
|
-
if (info
|
|
7035
|
+
if (JavascriptParser.isVariableInfo(info)) {
|
|
6413
7036
|
return !info.isFree();
|
|
6414
7037
|
}
|
|
6415
7038
|
return true;
|
|
@@ -6425,7 +7048,7 @@ class JavascriptParser extends Parser {
|
|
|
6425
7048
|
_isDefinedPlainVariable(name) {
|
|
6426
7049
|
const info = this.scope.definitions.get(name);
|
|
6427
7050
|
if (info === undefined) return false;
|
|
6428
|
-
if (info
|
|
7051
|
+
if (JavascriptParser.isVariableInfo(info)) {
|
|
6429
7052
|
return !(info.isFree() || info.isTagged() || info.tagInfo !== undefined);
|
|
6430
7053
|
}
|
|
6431
7054
|
return true;
|
|
@@ -6488,7 +7111,7 @@ class JavascriptParser extends Parser {
|
|
|
6488
7111
|
/**
|
|
6489
7112
|
* Parses comment options.
|
|
6490
7113
|
* @param {Range} range range of the comment
|
|
6491
|
-
* @returns {{ options:
|
|
7114
|
+
* @returns {{ options: MagicCommentOptions | null, errors: (Error & { comment: Comment })[] | null }} result
|
|
6492
7115
|
*/
|
|
6493
7116
|
parseCommentOptions(range) {
|
|
6494
7117
|
return parseCommentOptionsInRange(
|
|
@@ -6588,7 +7211,7 @@ class JavascriptParser extends Parser {
|
|
|
6588
7211
|
const info = this.getVariableInfo(varName);
|
|
6589
7212
|
/** @type {string} */
|
|
6590
7213
|
let name;
|
|
6591
|
-
if (info
|
|
7214
|
+
if (JavascriptParser.isVariableInfo(info) && info.name) {
|
|
6592
7215
|
if (!info.isFree()) return;
|
|
6593
7216
|
name = info.name;
|
|
6594
7217
|
} else if (typeof info !== "string") {
|
|
@@ -6608,7 +7231,7 @@ class JavascriptParser extends Parser {
|
|
|
6608
7231
|
const info = this.getVariableInfo(varName);
|
|
6609
7232
|
/** @type {string} */
|
|
6610
7233
|
let name;
|
|
6611
|
-
if (info
|
|
7234
|
+
if (JavascriptParser.isVariableInfo(info) && info.name) {
|
|
6612
7235
|
if (!info.isFree() && !info.isTagged()) return;
|
|
6613
7236
|
name = info.name;
|
|
6614
7237
|
} else if (typeof info !== "string") {
|
|
@@ -6719,7 +7342,7 @@ class JavascriptParser extends Parser {
|
|
|
6719
7342
|
*/
|
|
6720
7343
|
_resolveMemberRoot(rootName) {
|
|
6721
7344
|
const info = this.getVariableInfo(rootName);
|
|
6722
|
-
if (info
|
|
7345
|
+
if (JavascriptParser.isVariableInfo(info) && info.name) {
|
|
6723
7346
|
if (!info.isFree() && !info.isTagged()) return;
|
|
6724
7347
|
this._memberRootInfo = info;
|
|
6725
7348
|
return info.name;
|
|
@@ -6850,6 +7473,15 @@ class JavascriptParser extends Parser {
|
|
|
6850
7473
|
);
|
|
6851
7474
|
}
|
|
6852
7475
|
|
|
7476
|
+
/**
|
|
7477
|
+
* Whether a definition is a variable rather than a free name or a scope.
|
|
7478
|
+
* @param {unknown} value a scope definition
|
|
7479
|
+
* @returns {value is VariableInfo} true when the value is a variable
|
|
7480
|
+
*/
|
|
7481
|
+
static isVariableInfo(value) {
|
|
7482
|
+
return value instanceof VariableInfo;
|
|
7483
|
+
}
|
|
7484
|
+
|
|
6853
7485
|
/**
|
|
6854
7486
|
* Get module parse function.
|
|
6855
7487
|
* @param {Compilation} compilation compilation
|
|
@@ -6858,10 +7490,7 @@ class JavascriptParser extends Parser {
|
|
|
6858
7490
|
*/
|
|
6859
7491
|
static _getModuleParseFunction(compilation, module) {
|
|
6860
7492
|
// Get from module if available
|
|
6861
|
-
if (
|
|
6862
|
-
module instanceof NormalModule &&
|
|
6863
|
-
module.parser instanceof JavascriptParser
|
|
6864
|
-
) {
|
|
7493
|
+
if (module.is("normal") && module.parser instanceof JavascriptParser) {
|
|
6865
7494
|
return module.parser.options.parse;
|
|
6866
7495
|
}
|
|
6867
7496
|
|