@depup/webpack 5.110.1-depup.0 → 5.111.1-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -8
- package/changes.json +7 -11
- package/lib/APIPlugin.js +26 -11
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/Cache.js +8 -3
- package/lib/CacheFacade.js +1 -1
- package/lib/ChunkGraph.js +20 -18
- package/lib/CircularModulesPlugin.js +157 -55
- package/lib/CleanPlugin.js +2 -2
- package/lib/CompatibilityPlugin.js +3 -4
- package/lib/Compilation.js +337 -338
- package/lib/Compiler.js +213 -51
- package/lib/ConcatenationScope.js +25 -35
- package/lib/ConstPlugin.js +16 -132
- package/lib/CopyPlugin.js +1054 -0
- package/lib/DefinePlugin.js +24 -8
- package/lib/DependencyTemplate.js +2 -1
- package/lib/DotenvPlugin.js +64 -40
- package/lib/ErrorHelpers.js +113 -0
- package/lib/ExportsInfo.js +30 -16
- package/lib/ExternalModule.js +47 -22
- package/lib/FileSystemInfo.js +17 -14
- package/lib/FlagDependencyExportsPlugin.js +53 -34
- package/lib/FlagDependencyUsagePlugin.js +17 -15
- package/lib/Generator.js +24 -2
- package/lib/HotModuleReplacementPlugin.js +55 -7
- package/lib/IgnorePlugin.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +5 -3
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/MainTemplate.js +5 -1
- package/lib/Module.js +19 -10
- package/lib/ModuleGraph.js +6 -9
- package/lib/MultiCompiler.js +7 -17
- package/lib/MultiWatching.js +1 -1
- package/lib/NormalModule.js +148 -70
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/RuntimeGlobals.js +21 -7
- package/lib/RuntimeModule.js +28 -12
- package/lib/RuntimePlugin.js +33 -3
- package/lib/RuntimeTemplate.js +1147 -847
- package/lib/SourceMapDevToolPlugin.js +54 -104
- package/lib/TemplatedPathPlugin.js +16 -59
- package/lib/Watching.js +9 -0
- package/lib/WebpackOptionsApply.js +84 -91
- package/lib/asset/AssetBytesGenerator.js +7 -1
- package/lib/asset/AssetGenerator.js +50 -24
- package/lib/asset/AssetModule.js +3 -0
- package/lib/asset/AssetSourceGenerator.js +7 -1
- package/lib/asset/WebManifestParser.js +7 -5
- package/lib/async-modules/AsyncModuleHelpers.js +10 -4
- package/lib/buildChunkGraph.js +11 -15
- package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
- package/lib/cache/IdleFileCachePlugin.js +2 -2
- package/lib/cache/MemoryCachePlugin.js +4 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
- package/lib/cache/PackFileCacheStrategy.js +17 -19
- package/lib/cache/getLazyHashedEtag.js +3 -5
- package/lib/config/browserslistTargetHandler.js +17 -4
- package/lib/config/defaults.js +162 -142
- package/lib/config/getClaimedAssetTypes.js +10 -11
- package/lib/config/normalization.js +100 -20
- package/lib/config/target.js +13 -4
- package/lib/container/ContainerReferencePlugin.js +6 -0
- package/lib/container/RemoteRuntimeModule.js +9 -0
- package/lib/container/declaredRemotes.js +39 -0
- package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
- package/lib/{ContextModule.js → context/ContextModule.js} +54 -115
- package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
- package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
- package/lib/css/CssGenerator.js +27 -11
- package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
- package/lib/css/CssLoadingRuntimeModule.js +92 -15
- package/lib/css/CssModule.js +1 -1
- package/lib/css/CssModulesPlugin.js +3 -10
- package/lib/css/CssParser.js +162 -31
- package/lib/css/CssServerStylesRuntimeModule.js +9 -0
- package/lib/css/cssMinify.js +43 -32
- package/lib/css/data.js +3526 -871
- package/lib/css/syntax.js +6455 -1237
- package/lib/debug/ProfilingPlugin.js +7 -4
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
- package/lib/dependencies/AMDRuntimeModules.js +18 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +13 -12
- package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
- package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -5
- package/lib/dependencies/CommonJsPlugin.js +19 -3
- package/lib/dependencies/CommonJsRequireDependency.js +32 -9
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -9
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +20 -7
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/CssIcssExportDependency.js +13 -9
- package/lib/dependencies/CssIcssImportDependency.js +3 -6
- package/lib/dependencies/CssUrlDependency.js +3 -5
- package/lib/dependencies/HarmonyCompatibilityDependency.js +67 -22
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +10 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -7
- package/lib/dependencies/HarmonyExportExpressionDependency.js +47 -33
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +217 -34
- package/lib/dependencies/HarmonyExportInitFragment.js +110 -23
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +25 -58
- package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
- package/lib/dependencies/HarmonyImportDependency.js +99 -41
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +198 -25
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +117 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -3
- package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
- package/lib/dependencies/HtmlEntryDependency.js +136 -104
- package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
- package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
- package/lib/dependencies/ImportContextDependency.js +43 -3
- package/lib/dependencies/ImportDependency.js +8 -29
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
- package/lib/dependencies/ImportMetaMainDependency.js +104 -0
- package/lib/dependencies/ImportMetaPlugin.js +67 -25
- package/lib/dependencies/ImportParserPlugin.js +25 -15
- package/lib/dependencies/LoaderPlugin.js +26 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RequireHeaderDependency.js +20 -21
- package/lib/dependencies/SystemRuntimeModule.js +9 -0
- package/lib/dependencies/URLContextDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +6 -5
- package/lib/dependencies/WorkerAndWorkletPlugin.js +16 -21
- package/lib/dependencies/WorkerDependency.js +12 -18
- package/lib/dependencies/WorkletDependency.js +12 -20
- package/lib/dependencies/importOptionsCheck.js +47 -0
- package/lib/dll/DelegatedModule.js +18 -1
- package/lib/dll/DllReferencePlugin.js +11 -8
- package/lib/dll/LibManifestPlugin.js +1 -1
- package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
- package/lib/errors/DotenvFileError.js +29 -0
- package/lib/errors/DuplicateModulesWarning.js +12 -7
- package/lib/errors/EmptyCopyPatternWarning.js +26 -0
- package/lib/errors/ExternalStarReexportError.js +44 -0
- package/lib/errors/HookWebpackError.js +3 -2
- package/lib/errors/ImportedBindingAssignmentError.js +30 -0
- package/lib/errors/MissingSourceMapsWarning.js +36 -0
- package/lib/errors/ModuleParseError.js +2 -1
- package/lib/errors/UnusedAssetsWarning.js +36 -0
- package/lib/errors/UnusedFederationWarning.js +35 -0
- package/lib/errors/UnusedModulesWarning.js +38 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
- package/lib/esm/ModuleChunkLoadingPlugin.js +21 -5
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +91 -53
- package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
- package/lib/hmr/LazyCompilationPlugin.js +3 -5
- package/lib/html/HtmlGenerator.js +72 -87
- package/lib/html/HtmlModulesPlugin.js +479 -215
- package/lib/html/HtmlParser.js +110 -147
- package/lib/html/builtinEmbeddedRenderer.js +107 -0
- package/lib/html/data.js +142 -7
- package/lib/html/htmlMinify.js +92 -122
- package/lib/html/syntax.js +2031 -1556
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/index.js +49 -3
- package/lib/javascript/ChunkFormatHelpers.js +4 -3
- package/lib/javascript/JavascriptGenerator.js +8 -1
- package/lib/javascript/JavascriptModule.js +1 -0
- package/lib/javascript/JavascriptModulesPlugin.js +76 -80
- package/lib/javascript/JavascriptParser.js +1970 -900
- package/lib/javascript/StartupHelpers.js +27 -3
- package/lib/javascript/data.js +172 -0
- package/lib/javascript/grammar.js +5546 -0
- package/lib/javascript/parser.js +1500 -0
- package/lib/javascript/regexp.js +1762 -0
- package/lib/javascript/regexpData.js +51 -0
- package/lib/javascript/syntax.js +9061 -5262
- package/lib/json/JsonGenerator.js +7 -1
- package/lib/library/ModuleLibraryPlugin.js +171 -132
- package/lib/loaders/LoaderRunner.js +170 -14
- package/lib/node/NodeWatchFileSystem.js +3 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -15
- package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
- package/lib/optimize/AggressiveMergingPlugin.js +3 -5
- package/lib/optimize/ConcatenatedModule.js +222 -125
- package/lib/optimize/ConstExportsPlugin.js +50 -34
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
- package/lib/optimize/InlineExports.js +20 -2
- package/lib/optimize/InnerGraphPlugin.js +7 -13
- package/lib/optimize/LimitChunkCountPlugin.js +5 -8
- package/lib/optimize/MangleExportsPlugin.js +13 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +27 -5
- package/lib/optimize/RealContentHashPlugin.js +179 -44
- package/lib/optimize/SideEffectsFlagPlugin.js +24 -28
- package/lib/optimize/SplitChunksPlugin.js +2 -4
- package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
- package/lib/performance/BroadContextsPlugin.js +1 -1
- package/lib/performance/CacheEffectivenessPlugin.js +7 -7
- package/lib/performance/DuplicateModulesPlugin.js +57 -13
- package/lib/performance/EvalUsagePlugin.js +5 -2
- package/lib/performance/MissingSourceMapsPlugin.js +115 -0
- package/lib/performance/PureAnnotationsPlugin.js +6 -3
- package/lib/performance/SizeLimitsPlugin.js +2 -4
- package/lib/performance/TopLevelThisPlugin.js +5 -4
- package/lib/performance/UnusedAssetsPlugin.js +109 -0
- package/lib/performance/UnusedFederationPlugin.js +147 -0
- package/lib/performance/UnusedModulesPlugin.js +141 -0
- package/lib/performance/UnusedReexportsPlugin.js +1 -55
- package/lib/performance/isOnlyReexported.js +65 -0
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +8 -8
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
- package/lib/prefetch/ResourceHintPlugin.js +29 -35
- package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +16 -10
- package/lib/rules/RuleSetCompiler.js +211 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +103 -67
- package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
- package/lib/runtime/BaseUriRuntimeModule.js +9 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +12 -4
- package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
- package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
- package/lib/runtime/GlobalRuntimeModule.js +11 -4
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
- package/lib/runtime/HelperRuntimeModule.js +10 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +313 -222
- package/lib/runtime/NonceRuntimeModule.js +9 -0
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
- package/lib/runtime/PublicPathRuntimeModule.js +9 -0
- package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
- package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
- package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
- package/lib/runtime/SystemContextRuntimeModule.js +9 -0
- package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
- package/lib/schemes/DataUriPlugin.js +3 -6
- package/lib/schemes/HttpUriPlugin.js +22 -5
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +9 -9
- package/lib/serialization/FileMiddleware.js +31 -18
- package/lib/serialization/ObjectMiddleware.js +168 -139
- package/lib/sharing/ConsumeSharedPlugin.js +12 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
- package/lib/sharing/ShareRuntimeModule.js +9 -0
- package/lib/sharing/declaredShared.js +47 -0
- package/lib/stats/DefaultStatsFactoryPlugin.js +6 -5
- package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
- package/lib/typescript/TypeScriptPlugin.js +10 -13
- package/lib/url/URLParserPlugin.js +6 -8
- package/lib/util/ArrayQueue.js +3 -3
- package/lib/util/LocConverter.js +4 -7
- package/lib/util/SourceProcessor.js +115 -99
- package/lib/util/URLAbsoluteSpecifier.js +3 -1
- package/lib/util/async.js +292 -0
- package/lib/util/buildDiagnostics.js +69 -0
- package/lib/util/chainedImports.js +3 -4
- package/lib/util/concatenate.js +4 -4
- package/lib/util/conventions.js +5 -1
- package/lib/util/createHooksRegistry.js +1 -2
- package/lib/util/createMappings.js +25 -3
- package/lib/util/dataURL.js +2 -3
- package/lib/util/deterministicGrouping.js +8 -13
- package/lib/util/findGraphRoots.js +6 -13
- package/lib/util/fs.js +27 -1
- package/lib/util/globUtils.js +1 -1
- package/lib/util/handlerKeys.js +40 -0
- package/lib/util/hash/wasm-hash.js +3 -4
- package/lib/util/identifier.js +20 -0
- package/lib/util/internalSerializables.js +7 -1
- package/lib/util/registerExternalSerializer.js +6 -45
- package/lib/util/removeBOM.js +82 -1
- package/lib/util/semver.js +5 -3
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +14 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +14 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +7 -12
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +12 -4
- package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
- package/lib/web/FetchCompileAsyncWasmPlugin.js +10 -6
- package/lib/web/FetchCompileWasmPlugin.js +4 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
- package/package.json +55 -46
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +388 -76
- package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
- package/schemas/plugins/ManifestPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
- package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/types.d.ts +1795 -608
- package/lib/dependencies/ExportBindingInitFragment.js +0 -191
- package/lib/errors/EntrypointOverlapWarning.js +0 -45
- package/lib/performance/EntrypointOverlapPlugin.js +0 -122
|
@@ -257,10 +257,9 @@ class URLParserPlugin {
|
|
|
257
257
|
relative
|
|
258
258
|
);
|
|
259
259
|
dep.loc = parser.getLocation(expr);
|
|
260
|
-
// `parser.javascript.urlHints`
|
|
261
|
-
//
|
|
262
|
-
//
|
|
263
|
-
// when both are set.
|
|
260
|
+
// `parser.javascript.urlHints` gives the project-wide defaults,
|
|
261
|
+
// resolved per request; a per-URL magic comment for the same hint
|
|
262
|
+
// wins where both are set.
|
|
264
263
|
ResourceHintPlugin.applyResourceHints(
|
|
265
264
|
dep,
|
|
266
265
|
this.options.urlHints,
|
|
@@ -270,10 +269,9 @@ class URLParserPlugin {
|
|
|
270
269
|
parser.getLocation(expr)
|
|
271
270
|
);
|
|
272
271
|
parser.state.current.addDependency(dep);
|
|
273
|
-
//
|
|
274
|
-
//
|
|
275
|
-
//
|
|
276
|
-
// rebuild leaves unaffected can otherwise deadlock the scheduler.
|
|
272
|
+
// The ESM template embeds the asset's resolved filename, so the asset
|
|
273
|
+
// must be code-generated first. Added in that mode only: elsewhere the
|
|
274
|
+
// extra code-gen dependency can deadlock a watch rebuild.
|
|
277
275
|
if (parser.state.compilation.options.output.module) {
|
|
278
276
|
parser.state.module.addCodeGenerationDependency(dep);
|
|
279
277
|
}
|
package/lib/util/ArrayQueue.js
CHANGED
|
@@ -90,11 +90,11 @@ class ArrayQueue {
|
|
|
90
90
|
[Symbol.iterator]() {
|
|
91
91
|
return {
|
|
92
92
|
next: () => {
|
|
93
|
-
|
|
94
|
-
if (
|
|
93
|
+
// length, not truthiness: a queued `0`/`false`/`undefined` is a value
|
|
94
|
+
if (this.length > 0) {
|
|
95
95
|
return {
|
|
96
96
|
done: false,
|
|
97
|
-
value:
|
|
97
|
+
value: /** @type {T} */ (this.dequeue())
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
100
|
return {
|
package/lib/util/LocConverter.js
CHANGED
|
@@ -63,13 +63,10 @@ class LocConverter {
|
|
|
63
63
|
// Retreat on line 1: no `\n` precedes `pos`, the cache stays valid.
|
|
64
64
|
this.column = pos;
|
|
65
65
|
} else {
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
// newlines strictly **before** `this.pos` and at-or-after
|
|
71
|
-
// `pos` represent crossed line boundaries. The smallest
|
|
72
|
-
// crossed one is the next newline after the new position.
|
|
66
|
+
// WHY: A `\n` counts as the last column of its own line here, so a
|
|
67
|
+
// `this.pos` sitting on one is already on that line. Retreating
|
|
68
|
+
// therefore crosses only the newlines at or after `pos` and strictly
|
|
69
|
+
// before `this.pos` — the newline at `this.pos` is not one of them.
|
|
73
70
|
let i = input.lastIndexOf("\n", this.pos - 1);
|
|
74
71
|
while (i >= pos) {
|
|
75
72
|
this._nextNewline = i;
|
|
@@ -99,6 +99,23 @@ const expandDeferredWrites = (text, resolve, infix) => {
|
|
|
99
99
|
return out + text.slice(from);
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
+
/**
|
|
103
|
+
* The text this print spells with every deferred write declined: each marker
|
|
104
|
+
* replaced by what would stand there had no renderer answered. What a print
|
|
105
|
+
* verifying itself by re-parsing has to read, since a marker otherwise parses
|
|
106
|
+
* as text where its node stood. `build` rather than `source` so a write inside
|
|
107
|
+
* an attribute comes back escaped for where it sits.
|
|
108
|
+
* @param {string} text the printed output, holding this print's markers
|
|
109
|
+
* @param {DeferredWrite[]} writes what the print deferred, indexed by id
|
|
110
|
+
* @returns {string} the text with every marker put back
|
|
111
|
+
*/
|
|
112
|
+
const declineDeferredWrites = (text, writes) =>
|
|
113
|
+
expandDeferredWrites(
|
|
114
|
+
text,
|
|
115
|
+
(id) => (id < writes.length ? writes[id].build(undefined) : undefined),
|
|
116
|
+
deferredInfix
|
|
117
|
+
);
|
|
118
|
+
|
|
102
119
|
/**
|
|
103
120
|
* Babel-style visitor map keyed by a numeric node-type discriminator; a bucket
|
|
104
121
|
* is a function (enter-only) or `{ enter?, exit? }`.
|
|
@@ -244,20 +261,20 @@ class PrintContext {
|
|
|
244
261
|
/** @type {NodePrinter<TPath, TNode, TPrintOptions>} */
|
|
245
262
|
this._printer = printer;
|
|
246
263
|
// Printed text by node handle, in two columns rather than one `Map`: the
|
|
247
|
-
// handles are dense integers, and
|
|
248
|
-
// a store that never holds more than a few dozen of them at once.
|
|
264
|
+
// handles are dense integers, and `_moveEpoch` keeps the live set small.
|
|
249
265
|
/** @type {string[]} each finished node's printed text */
|
|
250
266
|
this._storeText = [];
|
|
251
267
|
/** @type {Int32Array} the epoch each slot was written in */
|
|
252
268
|
this._storeGen = new Int32Array(0);
|
|
253
269
|
/** @type {number} current epoch; a slot from an older one reads as absent */
|
|
254
270
|
this._gen = 1;
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
//
|
|
260
|
-
//
|
|
271
|
+
/** @type {number} lowest slot written since the epoch last moved */
|
|
272
|
+
this._storeLow = 0x7fffffff;
|
|
273
|
+
/** @type {number} highest slot written since the epoch last moved */
|
|
274
|
+
this._storeHigh = -1;
|
|
275
|
+
// Output is `_chunks` joined, then `_tail`. Printing that never takes
|
|
276
|
+
// anything back only appends to `_tail`; a piece is cut off into `_chunks`
|
|
277
|
+
// for retractable text alone, so no other emit pays for that ability.
|
|
261
278
|
/** @type {string[]} pieces already cut off, in output order */
|
|
262
279
|
this._chunks = [];
|
|
263
280
|
/** @type {string} output after the last cut piece */
|
|
@@ -268,7 +285,7 @@ class PrintContext {
|
|
|
268
285
|
this._flattened = 0;
|
|
269
286
|
/** @type {[number, number, number, number][]} `[chunkIndex, offsetInChunk, srcLine, srcCol]`, output-ordered; a `srcLine` of -1 is one {@link retract} took back with its piece */
|
|
270
287
|
this._mappings = [];
|
|
271
|
-
/** @type {
|
|
288
|
+
/** @type {number[] | null} by retractable piece index, the mapping anchored to it, so taking the piece back takes its mapping too */
|
|
272
289
|
this._retractableMappings = null;
|
|
273
290
|
// A map is built only for a caller that named the input, and that is known
|
|
274
291
|
// before printing — so a print nobody asks a map of collects none.
|
|
@@ -279,10 +296,9 @@ class PrintContext {
|
|
|
279
296
|
this._inserts = [];
|
|
280
297
|
/** @type {number} next `_inserts` entry not yet flushed */
|
|
281
298
|
this._insertIdx = 0;
|
|
282
|
-
// Openers of the nodes
|
|
283
|
-
//
|
|
284
|
-
//
|
|
285
|
-
// emitting an opener eagerly would give up.
|
|
299
|
+
// Openers of the nodes printed in pieces, innermost last, held back until
|
|
300
|
+
// one has content — which is what lets a node whose children all print to
|
|
301
|
+
// nothing still be dropped whole.
|
|
286
302
|
/** @type {string[]} openers not yet emitted, outermost first */
|
|
287
303
|
this._pending = [];
|
|
288
304
|
/** @type {[number | undefined, number | undefined, number | undefined] | null} anchor for the first pending opener */
|
|
@@ -389,16 +405,14 @@ class PrintContext {
|
|
|
389
405
|
_growStore(need) {
|
|
390
406
|
// From empty: a context that prints one inline `style=""` must not pay for
|
|
391
407
|
// a stylesheet's worth of columns.
|
|
392
|
-
const
|
|
393
|
-
|
|
394
|
-
//
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
for (let i =
|
|
398
|
-
for (let i = held.length; i < size; i++) text.push("");
|
|
408
|
+
const text = this._storeText;
|
|
409
|
+
const size = Math.max(need, text.length * 2, 16);
|
|
410
|
+
// Appended in place: `push` keeps the column packed for the read every
|
|
411
|
+
// composed child makes, and what it already holds never moves — where
|
|
412
|
+
// filling a second array would copy every slot again at each growth.
|
|
413
|
+
for (let i = text.length; i < size; i++) text.push("");
|
|
399
414
|
const gen = new Int32Array(size);
|
|
400
415
|
gen.set(this._storeGen);
|
|
401
|
-
this._storeText = text;
|
|
402
416
|
this._storeGen = gen;
|
|
403
417
|
}
|
|
404
418
|
|
|
@@ -409,8 +423,25 @@ class PrintContext {
|
|
|
409
423
|
* node's text.
|
|
410
424
|
*/
|
|
411
425
|
dropStore() {
|
|
412
|
-
|
|
413
|
-
|
|
426
|
+
this._moveEpoch();
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Move the epoch on and release the text every slot written under the old one
|
|
431
|
+
* holds. Only the range actually written is walked, so the drop stays O(1)
|
|
432
|
+
* per node.
|
|
433
|
+
* @returns {void}
|
|
434
|
+
*/
|
|
435
|
+
_moveEpoch() {
|
|
436
|
+
const high = this._storeHigh;
|
|
437
|
+
if (high !== -1) {
|
|
438
|
+
// `""` rather than a hole: the column is packed, and a hole in it would
|
|
439
|
+
// cost every read after this one.
|
|
440
|
+
const text = this._storeText;
|
|
441
|
+
for (let i = this._storeLow; i <= high; i++) text[i] = "";
|
|
442
|
+
this._storeLow = 0x7fffffff;
|
|
443
|
+
this._storeHigh = -1;
|
|
444
|
+
}
|
|
414
445
|
this._gen++;
|
|
415
446
|
}
|
|
416
447
|
|
|
@@ -454,6 +485,8 @@ class PrintContext {
|
|
|
454
485
|
if (n >= this._storeText.length) this._growStore(n + 1);
|
|
455
486
|
this._storeText[n] = text;
|
|
456
487
|
this._storeGen[n] = this._gen;
|
|
488
|
+
if (n < this._storeLow) this._storeLow = n;
|
|
489
|
+
if (n > this._storeHigh) this._storeHigh = n;
|
|
457
490
|
}
|
|
458
491
|
|
|
459
492
|
/**
|
|
@@ -487,14 +520,12 @@ class PrintContext {
|
|
|
487
520
|
_emit(text) {
|
|
488
521
|
this._tail += text;
|
|
489
522
|
this._tailLength += text.length;
|
|
490
|
-
// A printer returns
|
|
491
|
-
//
|
|
492
|
-
//
|
|
493
|
-
//
|
|
494
|
-
//
|
|
495
|
-
//
|
|
496
|
-
// the result would have paid for anyway, but paying it per piece means an
|
|
497
|
-
// allocation for each, and the pieces are small.
|
|
523
|
+
// WHY: A printer returns a rope of its children's pieces, and appending a
|
|
524
|
+
// rope onto a rope keeps every fragment reachable until the output is
|
|
525
|
+
// flattened — a second copy of a large stylesheet. Cutting the tail once it
|
|
526
|
+
// passes a block forces that block flat and drops the fragments behind it.
|
|
527
|
+
// Per block rather than per piece: the copy is one the result pays anyway,
|
|
528
|
+
// while per piece it would be an allocation each, and the pieces are small.
|
|
498
529
|
if (this._tailLength >= FLATTEN_BLOCK) this._cutTail();
|
|
499
530
|
}
|
|
500
531
|
|
|
@@ -537,7 +568,7 @@ class PrintContext {
|
|
|
537
568
|
retract(index) {
|
|
538
569
|
this._chunks[index] = "";
|
|
539
570
|
if (this._retractableMappings === null) return;
|
|
540
|
-
const mapping = this._retractableMappings
|
|
571
|
+
const mapping = this._retractableMappings[index];
|
|
541
572
|
if (mapping !== undefined) this._mappings[mapping][2] = -1;
|
|
542
573
|
}
|
|
543
574
|
|
|
@@ -583,12 +614,12 @@ class PrintContext {
|
|
|
583
614
|
this.anchor(srcOffset, srcLine, srcCol);
|
|
584
615
|
const mapping = this._mappings.length > before ? before : -1;
|
|
585
616
|
const at = this.emitRetractable(text === undefined ? this.get(node) : text);
|
|
586
|
-
this.
|
|
617
|
+
this._moveEpoch();
|
|
587
618
|
if (mapping !== -1) {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
this._retractableMappings
|
|
619
|
+
// Indexed by piece rather than a `Map`: pieces are dense integers, and
|
|
620
|
+
// nearly every rule minifying goes out as one.
|
|
621
|
+
if (this._retractableMappings === null) this._retractableMappings = [];
|
|
622
|
+
this._retractableMappings[at] = mapping;
|
|
592
623
|
}
|
|
593
624
|
return at;
|
|
594
625
|
}
|
|
@@ -612,7 +643,7 @@ class PrintContext {
|
|
|
612
643
|
this._emit(
|
|
613
644
|
text === undefined ? this.get(/** @type {TNode} */ (node)) : text
|
|
614
645
|
);
|
|
615
|
-
this.
|
|
646
|
+
this._moveEpoch();
|
|
616
647
|
}
|
|
617
648
|
|
|
618
649
|
/**
|
|
@@ -724,68 +755,44 @@ class PrintContext {
|
|
|
724
755
|
|
|
725
756
|
/**
|
|
726
757
|
* @param {SourceMapOptions} options the input's name / content
|
|
758
|
+
* @param {string=} code the output {@link result} built, walked for its line breaks
|
|
727
759
|
* @returns {SourceMap} the input->output source map
|
|
728
760
|
*/
|
|
729
|
-
sourceMap(options) {
|
|
761
|
+
sourceMap(options, code) {
|
|
730
762
|
let out = "";
|
|
731
763
|
let genLine = 0;
|
|
732
764
|
let genCol = 0;
|
|
733
765
|
let srcLine = 0;
|
|
734
766
|
let srcCol = 0;
|
|
735
767
|
let atLineStart = true;
|
|
736
|
-
//
|
|
737
|
-
//
|
|
738
|
-
|
|
739
|
-
// its start, since output accumulates into the piece it is appending to.
|
|
768
|
+
// Walked over the flat output rather than piece by piece: a piece is a rope
|
|
769
|
+
// until something reads it, and reading each one flattens each one.
|
|
770
|
+
const text = code === undefined ? this.result() : code;
|
|
740
771
|
const chunks = this._chunks;
|
|
741
|
-
const tail = this._tail;
|
|
742
|
-
/**
|
|
743
|
-
* @param {number} i piece index, `chunks.length` being the tail
|
|
744
|
-
* @returns {string} that piece
|
|
745
|
-
*/
|
|
746
|
-
const pieceAt = (i) => (i === chunks.length ? tail : chunks[i]);
|
|
747
772
|
let atChunk = 0;
|
|
773
|
+
let chunkStart = 0;
|
|
748
774
|
let atOffset = 0;
|
|
749
775
|
let atLine = 0;
|
|
750
776
|
let atCol = 0;
|
|
751
|
-
// Offset of the next newline at or after the cursor, `-1` for none left
|
|
752
|
-
//
|
|
753
|
-
|
|
754
|
-
// the end of the piece every time — and minified output, the case with no
|
|
755
|
-
// newlines at all, is the one where that is the whole piece.
|
|
756
|
-
let nextNewline = pieceAt(0).indexOf("\n");
|
|
757
|
-
/**
|
|
758
|
-
* @param {string} text the piece to walk
|
|
759
|
-
* @param {number} to offset to walk to
|
|
760
|
-
*/
|
|
761
|
-
const advanceOver = (text, to) => {
|
|
762
|
-
while (nextNewline !== -1 && nextNewline < to) {
|
|
763
|
-
atLine++;
|
|
764
|
-
atCol = 0;
|
|
765
|
-
atOffset = nextNewline + 1;
|
|
766
|
-
nextNewline = text.indexOf("\n", atOffset);
|
|
767
|
-
}
|
|
768
|
-
atCol += to - atOffset;
|
|
769
|
-
atOffset = to;
|
|
770
|
-
};
|
|
771
|
-
/**
|
|
772
|
-
* @param {number} chunk piece index to advance to
|
|
773
|
-
* @param {number} offset offset within it
|
|
774
|
-
*/
|
|
775
|
-
const advanceTo = (chunk, offset) => {
|
|
776
|
-
while (atChunk < chunk) {
|
|
777
|
-
const text = pieceAt(atChunk);
|
|
778
|
-
advanceOver(text, text.length);
|
|
779
|
-
atChunk++;
|
|
780
|
-
atOffset = 0;
|
|
781
|
-
nextNewline = pieceAt(atChunk).indexOf("\n");
|
|
782
|
-
}
|
|
783
|
-
if (offset > atOffset) advanceOver(pieceAt(atChunk), offset);
|
|
784
|
-
};
|
|
777
|
+
// Offset of the next newline at or after the cursor, `-1` for none left.
|
|
778
|
+
// Carried rather than searched for per mapping: `indexOf` has no end bound.
|
|
779
|
+
let nextNewline = text.indexOf("\n");
|
|
785
780
|
for (const [chunkIndex, chunkOffset, sl, sc] of this._mappings) {
|
|
786
781
|
// Its piece was taken back, so there is no output left to anchor.
|
|
787
782
|
if (sl === -1) continue;
|
|
788
|
-
|
|
783
|
+
// A piece's length is stored, so summing them costs nothing per byte.
|
|
784
|
+
while (atChunk < chunkIndex) chunkStart += chunks[atChunk++].length;
|
|
785
|
+
const to = chunkStart + chunkOffset;
|
|
786
|
+
if (to > atOffset) {
|
|
787
|
+
while (nextNewline !== -1 && nextNewline < to) {
|
|
788
|
+
atLine++;
|
|
789
|
+
atCol = 0;
|
|
790
|
+
atOffset = nextNewline + 1;
|
|
791
|
+
nextNewline = text.indexOf("\n", atOffset);
|
|
792
|
+
}
|
|
793
|
+
atCol += to - atOffset;
|
|
794
|
+
atOffset = to;
|
|
795
|
+
}
|
|
789
796
|
const gl = atLine;
|
|
790
797
|
const gc = atCol;
|
|
791
798
|
while (genLine < gl) {
|
|
@@ -900,7 +907,11 @@ class PrintContext {
|
|
|
900
907
|
if (this._insertIdx < this._inserts.length) this._flushBefore(Infinity);
|
|
901
908
|
// Nothing was ever cut into its own piece, so there is nothing to join.
|
|
902
909
|
const chunks = this._chunks;
|
|
903
|
-
|
|
910
|
+
if (chunks.length === 0) return this._tail;
|
|
911
|
+
// The tail joins as a piece of its own, so the output comes back flat
|
|
912
|
+
// rather than as a rope over the join that every reader flattens again.
|
|
913
|
+
this._cutTail();
|
|
914
|
+
return chunks.join("");
|
|
904
915
|
}
|
|
905
916
|
}
|
|
906
917
|
|
|
@@ -1003,10 +1014,9 @@ class SourceProcessor {
|
|
|
1003
1014
|
this._grammar(input, this._visitors, undefined, opts);
|
|
1004
1015
|
return undefined;
|
|
1005
1016
|
}
|
|
1006
|
-
// Handed over whole rather than copied entry by entry: which
|
|
1007
|
-
// print options is the language's to say, and
|
|
1008
|
-
//
|
|
1009
|
-
// along is inert — a printer reads only what its own type declares.
|
|
1017
|
+
// Handed over whole rather than copied entry by entry: which entries are
|
|
1018
|
+
// print options is the language's to say, and a grammar-only one riding
|
|
1019
|
+
// along is inert, since a printer reads only what its own type declares.
|
|
1010
1020
|
const ctx = new PrintContext(
|
|
1011
1021
|
/** @type {PrintOptions & TPrintOptions} */ (
|
|
1012
1022
|
/** @type {unknown} */ ({ ...opts, mode: asked })
|
|
@@ -1015,16 +1025,21 @@ class SourceProcessor {
|
|
|
1015
1025
|
);
|
|
1016
1026
|
this._grammar(input, this._visitors, ctx, opts);
|
|
1017
1027
|
const name = /** @type {{ source?: string, content?: string }} */ (opts);
|
|
1018
|
-
const build = () =>
|
|
1019
|
-
code
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
+
const build = () => {
|
|
1029
|
+
const code = ctx.result();
|
|
1030
|
+
return {
|
|
1031
|
+
code,
|
|
1032
|
+
// Built only for a caller that named the input: a map walks the whole
|
|
1033
|
+
// output, and an inline `style=""` asks for none thousands of times a page.
|
|
1034
|
+
map:
|
|
1035
|
+
name.source === undefined
|
|
1036
|
+
? undefined
|
|
1037
|
+
: ctx.sourceMap(
|
|
1038
|
+
{ source: name.source, content: name.content },
|
|
1039
|
+
code
|
|
1040
|
+
)
|
|
1041
|
+
};
|
|
1042
|
+
};
|
|
1028
1043
|
if (this._deferred !== null) {
|
|
1029
1044
|
const finish = this._deferred;
|
|
1030
1045
|
|
|
@@ -1142,4 +1157,5 @@ class SourceProcessor {
|
|
|
1142
1157
|
SourceProcessor.PrintContext = PrintContext;
|
|
1143
1158
|
|
|
1144
1159
|
module.exports = SourceProcessor;
|
|
1160
|
+
module.exports.declineDeferredWrites = declineDeferredWrites;
|
|
1145
1161
|
module.exports.deferredWrite = deferredWrite;
|
|
@@ -17,6 +17,7 @@ const _0CharCode = "0".charCodeAt(0);
|
|
|
17
17
|
const _9CharCode = "9".charCodeAt(0);
|
|
18
18
|
const plusCharCode = "+".charCodeAt(0);
|
|
19
19
|
const hyphenCharCode = "-".charCodeAt(0);
|
|
20
|
+
const dotCharCode = ".".charCodeAt(0);
|
|
20
21
|
const colonCharCode = ":".charCodeAt(0);
|
|
21
22
|
const hashCharCode = "#".charCodeAt(0);
|
|
22
23
|
const queryCharCode = "?".charCodeAt(0);
|
|
@@ -46,7 +47,8 @@ function getScheme(specifier) {
|
|
|
46
47
|
(ch >= aUpperCaseCharCode && ch <= zUpperCaseCharCode) ||
|
|
47
48
|
(ch >= _0CharCode && ch <= _9CharCode) ||
|
|
48
49
|
ch === plusCharCode ||
|
|
49
|
-
ch === hyphenCharCode
|
|
50
|
+
ch === hyphenCharCode ||
|
|
51
|
+
ch === dotCharCode
|
|
50
52
|
) {
|
|
51
53
|
if (++i === specifier.length) return;
|
|
52
54
|
ch = specifier.charCodeAt(i);
|