webpack 5.107.2 → 5.108.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hot/dev-server.js +2 -0
- package/lib/APIPlugin.js +8 -4
- package/lib/CacheFacade.js +7 -0
- package/lib/Chunk.js +4 -0
- package/lib/ChunkGraph.js +30 -9
- package/lib/CircularModulesPlugin.js +190 -0
- package/lib/CleanPlugin.js +2 -1
- package/lib/Compilation.js +396 -65
- package/lib/Compiler.js +25 -11
- package/lib/ConcatenationScope.js +10 -3
- package/lib/ContextExclusionPlugin.js +1 -0
- package/lib/ContextModule.js +92 -47
- package/lib/ContextReplacementPlugin.js +4 -0
- package/lib/DefinePlugin.js +89 -15
- package/lib/Dependency.js +111 -7
- package/lib/EntryOptionPlugin.js +39 -2
- package/lib/EntryPlugin.js +2 -0
- package/lib/ExportsInfo.js +314 -73
- package/lib/ExternalModule.js +82 -34
- package/lib/ExternalModuleFactoryPlugin.js +1 -0
- package/lib/ExternalsPlugin.js +1 -0
- package/lib/FileSystemInfo.js +173 -23
- package/lib/FlagAllModulesAsUsedPlugin.js +1 -5
- package/lib/FlagDependencyExportsPlugin.js +23 -0
- package/lib/FlagDependencyUsagePlugin.js +87 -5
- package/lib/FlagEntryExportAsUsedPlugin.js +2 -0
- package/lib/Generator.js +8 -0
- package/lib/HotModuleReplacementPlugin.js +65 -28
- package/lib/IgnorePlugin.js +1 -0
- package/lib/InitFragment.js +5 -0
- package/lib/JavascriptMetaInfoPlugin.js +7 -5
- package/lib/LazyBarrel.js +361 -0
- package/lib/LoaderTargetPlugin.js +1 -0
- package/lib/Module.js +21 -42
- package/lib/ModuleGraph.js +3 -2
- package/lib/ModuleProfile.js +27 -1
- package/lib/ModuleTemplate.js +2 -0
- package/lib/MultiCompiler.js +2 -0
- package/lib/MultiStats.js +1 -0
- package/lib/MultiWatching.js +2 -0
- package/lib/NodeStuffPlugin.js +22 -17
- package/lib/NormalModule.js +142 -80
- package/lib/NormalModuleReplacementPlugin.js +2 -0
- package/lib/PrefetchPlugin.js +2 -0
- package/lib/ProgressPlugin.js +8 -0
- package/lib/ProvidePlugin.js +1 -0
- package/lib/RawModule.js +20 -16
- package/lib/RecordIdsPlugin.js +1 -0
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimePlugin.js +58 -26
- package/lib/RuntimeTemplate.js +278 -21
- package/lib/SelfModuleFactory.js +1 -0
- package/lib/SourceMapDevToolPlugin.js +3 -5
- package/lib/Stats.js +1 -0
- package/lib/Template.js +8 -2
- package/lib/TemplatedPathPlugin.js +473 -131
- package/lib/WarnCaseSensitiveModulesPlugin.js +1 -0
- package/lib/WarnDeprecatedOptionPlugin.js +4 -0
- package/lib/WarnNoModeSetPlugin.js +1 -0
- package/lib/WatchIgnorePlugin.js +1 -0
- package/lib/Watching.js +9 -0
- package/lib/WebpackOptionsApply.js +50 -5
- package/lib/asset/AssetBytesGenerator.js +11 -3
- package/lib/asset/AssetGenerator.js +47 -22
- package/lib/asset/AssetModule.js +47 -0
- package/lib/asset/AssetModulesPlugin.js +14 -14
- package/lib/asset/AssetParser.js +2 -2
- package/lib/asset/AssetSourceGenerator.js +8 -0
- package/lib/asset/RawDataUrlModule.js +12 -13
- package/lib/buildChunkGraph.js +64 -7
- package/lib/bun/BunTargetPlugin.js +48 -0
- package/lib/cache/AddBuildDependenciesPlugin.js +1 -0
- package/lib/cache/AddManagedPathsPlugin.js +3 -0
- package/lib/cache/IdleFileCachePlugin.js +4 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +1 -0
- package/lib/cache/ResolverCachePlugin.js +2 -0
- package/lib/cache/mergeEtags.js +2 -0
- package/lib/cli.js +109 -19
- package/lib/config/browserslistTargetHandler.js +99 -0
- package/lib/config/defaults.js +147 -7
- package/lib/config/defineConfig.js +31 -0
- package/lib/config/normalization.js +5 -0
- package/lib/config/target.js +181 -2
- package/lib/container/ContainerEntryModule.js +15 -14
- package/lib/container/ContainerExposedDependency.js +2 -2
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackDependency.js +5 -7
- package/lib/container/FallbackModule.js +10 -9
- package/lib/container/RemoteModule.js +20 -10
- package/lib/container/RemoteRuntimeModule.js +14 -12
- package/lib/css/CssGenerator.js +353 -327
- package/lib/css/CssInjectStyleRuntimeModule.js +36 -8
- package/lib/css/CssLoadingRuntimeModule.js +118 -47
- package/lib/css/CssModule.js +52 -23
- package/lib/css/CssModulesPlugin.js +107 -124
- package/lib/css/CssParser.js +2759 -2205
- package/lib/css/syntax.js +2859 -0
- package/lib/debug/ProfilingPlugin.js +2 -0
- package/lib/deno/DenoTargetPlugin.js +47 -0
- package/lib/dependencies/AMDDefineDependency.js +22 -17
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +1 -0
- package/lib/dependencies/AMDRequireArrayDependency.js +7 -11
- package/lib/dependencies/AMDRequireContextDependency.js +7 -11
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -0
- package/lib/dependencies/AMDRequireDependency.js +24 -20
- package/lib/dependencies/CachedConstDependency.js +3 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +1 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +79 -31
- package/lib/dependencies/CommonJsExportsDependency.js +21 -16
- package/lib/dependencies/CommonJsExportsParserPlugin.js +230 -7
- package/lib/dependencies/CommonJsFullRequireDependency.js +27 -19
- package/lib/dependencies/CommonJsImportsParserPlugin.js +51 -16
- package/lib/dependencies/CommonJsPlugin.js +1 -1
- package/lib/dependencies/CommonJsRequireContextDependency.js +10 -13
- package/lib/dependencies/CommonJsRequireDependency.js +42 -11
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -14
- package/lib/dependencies/ConstDependency.js +16 -11
- package/lib/dependencies/ContextDependency.js +4 -0
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +23 -14
- package/lib/dependencies/CreateRequireParserPlugin.js +1 -0
- package/lib/dependencies/CreateScriptUrlDependency.js +5 -7
- package/lib/dependencies/CriticalDependencyWarning.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +512 -574
- package/lib/dependencies/CssIcssImportDependency.js +9 -9
- package/lib/dependencies/CssIcssSymbolDependency.js +22 -15
- package/lib/dependencies/CssImportDependency.js +25 -1
- package/lib/dependencies/CssUrlDependency.js +23 -14
- package/lib/dependencies/DllEntryDependency.js +9 -13
- package/lib/dependencies/ExportBindingInitFragment.js +164 -0
- package/lib/dependencies/ExportsInfoDependency.js +12 -12
- package/lib/dependencies/ExternalModuleDependency.js +8 -5
- package/lib/dependencies/ExternalModuleInitFragment.js +7 -5
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +13 -10
- package/lib/dependencies/HarmonyAcceptDependency.js +11 -11
- package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +47 -22
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +28 -2
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +46 -22
- package/lib/dependencies/HarmonyExportExpressionDependency.js +107 -30
- package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -9
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +109 -31
- package/lib/dependencies/HarmonyExportInitFragment.js +18 -15
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +83 -18
- package/lib/dependencies/HarmonyExports.js +4 -1
- package/lib/dependencies/HarmonyImportDependency.js +24 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +110 -74
- package/lib/dependencies/HarmonyImportGuard.js +254 -0
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +18 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +118 -14
- package/lib/dependencies/HarmonyLinkingError.js +1 -0
- package/lib/dependencies/HarmonyModulesPlugin.js +1 -0
- package/lib/dependencies/{HtmlScriptSrcDependency.js → HtmlEntryDependency.js} +261 -109
- package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
- package/lib/dependencies/HtmlInlineScriptDependency.js +17 -13
- package/lib/dependencies/HtmlInlineStyleDependency.js +45 -11
- package/lib/dependencies/ImportContextDependency.js +5 -9
- package/lib/dependencies/ImportDependency.js +44 -2
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -0
- package/lib/dependencies/ImportMetaPlugin.js +74 -30
- package/lib/dependencies/ImportParserPlugin.js +19 -0
- package/lib/dependencies/ImportWeakDependency.js +1 -0
- package/lib/dependencies/JsonExportsDependency.js +9 -9
- package/lib/dependencies/LoaderImportDependency.js +1 -0
- package/lib/dependencies/LocalModule.js +11 -12
- package/lib/dependencies/LocalModuleDependency.js +11 -13
- package/lib/dependencies/ModuleDecoratorDependency.js +9 -9
- package/lib/dependencies/ModuleDependency.js +7 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +1 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +15 -11
- package/lib/dependencies/ProvidedDependency.js +31 -27
- package/lib/dependencies/PureExpressionDependency.js +7 -9
- package/lib/dependencies/RequireEnsureDependency.js +12 -13
- package/lib/dependencies/RequireHeaderDependency.js +3 -4
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
- package/lib/dependencies/RequireResolveContextDependency.js +7 -11
- package/lib/dependencies/RequireResolveDependency.js +1 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +3 -5
- package/lib/dependencies/RuntimeRequirementsDependency.js +6 -7
- package/lib/dependencies/StaticExportsDependency.js +10 -10
- package/lib/dependencies/SystemPlugin.js +2 -0
- package/lib/dependencies/URLContextDependency.js +5 -7
- package/lib/dependencies/URLDependency.js +14 -16
- package/lib/dependencies/UnsupportedDependency.js +8 -13
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +11 -16
- package/lib/dependencies/WebAssemblyImportDependency.js +14 -16
- package/lib/dependencies/WebpackIsIncludedDependency.js +1 -0
- package/lib/dependencies/WorkerDependency.js +19 -8
- package/lib/dependencies/WorkerPlugin.js +22 -6
- package/lib/dependencies/processExportInfo.js +13 -11
- package/lib/dll/DelegatedModule.js +29 -15
- package/lib/dll/DelegatedModuleFactoryPlugin.js +1 -0
- package/lib/dll/DelegatedPlugin.js +1 -0
- package/lib/dll/DllEntryPlugin.js +3 -0
- package/lib/dll/DllModule.js +3 -2
- package/lib/dll/DllPlugin.js +16 -0
- package/lib/dll/DllReferencePlugin.js +3 -0
- package/lib/dll/LibManifestPlugin.js +1 -0
- package/lib/electron/ElectronTargetPlugin.js +22 -4
- package/lib/errors/ConcurrentCompilationError.js +1 -0
- package/lib/errors/HookWebpackError.js +11 -13
- package/lib/errors/IgnoreErrorModuleFactory.js +1 -0
- package/lib/errors/InvalidDependenciesModuleWarning.js +2 -0
- package/lib/errors/JSONParseError.js +9 -8
- package/lib/errors/ModuleBuildError.js +16 -13
- package/lib/errors/ModuleDependencyError.js +8 -1
- package/lib/errors/ModuleDependencyWarning.js +8 -1
- package/lib/errors/ModuleError.js +5 -11
- package/lib/errors/ModuleHashingError.js +4 -0
- package/lib/errors/ModuleNotFoundError.js +3 -0
- package/lib/errors/ModuleParseError.js +5 -11
- package/lib/errors/ModuleRestoreError.js +2 -0
- package/lib/errors/ModuleStoreError.js +3 -0
- package/lib/errors/ModuleWarning.js +7 -11
- package/lib/errors/NodeStuffInWebError.js +1 -0
- package/lib/errors/NonErrorEmittedError.js +2 -0
- package/lib/errors/UnhandledSchemeError.js +1 -0
- package/lib/esm/ModuleChunkLoadingPlugin.js +0 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +28 -23
- package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +7 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
- package/lib/hmr/LazyCompilationPlugin.js +30 -6
- package/lib/html/HtmlGenerator.js +217 -23
- package/lib/html/HtmlModule.js +40 -0
- package/lib/html/HtmlModulesPlugin.js +219 -55
- package/lib/html/HtmlParser.js +1108 -1099
- package/lib/html/{walkHtmlTokens.js → syntax.js} +4701 -212
- package/lib/ids/IdHelpers.js +4 -2
- package/lib/index.js +19 -0
- package/lib/javascript/BasicEvaluatedExpression.js +1 -0
- package/lib/javascript/EnableChunkLoadingPlugin.js +1 -0
- package/lib/javascript/JavascriptGenerator.js +6 -2
- package/lib/javascript/JavascriptModule.js +54 -0
- package/lib/javascript/JavascriptModulesPlugin.js +257 -102
- package/lib/javascript/JavascriptParser.js +285 -158
- package/lib/json/JsonModule.js +40 -0
- package/lib/json/JsonModulesPlugin.js +7 -0
- package/lib/json/JsonParser.js +4 -2
- package/lib/library/AssignLibraryPlugin.js +5 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -0
- package/lib/library/FalseIIFEUmdWarning.js +1 -0
- package/lib/library/ModuleLibraryPlugin.js +24 -5
- package/lib/library/SystemLibraryPlugin.js +3 -3
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/node/NodeWatchFileSystem.js +1 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -9
- package/lib/node/RequireChunkLoadingRuntimeModule.js +18 -16
- package/lib/optimize/ConcatenatedModule.js +395 -77
- package/lib/optimize/ConstExportsPlugin.js +211 -0
- package/lib/optimize/InlineExports.js +178 -0
- package/lib/optimize/InnerGraph.js +372 -275
- package/lib/optimize/InnerGraphPlugin.js +196 -99
- package/lib/optimize/ModuleConcatenationPlugin.js +56 -25
- package/lib/optimize/RealContentHashPlugin.js +14 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +234 -64
- package/lib/runtime/AsyncModuleRuntimeModule.js +32 -30
- package/lib/runtime/AutoPublicPathRuntimeModule.js +11 -5
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +6 -4
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +33 -4
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +82 -3
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +18 -13
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +39 -26
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
- package/lib/runtime/RelativeUrlRuntimeModule.js +3 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
- package/lib/runtime/StartupEntrypointRuntimeModule.js +4 -3
- package/lib/runtime/WorkerRuntimeModule.js +33 -0
- package/lib/schemes/HttpUriPlugin.js +3 -2
- package/lib/serialization/AggregateErrorSerializer.js +7 -6
- package/lib/serialization/ArraySerializer.js +4 -8
- package/lib/serialization/BinaryMiddleware.js +538 -468
- package/lib/serialization/DateObjectSerializer.js +2 -2
- package/lib/serialization/ErrorObjectSerializer.js +7 -6
- package/lib/serialization/MapObjectSerializer.js +5 -9
- package/lib/serialization/NullPrototypeObjectSerializer.js +7 -9
- package/lib/serialization/ObjectMiddleware.js +50 -13
- package/lib/serialization/PlainObjectSerializer.js +9 -8
- package/lib/serialization/RegExpObjectSerializer.js +2 -2
- package/lib/serialization/Serializer.js +1 -0
- package/lib/serialization/SetObjectSerializer.js +4 -8
- package/lib/sharing/ConsumeSharedModule.js +6 -7
- package/lib/sharing/ConsumeSharedPlugin.js +1 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +46 -41
- package/lib/sharing/ProvideSharedDependency.js +30 -15
- package/lib/sharing/ProvideSharedModule.js +30 -11
- package/lib/sharing/ProvideSharedPlugin.js +4 -2
- package/lib/sharing/SharePlugin.js +3 -0
- package/lib/sharing/ShareRuntimeModule.js +18 -16
- package/lib/sharing/resolveMatchedConfigs.js +2 -1
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +4 -6
- package/lib/stats/DefaultStatsPrinterPlugin.js +14 -14
- package/lib/stats/StatsFactory.js +11 -9
- package/lib/stats/StatsPrinter.js +9 -2
- package/lib/url/URLParserPlugin.js +5 -2
- package/lib/util/AsyncQueue.js +10 -0
- package/lib/util/LazyBucketSortedSet.js +5 -0
- package/lib/util/LazySet.js +6 -4
- package/lib/util/LocConverter.js +11 -1
- package/lib/util/Semaphore.js +1 -0
- package/lib/util/SourceProcessor.js +106 -0
- package/lib/util/TupleSet.js +1 -0
- package/lib/util/WeakTupleMap.js +27 -1
- package/lib/util/chainedImports.js +3 -3
- package/lib/util/comparators.js +2 -2
- package/lib/util/concatenate.js +31 -7
- package/lib/util/createHash.js +0 -1
- package/lib/util/deterministicGrouping.js +19 -12
- package/lib/util/extractSourceMap.js +1 -1
- package/lib/util/findGraphRoots.js +2 -0
- package/lib/util/fs.js +10 -5
- package/lib/util/hash/DebugHash.js +1 -0
- package/lib/util/hash/hash-digest.js +24 -15
- package/lib/util/identifier.js +7 -0
- package/lib/util/internalSerializables.js +11 -2
- package/lib/util/magicComment.js +42 -0
- package/lib/util/makeSerializable.js +1 -0
- package/lib/util/nonNumericOnlyHash.js +30 -1
- package/lib/util/property.js +7 -1
- package/lib/util/publicPathPlaceholder.js +64 -0
- package/lib/util/registerExternalSerializer.js +4 -4
- package/lib/wasm-async/AsyncWasmModule.js +77 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -96
- package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +1 -1
- package/lib/wasm-sync/SyncWasmModule.js +39 -0
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +1 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -3
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +10 -0
- package/lib/wasm-sync/WebAssemblyParser.js +7 -3
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +45 -39
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +11 -10
- package/package.json +35 -27
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +212 -3
- package/schemas/plugins/HtmlGeneratorOptions.check.js +1 -1
- package/schemas/plugins/HtmlParserOptions.check.d.ts +7 -0
- package/schemas/plugins/HtmlParserOptions.check.js +6 -0
- package/schemas/plugins/HtmlParserOptions.json +3 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/types.d.ts +1456 -290
- package/lib/css/walkCssTokens.js +0 -2020
- package/lib/util/AppendOnlyStackedSet.js +0 -93
|
@@ -1689,8 +1689,8 @@ class DefaultStatsPrinterPlugin {
|
|
|
1689
1689
|
Object.keys(COMPILATION_SIMPLE_PRINTERS)
|
|
1690
1690
|
)) {
|
|
1691
1691
|
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
|
|
1692
|
-
/** @type {
|
|
1693
|
-
(COMPILATION_SIMPLE_PRINTERS
|
|
1692
|
+
/** @type {NonNullable<CompilationSimplePrinters[keyof CompilationSimplePrinters]>} */
|
|
1693
|
+
(COMPILATION_SIMPLE_PRINTERS[key])(
|
|
1694
1694
|
obj,
|
|
1695
1695
|
/** @type {DefineStatsPrinterContext<"compilation">} */
|
|
1696
1696
|
(ctx),
|
|
@@ -1717,8 +1717,8 @@ class DefaultStatsPrinterPlugin {
|
|
|
1717
1717
|
Object.keys(MODULE_SIMPLE_PRINTERS)
|
|
1718
1718
|
)) {
|
|
1719
1719
|
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
|
|
1720
|
-
/** @type {EXPECTED_ANY} */
|
|
1721
|
-
(MODULE_SIMPLE_PRINTERS
|
|
1720
|
+
/** @type {SimplePrinter<EXPECTED_ANY, "module">} */
|
|
1721
|
+
(MODULE_SIMPLE_PRINTERS[key])(
|
|
1722
1722
|
obj,
|
|
1723
1723
|
/** @type {DefineStatsPrinterContext<"module">} */
|
|
1724
1724
|
(ctx),
|
|
@@ -1745,8 +1745,8 @@ class DefaultStatsPrinterPlugin {
|
|
|
1745
1745
|
Object.keys(MODULE_REASON_PRINTERS)
|
|
1746
1746
|
)) {
|
|
1747
1747
|
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
|
|
1748
|
-
/** @type {EXPECTED_ANY} */
|
|
1749
|
-
(MODULE_REASON_PRINTERS
|
|
1748
|
+
/** @type {SimplePrinter<EXPECTED_ANY, "moduleReason">} */
|
|
1749
|
+
(MODULE_REASON_PRINTERS[key])(
|
|
1750
1750
|
obj,
|
|
1751
1751
|
/** @type {DefineStatsPrinterContext<"moduleReason">} */
|
|
1752
1752
|
(ctx),
|
|
@@ -1773,8 +1773,8 @@ class DefaultStatsPrinterPlugin {
|
|
|
1773
1773
|
Object.keys(CHUNK_GROUP_PRINTERS)
|
|
1774
1774
|
)) {
|
|
1775
1775
|
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
|
|
1776
|
-
/** @type {EXPECTED_ANY} */
|
|
1777
|
-
(CHUNK_GROUP_PRINTERS
|
|
1776
|
+
/** @type {SimplePrinter<EXPECTED_ANY, "chunkGroupKind" | "chunkGroup">} */
|
|
1777
|
+
(CHUNK_GROUP_PRINTERS[key])(
|
|
1778
1778
|
obj,
|
|
1779
1779
|
/** @type {DefineStatsPrinterContext<"chunkGroupKind" | "chunkGroup">} */
|
|
1780
1780
|
(ctx),
|
|
@@ -1787,8 +1787,8 @@ class DefaultStatsPrinterPlugin {
|
|
|
1787
1787
|
Object.keys(CHUNK_PRINTERS)
|
|
1788
1788
|
)) {
|
|
1789
1789
|
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
|
|
1790
|
-
/** @type {EXPECTED_ANY} */
|
|
1791
|
-
(CHUNK_PRINTERS
|
|
1790
|
+
/** @type {SimplePrinter<EXPECTED_ANY, "chunk">} */
|
|
1791
|
+
(CHUNK_PRINTERS[key])(
|
|
1792
1792
|
obj,
|
|
1793
1793
|
/** @type {DefineStatsPrinterContext<"chunk">} */
|
|
1794
1794
|
(ctx),
|
|
@@ -1801,8 +1801,8 @@ class DefaultStatsPrinterPlugin {
|
|
|
1801
1801
|
Object.keys(ERROR_PRINTERS)
|
|
1802
1802
|
)) {
|
|
1803
1803
|
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
|
|
1804
|
-
/** @type {EXPECTED_ANY} */
|
|
1805
|
-
(ERROR_PRINTERS
|
|
1804
|
+
/** @type {SimplePrinter<EXPECTED_ANY, "error">} */
|
|
1805
|
+
(ERROR_PRINTERS[key])(
|
|
1806
1806
|
obj,
|
|
1807
1807
|
/** @type {DefineStatsPrinterContext<"error">} */
|
|
1808
1808
|
(ctx),
|
|
@@ -1815,8 +1815,8 @@ class DefaultStatsPrinterPlugin {
|
|
|
1815
1815
|
Object.keys(LOG_ENTRY_PRINTERS)
|
|
1816
1816
|
)) {
|
|
1817
1817
|
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
|
|
1818
|
-
/** @type {EXPECTED_ANY} */
|
|
1819
|
-
(LOG_ENTRY_PRINTERS
|
|
1818
|
+
/** @type {SimplePrinter<EXPECTED_ANY, "logging">} */
|
|
1819
|
+
(LOG_ENTRY_PRINTERS[key])(
|
|
1820
1820
|
obj,
|
|
1821
1821
|
/** @type {DefineStatsPrinterContext<"logging">} */
|
|
1822
1822
|
(ctx),
|
|
@@ -131,10 +131,11 @@ class StatsFactory {
|
|
|
131
131
|
});
|
|
132
132
|
const hooks = this.hooks;
|
|
133
133
|
this._caches =
|
|
134
|
-
/** @type {{ [Key in keyof StatsFactoryHooks]: Map<string,
|
|
134
|
+
/** @type {{ [Key in keyof StatsFactoryHooks]: StatsFactoryHooks[Key] extends HookMap<infer H> ? Map<string, H[]> : never }} */ ({});
|
|
135
135
|
for (const key of Object.keys(hooks)) {
|
|
136
136
|
this._caches[/** @type {keyof StatsFactoryHooks} */ (key)] = new Map();
|
|
137
137
|
}
|
|
138
|
+
/** @type {boolean} */
|
|
138
139
|
this._inCreate = false;
|
|
139
140
|
}
|
|
140
141
|
|
|
@@ -169,7 +170,7 @@ class StatsFactory {
|
|
|
169
170
|
* Returns hook.
|
|
170
171
|
* @template {StatsFactoryHooks[keyof StatsFactoryHooks]} HM
|
|
171
172
|
* @template {HM extends HookMap<infer H> ? H : never} H
|
|
172
|
-
* @template {H extends import("tapable").Hook<
|
|
173
|
+
* @template {H extends import("tapable").Hook<infer A, infer R> ? R : never} R
|
|
173
174
|
* @param {HM} hookMap hook map
|
|
174
175
|
* @param {Caches<H>} cache cache
|
|
175
176
|
* @param {string} type type
|
|
@@ -188,12 +189,13 @@ class StatsFactory {
|
|
|
188
189
|
* For each level waterfall.
|
|
189
190
|
* @template {StatsFactoryHooks[keyof StatsFactoryHooks]} HM
|
|
190
191
|
* @template {HM extends HookMap<infer H> ? H : never} H
|
|
192
|
+
* @template [D=EXPECTED_ANY]
|
|
191
193
|
* @param {HM} hookMap hook map
|
|
192
194
|
* @param {Caches<H>} cache cache
|
|
193
195
|
* @param {string} type type
|
|
194
|
-
* @param {
|
|
195
|
-
* @param {(hook: H,
|
|
196
|
-
* @returns {
|
|
196
|
+
* @param {D} data data
|
|
197
|
+
* @param {(hook: H, data: D) => D} fn fn
|
|
198
|
+
* @returns {D} data
|
|
197
199
|
* @private
|
|
198
200
|
*/
|
|
199
201
|
_forEachLevelWaterfall(hookMap, cache, type, data, fn) {
|
|
@@ -207,14 +209,14 @@ class StatsFactory {
|
|
|
207
209
|
* For each level filter.
|
|
208
210
|
* @template {StatsFactoryHooks[keyof StatsFactoryHooks]} T
|
|
209
211
|
* @template {T extends HookMap<infer H> ? H : never} H
|
|
210
|
-
* @template
|
|
212
|
+
* @template [D=EXPECTED_ANY]
|
|
211
213
|
* @param {T} hookMap hook map
|
|
212
214
|
* @param {Caches<H>} cache cache
|
|
213
215
|
* @param {string} type type
|
|
214
|
-
* @param {
|
|
215
|
-
* @param {(hook: H, item:
|
|
216
|
+
* @param {D[]} items items
|
|
217
|
+
* @param {(hook: H, item: D, idx: number, i: number) => boolean | void} fn fn
|
|
216
218
|
* @param {boolean} forceClone force clone
|
|
217
|
-
* @returns {
|
|
219
|
+
* @returns {D[]} result for each level
|
|
218
220
|
* @private
|
|
219
221
|
*/
|
|
220
222
|
_forEachLevelFilter(hookMap, cache, type, items, fn, forceClone) {
|
|
@@ -73,6 +73,12 @@ const { HookMap, SyncBailHook, SyncWaterfallHook } = require("tapable");
|
|
|
73
73
|
* @property {(message: string) => string=} formatError
|
|
74
74
|
*/
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Extracts the inner hook type held by a `HookMap`.
|
|
78
|
+
* @template T
|
|
79
|
+
* @typedef {T extends HookMap<infer H> ? H : never} HookMapHook
|
|
80
|
+
*/
|
|
81
|
+
|
|
76
82
|
/** @typedef {KnownStatsPrinterColorFunctions & KnownStatsPrinterFormatters & KnownStatsPrinterContext & Record<string, EXPECTED_ANY>} StatsPrinterContext */
|
|
77
83
|
/** @typedef {StatsPrinterContext & Required<KnownStatsPrinterColorFunctions> & Required<KnownStatsPrinterFormatters> & { type: string }} StatsPrinterContextWithExtra */
|
|
78
84
|
/** @typedef {EXPECTED_ANY} PrintObject */
|
|
@@ -107,8 +113,9 @@ class StatsPrinter {
|
|
|
107
113
|
print: new HookMap(() => new SyncBailHook(["object", "context"])),
|
|
108
114
|
result: new HookMap(() => new SyncWaterfallHook(["result", "context"]))
|
|
109
115
|
});
|
|
110
|
-
/** @type {Map<StatsPrintHooks[keyof StatsPrintHooks], Map<string,
|
|
116
|
+
/** @type {Map<StatsPrintHooks[keyof StatsPrintHooks], Map<string, HookMapHook<StatsPrintHooks[keyof StatsPrintHooks]>[]>>} */
|
|
111
117
|
this._levelHookCache = new Map();
|
|
118
|
+
/** @type {boolean} */
|
|
112
119
|
this._inPrint = false;
|
|
113
120
|
}
|
|
114
121
|
|
|
@@ -149,7 +156,7 @@ class StatsPrinter {
|
|
|
149
156
|
* @private
|
|
150
157
|
* @template {StatsPrintHooks[keyof StatsPrintHooks]} HM
|
|
151
158
|
* @template {HM extends HookMap<infer H> ? H : never} H
|
|
152
|
-
* @template {H extends import("tapable").Hook<
|
|
159
|
+
* @template {H extends import("tapable").Hook<infer A, infer R> ? R : never} R
|
|
153
160
|
* @param {HM} hookMap hook map
|
|
154
161
|
* @param {string} type type
|
|
155
162
|
* @param {(hooK: H) => R | undefined | void} fn fn
|
|
@@ -15,7 +15,7 @@ const CommentCompilationWarning = require("../errors/CommentCompilationWarning")
|
|
|
15
15
|
const UnsupportedFeatureWarning = require("../errors/UnsupportedFeatureWarning");
|
|
16
16
|
const BasicEvaluatedExpression = require("../javascript/BasicEvaluatedExpression");
|
|
17
17
|
const { approve } = require("../javascript/JavascriptParserHelpers");
|
|
18
|
-
const
|
|
18
|
+
const { getInnerGraphUtils } = require("../optimize/InnerGraph");
|
|
19
19
|
|
|
20
20
|
/** @typedef {import("estree").MemberExpression} MemberExpression */
|
|
21
21
|
/** @typedef {import("estree").NewExpression} NewExpressionNode */
|
|
@@ -189,7 +189,10 @@ class URLParserPlugin {
|
|
|
189
189
|
);
|
|
190
190
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
|
191
191
|
parser.state.current.addDependency(dep);
|
|
192
|
-
|
|
192
|
+
getInnerGraphUtils(parser.state.compilation).onUsage(
|
|
193
|
+
parser.state,
|
|
194
|
+
(e) => (dep.usedByExports = e)
|
|
195
|
+
);
|
|
193
196
|
return true;
|
|
194
197
|
}
|
|
195
198
|
|
package/lib/util/AsyncQueue.js
CHANGED
|
@@ -38,6 +38,7 @@ class AsyncQueueEntry {
|
|
|
38
38
|
* @param {Callback<R>} callback the callback
|
|
39
39
|
*/
|
|
40
40
|
constructor(item, callback) {
|
|
41
|
+
/** @type {T} */
|
|
41
42
|
this.item = item;
|
|
42
43
|
/** @type {typeof QUEUED_STATE | typeof PROCESSING_STATE | typeof DONE_STATE} */
|
|
43
44
|
this.state = QUEUED_STATE;
|
|
@@ -82,10 +83,15 @@ class AsyncQueue {
|
|
|
82
83
|
* @param {Processor<T, R>} options.processor async function to process items
|
|
83
84
|
*/
|
|
84
85
|
constructor({ name, context, parallelism, parent, processor, getKey }) {
|
|
86
|
+
/** @type {string | undefined} */
|
|
85
87
|
this._name = name;
|
|
88
|
+
/** @type {string} */
|
|
86
89
|
this._context = context || "normal";
|
|
90
|
+
/** @type {number} */
|
|
87
91
|
this._parallelism = parallelism || 1;
|
|
92
|
+
/** @type {Processor<T, R>} */
|
|
88
93
|
this._processor = processor;
|
|
94
|
+
/** @type {getKey<T, K>} */
|
|
89
95
|
this._getKey =
|
|
90
96
|
getKey ||
|
|
91
97
|
/** @type {getKey<T, K>} */ ((item) => /** @type {T & K} */ (item));
|
|
@@ -95,9 +101,13 @@ class AsyncQueue {
|
|
|
95
101
|
this._queued = new ArrayQueue();
|
|
96
102
|
/** @type {AsyncQueue<T, K, R>[] | undefined} */
|
|
97
103
|
this._children = undefined;
|
|
104
|
+
/** @type {number} */
|
|
98
105
|
this._activeTasks = 0;
|
|
106
|
+
/** @type {boolean} */
|
|
99
107
|
this._willEnsureProcessing = false;
|
|
108
|
+
/** @type {boolean} */
|
|
100
109
|
this._needProcessing = false;
|
|
110
|
+
/** @type {boolean} */
|
|
101
111
|
this._stopped = false;
|
|
102
112
|
/** @type {AsyncQueue<T, K, R>} */
|
|
103
113
|
this._root = parent ? parent._root : this;
|
|
@@ -57,14 +57,19 @@ class LazyBucketSortedSet {
|
|
|
57
57
|
* @param {...Arg<T, K>} args more pairs of getKey and comparator plus optional final comparator for the last layer
|
|
58
58
|
*/
|
|
59
59
|
constructor(getKey, comparator, ...args) {
|
|
60
|
+
/** @type {GetKey<T, K>} */
|
|
60
61
|
this._getKey = getKey;
|
|
62
|
+
/** @type {Arg<T, K>[]} */
|
|
61
63
|
this._innerArgs = args;
|
|
64
|
+
/** @type {boolean} */
|
|
62
65
|
this._leaf = args.length <= 1;
|
|
66
|
+
/** @type {SortableSet<K>} */
|
|
63
67
|
this._keys = new SortableSet(undefined, comparator);
|
|
64
68
|
/** @type {Map<K, Entry<T, K>>} */
|
|
65
69
|
this._map = new Map();
|
|
66
70
|
/** @type {Set<T>} */
|
|
67
71
|
this._unsortedItems = new Set();
|
|
72
|
+
/** @type {number} */
|
|
68
73
|
this.size = 0;
|
|
69
74
|
}
|
|
70
75
|
|
package/lib/util/LazySet.js
CHANGED
|
@@ -67,7 +67,9 @@ class LazySet {
|
|
|
67
67
|
this._toMerge = new Set();
|
|
68
68
|
/** @type {LazySet<T>[]} */
|
|
69
69
|
this._toDeepMerge = [];
|
|
70
|
+
/** @type {boolean} */
|
|
70
71
|
this._needMerge = false;
|
|
72
|
+
/** @type {boolean} */
|
|
71
73
|
this._deopt = false;
|
|
72
74
|
}
|
|
73
75
|
|
|
@@ -245,7 +247,7 @@ class LazySet {
|
|
|
245
247
|
/**
|
|
246
248
|
* Serializes the fully materialized set contents into webpack's object
|
|
247
249
|
* serialization stream.
|
|
248
|
-
* @param {import("../serialization/ObjectMiddleware").ObjectSerializerContext} context context
|
|
250
|
+
* @param {import("../serialization/ObjectMiddleware").ObjectSerializerContext<(number | T)[]>} context context
|
|
249
251
|
*/
|
|
250
252
|
serialize({ write }) {
|
|
251
253
|
if (this._needMerge) this._merge();
|
|
@@ -256,15 +258,15 @@ class LazySet {
|
|
|
256
258
|
/**
|
|
257
259
|
* Restores a `LazySet` from serialized item data.
|
|
258
260
|
* @template T
|
|
259
|
-
* @param {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} context context
|
|
261
|
+
* @param {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<(number | T)[]>} context context
|
|
260
262
|
* @returns {LazySet<T>} lazy set
|
|
261
263
|
*/
|
|
262
264
|
static deserialize({ read }) {
|
|
263
|
-
const count = read();
|
|
265
|
+
const count = /** @type {number} */ (read());
|
|
264
266
|
/** @type {T[]} */
|
|
265
267
|
const items = [];
|
|
266
268
|
for (let i = 0; i < count; i++) {
|
|
267
|
-
items.push(read());
|
|
269
|
+
items.push(/** @type {T} */ (read()));
|
|
268
270
|
}
|
|
269
271
|
return new LazySet(items);
|
|
270
272
|
}
|
package/lib/util/LocConverter.js
CHANGED
|
@@ -11,9 +11,13 @@ class LocConverter {
|
|
|
11
11
|
* @param {string} input input
|
|
12
12
|
*/
|
|
13
13
|
constructor(input) {
|
|
14
|
+
/** @type {string} */
|
|
14
15
|
this._input = input;
|
|
16
|
+
/** @type {number} */
|
|
15
17
|
this.line = 1;
|
|
18
|
+
/** @type {number} */
|
|
16
19
|
this.column = 0;
|
|
20
|
+
/** @type {number} */
|
|
17
21
|
this.pos = 0;
|
|
18
22
|
}
|
|
19
23
|
|
|
@@ -37,7 +41,13 @@ class LocConverter {
|
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
} else {
|
|
40
|
-
|
|
44
|
+
// Retreat: count newlines crossed in (pos, this.pos), i.e.
|
|
45
|
+
// exclude the newline at `this.pos` itself. By convention a
|
|
46
|
+
// `\n` is the last column of its line, so when `this.pos`
|
|
47
|
+
// sits on one we're already on the line containing it; only
|
|
48
|
+
// newlines strictly **before** `this.pos` and at-or-after
|
|
49
|
+
// `pos` represent crossed line boundaries.
|
|
50
|
+
let i = this._input.lastIndexOf("\n", this.pos - 1);
|
|
41
51
|
while (i >= pos) {
|
|
42
52
|
this.line--;
|
|
43
53
|
i = i > 0 ? this._input.lastIndexOf("\n", i - 1) : -1;
|
package/lib/util/Semaphore.js
CHANGED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Babel-style visitor map keyed by a numeric node-type discriminator; a bucket
|
|
9
|
+
* is a function (enter-only) or `{ enter?, exit? }`. `ctx.skipChildren()`
|
|
10
|
+
* (enter only) stops the walker descending into the node's children.
|
|
11
|
+
* @typedef {{ skipChildren(): void }} VisitorContext
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* @template TNode
|
|
15
|
+
* @typedef {(node: TNode, parent: TNode | null, ctx: VisitorContext) => void} VisitorFn
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* @template TNode
|
|
19
|
+
* @typedef {VisitorFn<TNode> | { enter?: VisitorFn<TNode>, exit?: VisitorFn<TNode> }} VisitorBucket
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* @template TNode
|
|
23
|
+
* @typedef {{ [nodeType: number]: VisitorBucket<TNode> }} VisitorMap
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* @template TNode
|
|
27
|
+
* @typedef {{ enter: VisitorFn<TNode>[], exit: VisitorFn<TNode>[] }} CompiledVisitorBucket
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* @template TNode
|
|
31
|
+
* @typedef {CompiledVisitorBucket<TNode>[]} CompiledVisitorMap a sparse array indexed by node type
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* A language grammar: parse `input` and fire the compiled visitors in source
|
|
35
|
+
* order (the grammar owns tokenizing, parsing, and walking).
|
|
36
|
+
* @template TNode
|
|
37
|
+
* @template TProcessOptions
|
|
38
|
+
* @typedef {(input: string, visitors: CompiledVisitorMap<TNode>, options: TProcessOptions) => void} Grammar
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Visitor coordinator: owns the visitor registry and drives a language
|
|
43
|
+
* `grammar` over the source. Language-agnostic — each syntax (CSS, HTML, …)
|
|
44
|
+
* binds its own grammar and node-type enum. Babel-style usage:
|
|
45
|
+
*
|
|
46
|
+
* ```
|
|
47
|
+
* processor.use({ [NodeType.X]: (node) => {}, [NodeType.Y]: { enter, exit } });
|
|
48
|
+
* processor.process(source);
|
|
49
|
+
* ```
|
|
50
|
+
* @template TNode
|
|
51
|
+
* @template [TProcessOptions=object]
|
|
52
|
+
*/
|
|
53
|
+
class SourceProcessor {
|
|
54
|
+
/**
|
|
55
|
+
* @param {Grammar<TNode, TProcessOptions>} grammar the grammar to drive over the source
|
|
56
|
+
*/
|
|
57
|
+
constructor(grammar) {
|
|
58
|
+
/** @type {Grammar<TNode, TProcessOptions>} */
|
|
59
|
+
this._grammar = grammar;
|
|
60
|
+
/** @type {CompiledVisitorMap<TNode>} */
|
|
61
|
+
this._visitors = [];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Register a Babel-style visitor map; calls accumulate per node type.
|
|
66
|
+
* A bucket is a function (= `{ enter }`) or `{ enter?, exit? }`.
|
|
67
|
+
* @param {VisitorMap<TNode>} map visitor map keyed by node type
|
|
68
|
+
* @returns {SourceProcessor<TNode, TProcessOptions>} `this`, for chaining
|
|
69
|
+
*/
|
|
70
|
+
use(map) {
|
|
71
|
+
// `map`'s keys are node-type enum members; `Object.keys` stringifies them,
|
|
72
|
+
// so index the compiled array by the number to match the numeric `node.type`.
|
|
73
|
+
for (const type of Object.keys(map)) {
|
|
74
|
+
const key = Number(type);
|
|
75
|
+
const v = map[key];
|
|
76
|
+
let bucket = this._visitors[key];
|
|
77
|
+
if (!bucket) {
|
|
78
|
+
bucket = { enter: [], exit: [] };
|
|
79
|
+
this._visitors[key] = bucket;
|
|
80
|
+
}
|
|
81
|
+
if (typeof v === "function") {
|
|
82
|
+
bucket.enter.push(v);
|
|
83
|
+
} else {
|
|
84
|
+
if (v.enter) bucket.enter.push(v.enter);
|
|
85
|
+
if (v.exit) bucket.exit.push(v.exit);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Run the grammar over `input`, firing visitors in source order. No
|
|
93
|
+
* AST retained.
|
|
94
|
+
* @param {string} input source text
|
|
95
|
+
* @param {TProcessOptions=} options grammar-specific options
|
|
96
|
+
*/
|
|
97
|
+
process(input, options) {
|
|
98
|
+
this._grammar(
|
|
99
|
+
input,
|
|
100
|
+
this._visitors,
|
|
101
|
+
options || /** @type {TProcessOptions} */ ({})
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
module.exports = SourceProcessor;
|
package/lib/util/TupleSet.js
CHANGED
package/lib/util/WeakTupleMap.js
CHANGED
|
@@ -45,7 +45,10 @@ class WeakTupleMap {
|
|
|
45
45
|
* Initializes an empty tuple trie node with optional value and child maps.
|
|
46
46
|
*/
|
|
47
47
|
constructor() {
|
|
48
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* @private
|
|
50
|
+
* @type {number}
|
|
51
|
+
*/
|
|
49
52
|
this.f = 0;
|
|
50
53
|
/**
|
|
51
54
|
* @private
|
|
@@ -127,6 +130,29 @@ class WeakTupleMap {
|
|
|
127
130
|
return newValue;
|
|
128
131
|
}
|
|
129
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Memoizes `compute(thisArg, ...args)` under the tuple key `[compute,
|
|
135
|
+
* ...args]`, computing it on a miss. Equivalent to `provide(compute, ...args,
|
|
136
|
+
* () => compute(thisArg, ...args))` but without allocating that closure (or an
|
|
137
|
+
* extra rest array) on every call — `ModuleGraph#cached` runs this on hot
|
|
138
|
+
* paths where most calls hit the cache and the closure would be pure waste.
|
|
139
|
+
* @param {(thisArg: EXPECTED_ANY, ...args: K) => V} compute computer, also the first key element
|
|
140
|
+
* @param {EXPECTED_ANY} thisArg first argument passed to `compute`
|
|
141
|
+
* @param {K} args remaining key elements, also passed to `compute`
|
|
142
|
+
* @returns {V} the value
|
|
143
|
+
*/
|
|
144
|
+
cachedProvide(compute, thisArg, args) {
|
|
145
|
+
/** @type {WeakTupleMap<K, V>} */
|
|
146
|
+
let node = this._get(/** @type {ArrayElement<K>} */ (compute));
|
|
147
|
+
for (let i = 0; i < args.length; i++) {
|
|
148
|
+
node = node._get(/** @type {ArrayElement<K>} */ (args[i]));
|
|
149
|
+
}
|
|
150
|
+
if (node._hasValue()) return /** @type {V} */ (node._getValue());
|
|
151
|
+
const newValue = compute(thisArg, ...args);
|
|
152
|
+
node._setValue(newValue);
|
|
153
|
+
return newValue;
|
|
154
|
+
}
|
|
155
|
+
|
|
130
156
|
/**
|
|
131
157
|
* Removes the value stored for the tuple key without pruning the trie.
|
|
132
158
|
* @param {K} args tuple
|
|
@@ -71,8 +71,8 @@ module.exports.getTrimmedIdsAndRange = (
|
|
|
71
71
|
* @returns {string[]} trimmed ids
|
|
72
72
|
*/
|
|
73
73
|
function trimIdsToThoseImported(ids, moduleGraph, dependency) {
|
|
74
|
-
/** @type {string[]} */
|
|
75
|
-
let trimmedIds
|
|
74
|
+
/** @type {string[] | undefined} */
|
|
75
|
+
let trimmedIds;
|
|
76
76
|
let currentExportsInfo = moduleGraph.getExportsInfo(
|
|
77
77
|
/** @type {Module} */ (moduleGraph.getModule(dependency))
|
|
78
78
|
);
|
|
@@ -95,5 +95,5 @@ function trimIdsToThoseImported(ids, moduleGraph, dependency) {
|
|
|
95
95
|
currentExportsInfo = nestedInfo;
|
|
96
96
|
}
|
|
97
97
|
// Never trim to nothing. This can happen for invalid imports (e.g. import { notThere } from "./module", or import { anything } from "./missingModule")
|
|
98
|
-
return trimmedIds.length ? trimmedIds : ids;
|
|
98
|
+
return trimmedIds !== undefined && trimmedIds.length ? trimmedIds : ids;
|
|
99
99
|
}
|
package/lib/util/comparators.js
CHANGED
|
@@ -61,13 +61,13 @@ const createCachedParameterizedComparator = (fn) => {
|
|
|
61
61
|
return (arg) => {
|
|
62
62
|
const cachedResult = map.get(arg);
|
|
63
63
|
if (cachedResult !== undefined) return cachedResult;
|
|
64
|
+
// arrow closure dispatches faster than a bound function on the sort hot path
|
|
64
65
|
/**
|
|
65
|
-
* Returns compare result.
|
|
66
66
|
* @param {T} a first item
|
|
67
67
|
* @param {T} b second item
|
|
68
68
|
* @returns {-1 | 0 | 1} compare result
|
|
69
69
|
*/
|
|
70
|
-
const result = fn
|
|
70
|
+
const result = (a, b) => fn(arg, a, b);
|
|
71
71
|
map.set(arg, result);
|
|
72
72
|
return result;
|
|
73
73
|
};
|
package/lib/util/concatenate.js
CHANGED
|
@@ -68,9 +68,28 @@ const getPathInAst = (ast, node) => {
|
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
if (Array.isArray(ast)) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
// sibling ranges are ordered and disjoint; binary search the container
|
|
72
|
+
let lo = 0;
|
|
73
|
+
let hi = ast.length - 1;
|
|
74
|
+
while (lo <= hi) {
|
|
75
|
+
const mid = (lo + hi) >> 1;
|
|
76
|
+
const item = ast[mid];
|
|
77
|
+
const r = item && item.range;
|
|
78
|
+
if (!r) {
|
|
79
|
+
// holes or range-less nodes: scan the remaining window linearly
|
|
80
|
+
for (let i = lo; i <= hi; i++) {
|
|
81
|
+
const enterResult = enterNode(ast[i]);
|
|
82
|
+
if (enterResult !== undefined) return enterResult;
|
|
83
|
+
}
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (r[0] > nr[0]) {
|
|
87
|
+
hi = mid - 1;
|
|
88
|
+
} else if (nr[0] >= r[1]) {
|
|
89
|
+
lo = mid + 1;
|
|
90
|
+
} else {
|
|
91
|
+
return r[1] >= nr[1] ? enterNode(item) : undefined;
|
|
92
|
+
}
|
|
74
93
|
}
|
|
75
94
|
} else if (ast && typeof ast === "object") {
|
|
76
95
|
const keys =
|
|
@@ -204,7 +223,7 @@ const RESERVED_NAMES = new Set(
|
|
|
204
223
|
);
|
|
205
224
|
|
|
206
225
|
/** @typedef {{ usedNames: UsedNames, alreadyCheckedScopes: ScopeSet }} ScopeInfo */
|
|
207
|
-
/** @typedef {Map<string, ScopeInfo
|
|
226
|
+
/** @typedef {Map<string, Map<string, ScopeInfo>>} UsedNamesInScopeInfo */
|
|
208
227
|
|
|
209
228
|
/**
|
|
210
229
|
* Gets used names in scope info.
|
|
@@ -214,14 +233,19 @@ const RESERVED_NAMES = new Set(
|
|
|
214
233
|
* @returns {ScopeInfo} info
|
|
215
234
|
*/
|
|
216
235
|
const getUsedNamesInScopeInfo = (usedNamesInScopeInfo, module, id) => {
|
|
217
|
-
|
|
218
|
-
let
|
|
236
|
+
// nested maps avoid building a `${module}-${id}` key string per lookup
|
|
237
|
+
let byId = usedNamesInScopeInfo.get(module);
|
|
238
|
+
if (byId === undefined) {
|
|
239
|
+
byId = new Map();
|
|
240
|
+
usedNamesInScopeInfo.set(module, byId);
|
|
241
|
+
}
|
|
242
|
+
let info = byId.get(id);
|
|
219
243
|
if (info === undefined) {
|
|
220
244
|
info = {
|
|
221
245
|
usedNames: new Set(),
|
|
222
246
|
alreadyCheckedScopes: new Set()
|
|
223
247
|
};
|
|
224
|
-
|
|
248
|
+
byId.set(id, info);
|
|
225
249
|
}
|
|
226
250
|
return info;
|
|
227
251
|
};
|
package/lib/util/createHash.js
CHANGED