@rollup/wasm-node 5.0.0-1 → 5.0.0-2
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/LICENSE.md +0 -17
- package/dist/bin/rollup +119 -108
- package/dist/es/getLogFilter.js +2 -2
- package/dist/es/parseAst.js +2 -2
- package/dist/es/rollup.js +2 -2
- package/dist/es/shared/node-entry.js +716 -375
- package/dist/es/shared/parseAst.js +12 -4
- package/dist/es/shared/watch.js +3204 -1008
- package/dist/getLogFilter.js +2 -2
- package/dist/loadConfigFile.js +2 -2
- package/dist/parseAst.js +2 -2
- package/dist/rollup.android-arm-eabi.node +0 -0
- package/dist/rollup.android-arm64.node +0 -0
- package/dist/rollup.android-x64.node +0 -0
- package/dist/rollup.d.ts +23 -9
- package/dist/rollup.darwin-arm64.node +0 -0
- package/dist/rollup.darwin-x64.node +0 -0
- package/dist/rollup.freebsd-arm64.node +0 -0
- package/dist/rollup.freebsd-x64.node +0 -0
- package/dist/rollup.js +2 -2
- package/dist/rollup.linux-arm-gnueabihf.node +0 -0
- package/dist/rollup.linux-arm-musleabihf.node +0 -0
- package/dist/rollup.linux-arm64-gnu.node +0 -0
- package/dist/rollup.linux-arm64-musl.node +0 -0
- package/dist/rollup.linux-loong64-gnu.node +0 -0
- package/dist/rollup.linux-loong64-musl.node +0 -0
- package/dist/rollup.linux-ppc64-gnu.node +0 -0
- package/dist/rollup.linux-ppc64-musl.node +0 -0
- package/dist/rollup.linux-riscv64-gnu.node +0 -0
- package/dist/rollup.linux-riscv64-musl.node +0 -0
- package/dist/rollup.linux-s390x-gnu.node +0 -0
- package/dist/rollup.linux-x64-gnu.node +0 -0
- package/dist/rollup.linux-x64-musl.node +0 -0
- package/dist/rollup.openbsd-x64.node +0 -0
- package/dist/rollup.openharmony-arm64.node +0 -0
- package/dist/rollup.win32-arm64-msvc.node +0 -0
- package/dist/rollup.win32-ia32-msvc.node +0 -0
- package/dist/rollup.win32-x64-gnu.node +0 -0
- package/dist/rollup.win32-x64-msvc.node +0 -0
- package/dist/shared/index.js +3198 -1002
- package/dist/shared/loadConfigFile.js +2 -2
- package/dist/shared/node-entry.js +2 -2
- package/dist/shared/parseAst.js +12 -4
- package/dist/shared/rollup.js +714 -373
- package/dist/shared/watch-cli.js +2 -2
- package/dist/shared/watch.js +2 -2
- package/dist/wasm-node/bindings_wasm_bg.wasm +0 -0
- package/package.json +17 -17
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v5.0.0-
|
|
4
|
-
Sun,
|
|
3
|
+
Rollup.js v5.0.0-2
|
|
4
|
+
Sun, 01 Nov 2026 08:56:25 GMT - commit 4009894760dbcbff5ba6cefa494787cc54ffaa62
|
|
5
5
|
|
|
6
6
|
https://github.com/rollup/rollup
|
|
7
7
|
|
|
8
8
|
Released under the MIT License.
|
|
9
9
|
*/
|
|
10
|
-
import { EMPTY_OBJECT, ArrowFunctionExpression as ArrowFunctionExpression$1, FunctionExpression as FunctionExpression$1, Identifier as Identifier$1, ObjectExpression as ObjectExpression$1, ExportDefaultDeclaration as ExportDefaultDeclaration$1, CallExpression as CallExpression$1, EMPTY_ARRAY, Program as Program$1, logRedeclarationError, LOGLEVEL_WARN, logUnusedExternalImports, Property as Property$1, logIllegalImportReassignment, BLANK, StaticBlock as StaticBlock$1, CatchClause as CatchClause$1, logDuplicateArgumentNameError, logModuleLevelDirective, ReturnStatement as ReturnStatement$1, VariableDeclarator as VariableDeclarator$1, ExpressionStatement as ExpressionStatement$1, logMissingExport, normalize, getImportPath, error, logSourcePhaseFormatUnsupported, logMissingNodeBuiltins, logReservedNamespace, logIllegalIdentifierAsName, logMissingNameOptionForIifeExport, logMissingNameOptionForUmdExport, RestElement as RestElement$1, logConstVariableReassignError, FunctionDeclaration as FunctionDeclaration$1, EMPTY_SET, logCannotCallNamespace, logEval, IfStatement as IfStatement$1, BlockStatement as BlockStatement$1, AwaitExpression as AwaitExpression$1, MemberExpression as MemberExpression$1, getRollupError, logParseError, logModuleParseError, LOGLEVEL_INFO, logFirstSideEffect, locate, logInvalidAnnotation, logThisIsUndefined, getAstBuffer, nodeTypeStrings, convertAnnotations, FIXED_STRINGS, convertNode as convertNode$1, logImportAttributeIsInvalid, logImportOptionsAreInvalid, logMissingEntryExport, logSyntheticNamedExportsNeedNamespaceExport, logDuplicateExportError, logInvalidSourcemapForError, augmentCodeLocation, logMissingJsxExport, logNamespaceConflict, logAmbiguousExternalNamespaces, logShimmedExport, deserializeLazyAst, TemplateLiteral as TemplateLiteral$1, Literal as Literal$1, logCircularReexport, logInvalidFormatForTopLevelAwait, logAddonNotGenerated, logIncompatibleExportOptionValue, logMixedExport, logFailedValidation, isPathFragment, logCyclicCrossChunkReexport, getAliasName, logUnexpectedNamedImport,
|
|
10
|
+
import { EMPTY_OBJECT, ArrowFunctionExpression as ArrowFunctionExpression$1, FunctionExpression as FunctionExpression$1, Identifier as Identifier$1, ObjectExpression as ObjectExpression$1, ExportDefaultDeclaration as ExportDefaultDeclaration$1, CallExpression as CallExpression$1, EMPTY_ARRAY, Program as Program$1, logRedeclarationError, LOGLEVEL_WARN, logUnusedExternalImports, Property as Property$1, logIllegalImportReassignment, BLANK, StaticBlock as StaticBlock$1, CatchClause as CatchClause$1, logDuplicateArgumentNameError, logModuleLevelDirective, ReturnStatement as ReturnStatement$1, VariableDeclarator as VariableDeclarator$1, ExpressionStatement as ExpressionStatement$1, logMissingExport, normalize, getImportPath, error, logSourcePhaseFormatUnsupported, logMissingNodeBuiltins, logReservedNamespace, logIllegalIdentifierAsName, logMissingNameOptionForIifeExport, logMissingNameOptionForUmdExport, RestElement as RestElement$1, logConstVariableReassignError, FunctionDeclaration as FunctionDeclaration$1, EMPTY_SET, logCannotCallNamespace, logEval, IfStatement as IfStatement$1, BlockStatement as BlockStatement$1, AwaitExpression as AwaitExpression$1, MemberExpression as MemberExpression$1, getRollupError, logParseError, logModuleParseError, LOGLEVEL_INFO, logFirstSideEffect, locate, logInvalidAnnotation, logThisIsUndefined, getAstBuffer, nodeTypeStrings, convertAnnotations, FIXED_STRINGS, convertNode as convertNode$1, isAbsolute as isAbsolute$1, logImportAttributeIsInvalid, logImportOptionsAreInvalid, logMissingEntryExport, logSyntheticNamedExportsNeedNamespaceExport, logDuplicateExportError, logInvalidSourcemapForError, augmentCodeLocation, logMissingJsxExport, logNamespaceConflict, logAmbiguousExternalNamespaces, logShimmedExport, deserializeLazyAst, TemplateLiteral as TemplateLiteral$1, Literal as Literal$1, logCircularReexport, logInvalidFormatForTopLevelAwait, logAddonNotGenerated, logIncompatibleExportOptionValue, logMixedExport, logFailedValidation, isPathFragment, logCyclicCrossChunkReexport, getAliasName, logUnexpectedNamedImport, relative as relative$1, logUnexpectedNamespaceReexport, logEmptyChunk, logMissingGlobalName, logAmbiguousGlobalName, logEmptyManualChunk, logOptimizeChunkStatus, logSourcemapBroken, logConflictingSourcemapSources, logErrorInHook, parseAst, logChunkInvalid, logInvalidOption, URL_OUTPUT_FORMAT, URL_OUTPUT_DIR, URL_OUTPUT_SOURCEMAPFILE, URL_OUTPUT_AMD_ID, logFileNameOutsideOutputDirectory, logCannotAssignModuleToChunk, logCircularChunk, logUnknownOption, printQuotedStringList, LOGLEVEL_ERROR, logLevelPriority, LOGLEVEL_DEBUG, logInvalidLogPosition, logAnonymousPluginCache, logDuplicatePluginName, parseAndWalk, logPluginError, warnDeprecation, URL_THIS_RESOLVE, logInvalidSetAssetSourceCall, serializeAst, logNoTransformMapOrAstWithoutCode, URL_TRANSFORM, logNonExternalSourcePhaseImport, relativeId, logInternalIdCannotBeExternal, isRelative, logUnresolvedImport, logUnresolvedImportTreatedAsExternal, logExternalSyntheticExports, logUnresolvedEntry, logUnresolvedImplicitDependant, logExternalModulesCannotBeIncludedInManualChunks, logEntryCannotBeExternal, logImplicitDependantCannotBeExternal, logBadLoader, logExternalModulesCannotBeTransformedToModules, URL_LOAD, logNoAssetSourceSet, logFileReferenceIdNotFoundForFilename, logAssetReferenceIdNotFoundForSetSource, logAssetSourceAlreadySet, logInvalidRollupPhaseForChunkEmission, logChunkNotGeneratedForFileName, logAssetNotFinalisedForFileName, logFileNameConflict, URL_GENERATEBUNDLE, logInputHookInOutputPlugin, logInvalidAddonPluginHook, logInvalidFunctionPluginHook, logImplicitDependantIsNotIncluded, logCircularDependency, augmentLogMessage, URL_JSX, URL_TREESHAKE, URL_TREESHAKE_MODULESIDEEFFECTS, URL_OUTPUT_INLINEDYNAMICIMPORTS, URL_PRESERVEENTRYSIGNATURES, URL_OUTPUT_GENERATEDCODE, isValidUrl, addTrailingSlashIfMissed, URL_OUTPUT_SOURCEMAPBASEURL, URL_OUTPUT_MANUALCHUNKS, logInvalidExportOptionValue, URL_OUTPUT_AMD_BASEPATH, URL_OUTPUT_INTEROP, URL_OUTPUT_IMPORTATTRIBUTESKEY, logAlreadyClosed, logMissingFileOrDirOption, logCannotEmitFromOptionsHook, URL_WATCH } from './parseAst.js';
|
|
11
11
|
import { relative, dirname, basename, extname, resolve as resolve$1, join } from 'node:path';
|
|
12
|
-
import { posix,
|
|
12
|
+
import { isAbsolute, posix, win32, resolve } from 'path';
|
|
13
13
|
import process$1, { env } from 'node:process';
|
|
14
14
|
import { performance } from 'node:perf_hooks';
|
|
15
15
|
import { xxhashBase16, xxhashBase64Url, xxhashBase36, parseAsync } from '../../native.js';
|
|
@@ -27,7 +27,7 @@ function _mergeNamespaces(n, m) {
|
|
|
27
27
|
return Object.defineProperty(n, Symbol.toStringTag, { value: 'Module' });
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
var version = "5.0.0-
|
|
30
|
+
var version = "5.0.0-2";
|
|
31
31
|
const pkg = {
|
|
32
32
|
version: version};
|
|
33
33
|
|
|
@@ -232,6 +232,17 @@ var BitSet = class BitSet {
|
|
|
232
232
|
has(n) {
|
|
233
233
|
return !!(this.bits[n >> 5] & 1 << (n & 31));
|
|
234
234
|
}
|
|
235
|
+
forEach(fn) {
|
|
236
|
+
const bits = this.bits;
|
|
237
|
+
for (let w = 0; w < bits.length; w++) {
|
|
238
|
+
let word = bits[w];
|
|
239
|
+
while (word) {
|
|
240
|
+
const lowest = word & -word;
|
|
241
|
+
fn((w << 5) + 31 - Math.clz32(lowest));
|
|
242
|
+
word ^= lowest;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
235
246
|
};
|
|
236
247
|
//#endregion
|
|
237
248
|
//#region src/Chunk.ts
|
|
@@ -245,6 +256,8 @@ var Chunk$1 = class Chunk {
|
|
|
245
256
|
this.content = content;
|
|
246
257
|
this.storeName = false;
|
|
247
258
|
this.edited = false;
|
|
259
|
+
this.replacesUntil = -1;
|
|
260
|
+
this.replacedFrom = -1;
|
|
248
261
|
this.previous = null;
|
|
249
262
|
this.next = null;
|
|
250
263
|
}
|
|
@@ -261,6 +274,8 @@ var Chunk$1 = class Chunk {
|
|
|
261
274
|
chunk.content = this.content;
|
|
262
275
|
chunk.storeName = this.storeName;
|
|
263
276
|
chunk.edited = this.edited;
|
|
277
|
+
chunk.replacesUntil = this.replacesUntil;
|
|
278
|
+
chunk.replacedFrom = this.replacedFrom;
|
|
264
279
|
return chunk;
|
|
265
280
|
}
|
|
266
281
|
contains(index) {
|
|
@@ -301,6 +316,8 @@ var Chunk$1 = class Chunk {
|
|
|
301
316
|
reset() {
|
|
302
317
|
this.intro = "";
|
|
303
318
|
this.outro = "";
|
|
319
|
+
this.replacesUntil = -1;
|
|
320
|
+
this.replacedFrom = -1;
|
|
304
321
|
if (this.edited) {
|
|
305
322
|
this.content = this.original;
|
|
306
323
|
this.storeName = false;
|
|
@@ -318,7 +335,7 @@ var Chunk$1 = class Chunk {
|
|
|
318
335
|
this.end = index;
|
|
319
336
|
if (this.edited) {
|
|
320
337
|
newChunk.edit("", false, true);
|
|
321
|
-
|
|
338
|
+
newChunk.replacedFrom = this.replacedFrom;
|
|
322
339
|
} else this.content = originalBefore;
|
|
323
340
|
newChunk.next = this.next;
|
|
324
341
|
if (newChunk.next) newChunk.next.previous = newChunk;
|
|
@@ -582,8 +599,8 @@ var Mappings = class {
|
|
|
582
599
|
this.generatedCodeColumn = 0;
|
|
583
600
|
this.raw = [];
|
|
584
601
|
this.rawSegments = this.raw[this.generatedCodeLine] = [];
|
|
585
|
-
this.
|
|
586
|
-
this.
|
|
602
|
+
this.rawRangeMappingsIndices = [];
|
|
603
|
+
this.rawRangeMappings = hires === "experimental-range" ? [this.rawRangeMappingsIndices] : void 0;
|
|
587
604
|
this.encoder = encoder;
|
|
588
605
|
}
|
|
589
606
|
nextLine() {
|
|
@@ -596,7 +613,28 @@ var Mappings = class {
|
|
|
596
613
|
this.generatedCodeLine += 1;
|
|
597
614
|
}
|
|
598
615
|
this.generatedCodeColumn = 0;
|
|
599
|
-
this.rawRangeMappings[this.generatedCodeLine] = this.rawRangeMappingsIndices = [];
|
|
616
|
+
if (this.rawRangeMappings) this.rawRangeMappings[this.generatedCodeLine] = this.rawRangeMappingsIndices = [];
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Emits the mappings for one MagicString: its intro, every chunk (with the
|
|
620
|
+
* chunk's own intro/outro) and its outro. `sourceIndex === -1` means the
|
|
621
|
+
* string has no source of its own, so its content only advances the
|
|
622
|
+
* generated position without mapping anything.
|
|
623
|
+
*/
|
|
624
|
+
addMagicString(magicString, sourceIndex, nameIndex) {
|
|
625
|
+
const { original } = magicString;
|
|
626
|
+
const locate = getLocator(original);
|
|
627
|
+
if (magicString.intro) this.advance(magicString.intro);
|
|
628
|
+
magicString.firstChunk.eachNext((chunk) => {
|
|
629
|
+
if (chunk.intro.length) this.advance(chunk.intro);
|
|
630
|
+
if (sourceIndex === -1) this.advance(chunk.content);
|
|
631
|
+
else if (chunk.edited) {
|
|
632
|
+
const name = chunk.storeName ? nameIndex.get(original.slice(chunk.start, chunk.replacesUntil)) : void 0;
|
|
633
|
+
this.addEdit(sourceIndex, chunk.content, locate(chunk.start), name ?? -1);
|
|
634
|
+
} else this.addUneditedChunk(sourceIndex, chunk, original, locate(chunk.start), magicString.sourcemapLocations);
|
|
635
|
+
if (chunk.outro.length) this.advance(chunk.outro);
|
|
636
|
+
});
|
|
637
|
+
if (magicString.outro) this.advance(magicString.outro);
|
|
600
638
|
}
|
|
601
639
|
addEdit(sourceIndex, content, loc, nameIndex) {
|
|
602
640
|
if (content.length) {
|
|
@@ -811,6 +849,9 @@ function expandReplacement(replacement, matched, position, str, captures, namedC
|
|
|
811
849
|
return result;
|
|
812
850
|
}
|
|
813
851
|
var MagicString = class MagicString {
|
|
852
|
+
/**
|
|
853
|
+
* Wraps `string` for editing; every index passed to the editing methods refers to this original string.
|
|
854
|
+
*/
|
|
814
855
|
constructor(string, options = {}) {
|
|
815
856
|
const chunk = new Chunk$1(0, string.length, string);
|
|
816
857
|
Object.defineProperties(this, {
|
|
@@ -860,7 +901,7 @@ var MagicString = class MagicString {
|
|
|
860
901
|
},
|
|
861
902
|
storedNames: {
|
|
862
903
|
writable: true,
|
|
863
|
-
value:
|
|
904
|
+
value: /* @__PURE__ */ new Set()
|
|
864
905
|
},
|
|
865
906
|
indentStr: {
|
|
866
907
|
writable: true,
|
|
@@ -900,7 +941,8 @@ var MagicString = class MagicString {
|
|
|
900
941
|
* See also `s.prependLeft(...)`.
|
|
901
942
|
*/
|
|
902
943
|
appendLeft(index, content) {
|
|
903
|
-
index =
|
|
944
|
+
index = this._resolveIndex(index);
|
|
945
|
+
if (index < 0 || index > this.original.length) throw new MagicStringError(`index ${index} is out of bounds`);
|
|
904
946
|
if (typeof content !== "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
|
|
905
947
|
this._split(index);
|
|
906
948
|
const chunk = this.byEnd.get(index);
|
|
@@ -914,7 +956,8 @@ var MagicString = class MagicString {
|
|
|
914
956
|
* See also `s.prependRight(...)`.
|
|
915
957
|
*/
|
|
916
958
|
appendRight(index, content) {
|
|
917
|
-
index =
|
|
959
|
+
index = this._resolveIndex(index);
|
|
960
|
+
if (index < 0 || index > this.original.length) throw new MagicStringError(`index ${index} is out of bounds`);
|
|
918
961
|
if (typeof content !== "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
|
|
919
962
|
this._split(index);
|
|
920
963
|
const chunk = this.byStart.get(index);
|
|
@@ -923,7 +966,10 @@ var MagicString = class MagicString {
|
|
|
923
966
|
return this;
|
|
924
967
|
}
|
|
925
968
|
/**
|
|
926
|
-
*
|
|
969
|
+
* Returns an independent copy: the chunk list, string-level intro/outro,
|
|
970
|
+
* sourcemap locations, stored names, indent exclusion ranges, `offset`,
|
|
971
|
+
* `filename` and `ignoreList` are all copied; later edits to either string
|
|
972
|
+
* do not affect the other.
|
|
927
973
|
*/
|
|
928
974
|
clone() {
|
|
929
975
|
const cloned = new MagicString(this.original, {
|
|
@@ -948,7 +994,7 @@ var MagicString = class MagicString {
|
|
|
948
994
|
cloned.lastChunk = clonedChunk;
|
|
949
995
|
if (this.indentExclusionRanges) cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
|
950
996
|
cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
|
|
951
|
-
cloned.storedNames =
|
|
997
|
+
cloned.storedNames = new Set(this.storedNames);
|
|
952
998
|
cloned.intro = this.intro;
|
|
953
999
|
cloned.outro = this.outro;
|
|
954
1000
|
cloned.hasMovedChunks = this.hasMovedChunks;
|
|
@@ -984,18 +1030,8 @@ var MagicString = class MagicString {
|
|
|
984
1030
|
}
|
|
985
1031
|
/** @internal */
|
|
986
1032
|
_generateMappings(mappings) {
|
|
987
|
-
const
|
|
988
|
-
|
|
989
|
-
const locate = getLocator(this.original);
|
|
990
|
-
if (this.intro) mappings.advance(this.intro);
|
|
991
|
-
this.firstChunk.eachNext((chunk) => {
|
|
992
|
-
const loc = locate(chunk.start);
|
|
993
|
-
if (chunk.intro.length) mappings.advance(chunk.intro);
|
|
994
|
-
if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
|
|
995
|
-
else mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
|
|
996
|
-
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
997
|
-
});
|
|
998
|
-
if (this.outro) mappings.advance(this.outro);
|
|
1033
|
+
const names = [...this.storedNames];
|
|
1034
|
+
mappings.addMagicString(this, 0, new Map(names.map((name, i) => [name, i])));
|
|
999
1035
|
return names;
|
|
1000
1036
|
}
|
|
1001
1037
|
/** @internal */
|
|
@@ -1017,9 +1053,13 @@ var MagicString = class MagicString {
|
|
|
1017
1053
|
this._ensureindentStr();
|
|
1018
1054
|
return this.indentStr;
|
|
1019
1055
|
}
|
|
1056
|
+
/**
|
|
1057
|
+
* Returns the indentation string guessed from the original content, falling back to a single tab character.
|
|
1058
|
+
* This is the value `s.indent()` uses when no prefix is supplied.
|
|
1059
|
+
*/
|
|
1020
1060
|
getIndentString() {
|
|
1021
1061
|
this._ensureindentStr();
|
|
1022
|
-
return this.indentStr
|
|
1062
|
+
return this.indentStr ?? " ";
|
|
1023
1063
|
}
|
|
1024
1064
|
indent(indentStr, options) {
|
|
1025
1065
|
const pattern = /^[^\r\n]/gm;
|
|
@@ -1034,9 +1074,9 @@ var MagicString = class MagicString {
|
|
|
1034
1074
|
if (indentStr === "") return this;
|
|
1035
1075
|
const resolvedIndentStr = indentStr;
|
|
1036
1076
|
options = options || {};
|
|
1037
|
-
const isExcluded =
|
|
1077
|
+
const isExcluded = new BitSet();
|
|
1038
1078
|
if (options.exclude) (typeof options.exclude[0] === "number" ? [options.exclude] : options.exclude).forEach((exclusion) => {
|
|
1039
|
-
for (let i = exclusion[0]; i < exclusion[1]; i += 1) isExcluded
|
|
1079
|
+
for (let i = exclusion[0]; i < exclusion[1]; i += 1) isExcluded.add(i);
|
|
1040
1080
|
});
|
|
1041
1081
|
let shouldIndentNextCharacter = options.indentStart !== false;
|
|
1042
1082
|
const indentPiece = (str) => {
|
|
@@ -1059,13 +1099,14 @@ var MagicString = class MagicString {
|
|
|
1059
1099
|
};
|
|
1060
1100
|
while (chunk) {
|
|
1061
1101
|
const end = chunk.end;
|
|
1062
|
-
if (!isExcluded
|
|
1102
|
+
if (!isExcluded.has(chunk.start)) chunk.intro = indentPiece(chunk.intro);
|
|
1063
1103
|
if (chunk.edited) {
|
|
1064
|
-
if (!isExcluded
|
|
1104
|
+
if (!isExcluded.has(chunk.start)) chunk.content = indentPiece(chunk.content);
|
|
1105
|
+
else if (chunk.content) shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === "\n";
|
|
1065
1106
|
} else if (options.exclude) {
|
|
1066
1107
|
charIndex = chunk.start;
|
|
1067
1108
|
while (charIndex < end) {
|
|
1068
|
-
if (!isExcluded
|
|
1109
|
+
if (!isExcluded.has(charIndex)) {
|
|
1069
1110
|
const char = this.original.charCodeAt(charIndex);
|
|
1070
1111
|
if (char === NEWLINE_CHAR) shouldIndentNextCharacter = true;
|
|
1071
1112
|
else if (char !== CR_CHAR && shouldIndentNextCharacter) indentAt(charIndex);
|
|
@@ -1091,7 +1132,7 @@ var MagicString = class MagicString {
|
|
|
1091
1132
|
charIndex += 1;
|
|
1092
1133
|
}
|
|
1093
1134
|
}
|
|
1094
|
-
if (!isExcluded
|
|
1135
|
+
if (!isExcluded.has(chunk.end - 1)) chunk.outro = indentPiece(chunk.outro);
|
|
1095
1136
|
charIndex = chunk.end;
|
|
1096
1137
|
chunk = chunk.next;
|
|
1097
1138
|
}
|
|
@@ -1128,16 +1169,19 @@ var MagicString = class MagicString {
|
|
|
1128
1169
|
* mirroring the `appendLeft`/`appendRight` distinction.
|
|
1129
1170
|
*/
|
|
1130
1171
|
move(start, end, index, affinity = "right") {
|
|
1131
|
-
start =
|
|
1132
|
-
end =
|
|
1133
|
-
index =
|
|
1172
|
+
start = this._resolveIndex(start);
|
|
1173
|
+
end = this._resolveIndex(end);
|
|
1174
|
+
index = this._resolveIndex(index);
|
|
1134
1175
|
if (start === end) return this;
|
|
1176
|
+
if (start < 0 || end > this.original.length || index < 0 || index > this.original.length) throw new MagicStringError(`range ${start}–${end} is out of bounds`);
|
|
1177
|
+
if (start > end) throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`);
|
|
1135
1178
|
if (index >= start && index <= end) throw new MagicStringError("cannot move a selection inside itself");
|
|
1136
1179
|
this._split(start);
|
|
1137
1180
|
this._split(end);
|
|
1138
1181
|
this._split(index);
|
|
1139
1182
|
const first = this.byStart.get(start);
|
|
1140
1183
|
const last = this.byEnd.get(end);
|
|
1184
|
+
if (!first || !last) throw new MagicStringError(`range ${start}–${end} is out of bounds`);
|
|
1141
1185
|
if (this.hasMovedChunks) {
|
|
1142
1186
|
let cursor = first;
|
|
1143
1187
|
while (cursor !== last) {
|
|
@@ -1172,9 +1216,9 @@ var MagicString = class MagicString {
|
|
|
1172
1216
|
if (oldRight) oldRight.previous = oldLeft;
|
|
1173
1217
|
if (newLeft) newLeft.next = first;
|
|
1174
1218
|
if (newRight) newRight.previous = last;
|
|
1175
|
-
if (!
|
|
1176
|
-
if (!
|
|
1177
|
-
this.lastChunk =
|
|
1219
|
+
if (!oldLeft) this.firstChunk = oldRight;
|
|
1220
|
+
if (!oldRight) {
|
|
1221
|
+
this.lastChunk = oldLeft;
|
|
1178
1222
|
this.lastChunk.next = null;
|
|
1179
1223
|
}
|
|
1180
1224
|
first.previous = newLeft;
|
|
@@ -1195,6 +1239,16 @@ var MagicString = class MagicString {
|
|
|
1195
1239
|
* It may be preferred to use `s.update(...)` instead if you wish to avoid overwriting the appended/prepended content.
|
|
1196
1240
|
*/
|
|
1197
1241
|
overwrite(start, end, content, options) {
|
|
1242
|
+
if (options === true) {
|
|
1243
|
+
if (!warned.storeName) {
|
|
1244
|
+
console.warn("The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string");
|
|
1245
|
+
warned.storeName = true;
|
|
1246
|
+
}
|
|
1247
|
+
return this.update(start, end, content, {
|
|
1248
|
+
storeName: true,
|
|
1249
|
+
overwrite: true
|
|
1250
|
+
});
|
|
1251
|
+
}
|
|
1198
1252
|
const optionObject = typeof options === "object" && options ? options : {};
|
|
1199
1253
|
return this.update(start, end, content, {
|
|
1200
1254
|
...optionObject,
|
|
@@ -1209,13 +1263,9 @@ var MagicString = class MagicString {
|
|
|
1209
1263
|
* the content is overwritten, or anything that was appended/prepended to the range as well.
|
|
1210
1264
|
*/
|
|
1211
1265
|
update(start, end, content, options) {
|
|
1212
|
-
start =
|
|
1213
|
-
end =
|
|
1266
|
+
start = this._resolveIndex(start);
|
|
1267
|
+
end = this._resolveIndex(end);
|
|
1214
1268
|
if (typeof content !== "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
|
|
1215
|
-
if (this.original.length !== 0) {
|
|
1216
|
-
if (start < 0) start = Math.max(0, start + this.original.length);
|
|
1217
|
-
if (end < 0) end = Math.max(0, end + this.original.length);
|
|
1218
|
-
}
|
|
1219
1269
|
if (start < 0) throw new MagicStringError(`start ${start} is out of bounds`);
|
|
1220
1270
|
if (end > this.original.length) throw new MagicStringError(`end ${end} is out of bounds`);
|
|
1221
1271
|
if (start === end) throw new MagicStringError(`cannot overwrite a zero-length range at ${start}, use appendLeft() or prependRight()`);
|
|
@@ -1232,30 +1282,21 @@ var MagicString = class MagicString {
|
|
|
1232
1282
|
const optionObject = typeof options === "object" && options ? options : {};
|
|
1233
1283
|
const storeName = optionObject.storeName || false;
|
|
1234
1284
|
const overwrite = optionObject.overwrite || false;
|
|
1235
|
-
if (storeName)
|
|
1236
|
-
const original = this.original.slice(start, end);
|
|
1237
|
-
Object.defineProperty(this.storedNames, original, {
|
|
1238
|
-
writable: true,
|
|
1239
|
-
value: true,
|
|
1240
|
-
enumerable: true
|
|
1241
|
-
});
|
|
1242
|
-
}
|
|
1285
|
+
if (storeName) this.storedNames.add(this.original.slice(start, end));
|
|
1243
1286
|
const first = this.byStart.get(start);
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
first.edit(content, storeName, !overwrite);
|
|
1254
|
-
} else {
|
|
1255
|
-
const newChunk = new Chunk$1(start, end, "").edit(content, storeName);
|
|
1256
|
-
last.next = newChunk;
|
|
1257
|
-
newChunk.previous = last;
|
|
1287
|
+
for (let chunk = first; chunk.end < end;) {
|
|
1288
|
+
const next = chunk.next;
|
|
1289
|
+
if (next === null || next !== this.byStart.get(chunk.end)) throw new MagicStringError("cannot overwrite across a split point");
|
|
1290
|
+
chunk = next;
|
|
1291
|
+
}
|
|
1292
|
+
for (let chunk = first.next; chunk !== null && chunk.start < end; chunk = chunk.next) {
|
|
1293
|
+
chunk.edit("", false, !overwrite);
|
|
1294
|
+
chunk.replacesUntil = -1;
|
|
1295
|
+
chunk.replacedFrom = start;
|
|
1258
1296
|
}
|
|
1297
|
+
first.edit(content, storeName, !overwrite);
|
|
1298
|
+
first.replacesUntil = end;
|
|
1299
|
+
first.replacedFrom = -1;
|
|
1259
1300
|
return this;
|
|
1260
1301
|
}
|
|
1261
1302
|
/**
|
|
@@ -1270,7 +1311,8 @@ var MagicString = class MagicString {
|
|
|
1270
1311
|
* Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at index
|
|
1271
1312
|
*/
|
|
1272
1313
|
prependLeft(index, content) {
|
|
1273
|
-
index =
|
|
1314
|
+
index = this._resolveIndex(index);
|
|
1315
|
+
if (index < 0 || index > this.original.length) throw new MagicStringError(`index ${index} is out of bounds`);
|
|
1274
1316
|
if (typeof content !== "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
|
|
1275
1317
|
this._split(index);
|
|
1276
1318
|
const chunk = this.byEnd.get(index);
|
|
@@ -1282,7 +1324,8 @@ var MagicString = class MagicString {
|
|
|
1282
1324
|
* Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
|
|
1283
1325
|
*/
|
|
1284
1326
|
prependRight(index, content) {
|
|
1285
|
-
index =
|
|
1327
|
+
index = this._resolveIndex(index);
|
|
1328
|
+
if (index < 0 || index > this.original.length) throw new MagicStringError(`index ${index} is out of bounds`);
|
|
1286
1329
|
if (typeof content !== "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
|
|
1287
1330
|
this._split(index);
|
|
1288
1331
|
const chunk = this.byStart.get(index);
|
|
@@ -1298,12 +1341,8 @@ var MagicString = class MagicString {
|
|
|
1298
1341
|
* Repeated removals and removals with partially overlapping ranges are allowed.
|
|
1299
1342
|
*/
|
|
1300
1343
|
remove(start, end) {
|
|
1301
|
-
start =
|
|
1302
|
-
end =
|
|
1303
|
-
if (this.original.length !== 0) {
|
|
1304
|
-
if (start < 0) start = Math.max(0, start + this.original.length);
|
|
1305
|
-
if (end < 0) end = Math.max(0, end + this.original.length);
|
|
1306
|
-
}
|
|
1344
|
+
start = this._resolveIndex(start);
|
|
1345
|
+
end = this._resolveIndex(end);
|
|
1307
1346
|
if (start === end) return this;
|
|
1308
1347
|
if (start < 0 || end > this.original.length) throw new MagicStringError(`range ${start}–${end} is out of bounds`);
|
|
1309
1348
|
if (start > end) throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`);
|
|
@@ -1314,7 +1353,9 @@ var MagicString = class MagicString {
|
|
|
1314
1353
|
if (chunk.start > start) chunk.intro = "";
|
|
1315
1354
|
if (chunk.end < end) chunk.outro = "";
|
|
1316
1355
|
chunk.edit("", false, true);
|
|
1317
|
-
chunk =
|
|
1356
|
+
chunk.replacesUntil = -1;
|
|
1357
|
+
chunk.replacedFrom = -1;
|
|
1358
|
+
chunk = end > chunk.end ? this.byStart.get(chunk.end) : void 0;
|
|
1318
1359
|
}
|
|
1319
1360
|
return this;
|
|
1320
1361
|
}
|
|
@@ -1322,12 +1363,8 @@ var MagicString = class MagicString {
|
|
|
1322
1363
|
* Reset the modified characters from `start` to `end` (of the original string, **not** the generated string).
|
|
1323
1364
|
*/
|
|
1324
1365
|
reset(start, end) {
|
|
1325
|
-
start =
|
|
1326
|
-
end =
|
|
1327
|
-
if (this.original.length !== 0) {
|
|
1328
|
-
if (start < 0) start = Math.max(0, start + this.original.length);
|
|
1329
|
-
if (end < 0) end = Math.max(0, end + this.original.length);
|
|
1330
|
-
}
|
|
1366
|
+
start = this._resolveIndex(start);
|
|
1367
|
+
end = this._resolveIndex(end);
|
|
1331
1368
|
if (start === end) return this;
|
|
1332
1369
|
if (start < 0 || end > this.original.length) throw new MagicStringError(`range ${start}–${end} is out of bounds`);
|
|
1333
1370
|
if (start > end) throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`);
|
|
@@ -1336,10 +1373,13 @@ var MagicString = class MagicString {
|
|
|
1336
1373
|
let chunk = this.byStart.get(start);
|
|
1337
1374
|
while (chunk) {
|
|
1338
1375
|
chunk.reset();
|
|
1339
|
-
chunk = end > chunk.end ? this.byStart.get(chunk.end) :
|
|
1376
|
+
chunk = end > chunk.end ? this.byStart.get(chunk.end) : void 0;
|
|
1340
1377
|
}
|
|
1341
1378
|
return this;
|
|
1342
1379
|
}
|
|
1380
|
+
/**
|
|
1381
|
+
* Returns the last character of the generated string, or `''` if it is empty.
|
|
1382
|
+
*/
|
|
1343
1383
|
lastChar() {
|
|
1344
1384
|
if (this.outro.length) return this.outro[this.outro.length - 1];
|
|
1345
1385
|
let chunk = this.lastChunk;
|
|
@@ -1352,49 +1392,57 @@ var MagicString = class MagicString {
|
|
|
1352
1392
|
if (this.intro.length) return this.intro[this.intro.length - 1];
|
|
1353
1393
|
return "";
|
|
1354
1394
|
}
|
|
1395
|
+
/**
|
|
1396
|
+
* Returns everything after the last newline in the generated string, or the whole string if there is no newline.
|
|
1397
|
+
*/
|
|
1355
1398
|
lastLine() {
|
|
1356
1399
|
let lineIndex = this.outro.lastIndexOf(n);
|
|
1357
|
-
if (lineIndex !== -1) return this.outro.
|
|
1400
|
+
if (lineIndex !== -1) return this.outro.slice(lineIndex + 1);
|
|
1358
1401
|
let lineStr = this.outro;
|
|
1359
1402
|
let chunk = this.lastChunk;
|
|
1360
1403
|
while (chunk) {
|
|
1361
1404
|
if (chunk.outro.length > 0) {
|
|
1362
1405
|
lineIndex = chunk.outro.lastIndexOf(n);
|
|
1363
|
-
if (lineIndex !== -1) return chunk.outro.
|
|
1406
|
+
if (lineIndex !== -1) return chunk.outro.slice(lineIndex + 1) + lineStr;
|
|
1364
1407
|
lineStr = chunk.outro + lineStr;
|
|
1365
1408
|
}
|
|
1366
1409
|
if (chunk.content.length > 0) {
|
|
1367
1410
|
lineIndex = chunk.content.lastIndexOf(n);
|
|
1368
|
-
if (lineIndex !== -1) return chunk.content.
|
|
1411
|
+
if (lineIndex !== -1) return chunk.content.slice(lineIndex + 1) + lineStr;
|
|
1369
1412
|
lineStr = chunk.content + lineStr;
|
|
1370
1413
|
}
|
|
1371
1414
|
if (chunk.intro.length > 0) {
|
|
1372
1415
|
lineIndex = chunk.intro.lastIndexOf(n);
|
|
1373
|
-
if (lineIndex !== -1) return chunk.intro.
|
|
1416
|
+
if (lineIndex !== -1) return chunk.intro.slice(lineIndex + 1) + lineStr;
|
|
1374
1417
|
lineStr = chunk.intro + lineStr;
|
|
1375
1418
|
}
|
|
1376
1419
|
chunk = chunk.previous;
|
|
1377
1420
|
}
|
|
1378
1421
|
lineIndex = this.intro.lastIndexOf(n);
|
|
1379
|
-
if (lineIndex !== -1) return this.intro.
|
|
1422
|
+
if (lineIndex !== -1) return this.intro.slice(lineIndex + 1) + lineStr;
|
|
1380
1423
|
return this.intro + lineStr;
|
|
1381
1424
|
}
|
|
1382
1425
|
/**
|
|
1383
|
-
* Returns the content of the generated string that corresponds to the slice
|
|
1384
|
-
*
|
|
1426
|
+
* Returns the content of the generated string that corresponds to the slice
|
|
1427
|
+
* between `start` and `end` of the original string, walking the generated
|
|
1428
|
+
* string from the chunk holding `start` to the chunk holding `end`. Throws
|
|
1429
|
+
* if either index falls inside replaced content. After `move()`, a range
|
|
1430
|
+
* whose end now comes before its start in the output yields `''`.
|
|
1385
1431
|
*/
|
|
1386
1432
|
slice(start = 0, end = this.original.length - this.offset) {
|
|
1387
|
-
start =
|
|
1388
|
-
end =
|
|
1389
|
-
if (this.original.length !== 0) {
|
|
1390
|
-
if (start < 0) start = Math.max(0, start + this.original.length);
|
|
1391
|
-
if (end < 0) end = Math.max(0, end + this.original.length);
|
|
1392
|
-
}
|
|
1433
|
+
start = this._resolveIndex(start);
|
|
1434
|
+
end = this._resolveIndex(end);
|
|
1393
1435
|
let result = "";
|
|
1394
|
-
let chunk
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
chunk
|
|
1436
|
+
let chunk;
|
|
1437
|
+
if (this.hasMovedChunks) {
|
|
1438
|
+
chunk = this.firstChunk;
|
|
1439
|
+
while (chunk && (chunk.start > start || chunk.end <= start)) {
|
|
1440
|
+
if (chunk.start < end && chunk.end >= end || end === 0 && chunk.start === 0) return result;
|
|
1441
|
+
chunk = chunk.next;
|
|
1442
|
+
}
|
|
1443
|
+
} else {
|
|
1444
|
+
if (start >= end) return result;
|
|
1445
|
+
chunk = this._chunkAt(start);
|
|
1398
1446
|
}
|
|
1399
1447
|
if (chunk && chunk.edited && chunk.start !== start) throw new MagicStringError(`cannot use edited character ${start} as slice start anchor`);
|
|
1400
1448
|
const startChunk = chunk;
|
|
@@ -1417,10 +1465,39 @@ var MagicString = class MagicString {
|
|
|
1417
1465
|
*/
|
|
1418
1466
|
snip(start, end) {
|
|
1419
1467
|
const clone = this.clone();
|
|
1420
|
-
clone.remove(
|
|
1421
|
-
clone.remove(end, clone.original.length);
|
|
1468
|
+
clone.remove(-clone.offset, start);
|
|
1469
|
+
clone.remove(end, clone.original.length - clone.offset);
|
|
1422
1470
|
return clone;
|
|
1423
1471
|
}
|
|
1472
|
+
/**
|
|
1473
|
+
* Applies `offset`, resolves a negative index from the end of `original` as
|
|
1474
|
+
* `update`/`remove` always have, and rejects anything that is not an integer.
|
|
1475
|
+
* Bounds are checked by the caller, because the methods report them differently.
|
|
1476
|
+
*
|
|
1477
|
+
* @internal
|
|
1478
|
+
*/
|
|
1479
|
+
_resolveIndex(index) {
|
|
1480
|
+
const resolved = index + this.offset;
|
|
1481
|
+
if (!Number.isInteger(resolved)) throw new MagicStringError(`index must be an integer, got ${index}`);
|
|
1482
|
+
if (resolved < 0 && this.original.length !== 0) return Math.max(0, resolved + this.original.length);
|
|
1483
|
+
return resolved;
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* The chunk whose original range holds `index` (`chunk.start <= index < chunk.end`),
|
|
1487
|
+
* or `undefined` when `index` is at or past the end. Searches from the last
|
|
1488
|
+
* visited chunk so that scans over nearby indices stay cheap.
|
|
1489
|
+
*
|
|
1490
|
+
* @internal
|
|
1491
|
+
*/
|
|
1492
|
+
_chunkAt(index) {
|
|
1493
|
+
let chunk = this.byStart.get(index);
|
|
1494
|
+
if (chunk) return chunk;
|
|
1495
|
+
chunk = this.lastSearchedChunk;
|
|
1496
|
+
const searchForward = index >= chunk.end;
|
|
1497
|
+
while (chunk && !chunk.contains(index)) chunk = searchForward ? this.byStart.get(chunk.end) : this.byEnd.get(chunk.start);
|
|
1498
|
+
if (chunk) this.lastSearchedChunk = chunk;
|
|
1499
|
+
return chunk;
|
|
1500
|
+
}
|
|
1424
1501
|
/** @internal */
|
|
1425
1502
|
_split(index) {
|
|
1426
1503
|
if (this.byStart.get(index) || this.byEnd.get(index)) return;
|
|
@@ -1473,6 +1550,11 @@ var MagicString = class MagicString {
|
|
|
1473
1550
|
if (this.outro.length && this.outro.trim()) return false;
|
|
1474
1551
|
return true;
|
|
1475
1552
|
}
|
|
1553
|
+
/**
|
|
1554
|
+
* Returns the length of the generated string, counting only content attached to the original characters.
|
|
1555
|
+
* Content outside the string body (`s.prepend()`/`s.append()`, and inserts before the first or after the last
|
|
1556
|
+
* character) is not counted, so this can differ from `s.toString().length`.
|
|
1557
|
+
*/
|
|
1476
1558
|
length() {
|
|
1477
1559
|
let chunk = this.firstChunk;
|
|
1478
1560
|
let length = 0;
|
|
@@ -1504,10 +1586,11 @@ var MagicString = class MagicString {
|
|
|
1504
1586
|
const end = chunk.end;
|
|
1505
1587
|
const aborted = chunk.trimEnd(rx);
|
|
1506
1588
|
if (chunk.end !== end) {
|
|
1507
|
-
|
|
1589
|
+
const next = chunk.next;
|
|
1590
|
+
if (this.lastChunk === chunk) this.lastChunk = next;
|
|
1508
1591
|
this.byEnd.set(chunk.end, chunk);
|
|
1509
|
-
this.byStart.set(
|
|
1510
|
-
this.byEnd.set(
|
|
1592
|
+
this.byStart.set(next.start, next);
|
|
1593
|
+
this.byEnd.set(next.end, next);
|
|
1511
1594
|
}
|
|
1512
1595
|
if (aborted) return true;
|
|
1513
1596
|
chunk = chunk.previous;
|
|
@@ -1532,10 +1615,11 @@ var MagicString = class MagicString {
|
|
|
1532
1615
|
const end = chunk.end;
|
|
1533
1616
|
const aborted = chunk.trimStart(rx);
|
|
1534
1617
|
if (chunk.end !== end) {
|
|
1535
|
-
|
|
1618
|
+
const next = chunk.next;
|
|
1619
|
+
if (chunk === this.lastChunk) this.lastChunk = next;
|
|
1536
1620
|
this.byEnd.set(chunk.end, chunk);
|
|
1537
|
-
this.byStart.set(
|
|
1538
|
-
this.byEnd.set(
|
|
1621
|
+
this.byStart.set(next.start, next);
|
|
1622
|
+
this.byEnd.set(next.end, next);
|
|
1539
1623
|
}
|
|
1540
1624
|
if (aborted) return true;
|
|
1541
1625
|
chunk = chunk.next;
|
|
@@ -1577,30 +1661,29 @@ var MagicString = class MagicString {
|
|
|
1577
1661
|
* @internal
|
|
1578
1662
|
*/
|
|
1579
1663
|
_hasRemovedContent(start, end) {
|
|
1580
|
-
|
|
1581
|
-
if (
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
while (chunk && !chunk.contains(start)) chunk = searchForward ? this.byStart.get(chunk.end) : this.byEnd.get(chunk.start);
|
|
1585
|
-
if (chunk) this.lastSearchedChunk = chunk;
|
|
1664
|
+
const atBoundary = this.byStart.get(start);
|
|
1665
|
+
if (atBoundary && start === end) {
|
|
1666
|
+
const previous = this.byEnd.get(start);
|
|
1667
|
+
return !!previous && previous.content === "" && atBoundary.content === "";
|
|
1586
1668
|
}
|
|
1669
|
+
let chunk = this._chunkAt(start);
|
|
1587
1670
|
while (chunk && chunk.start < end) {
|
|
1588
|
-
if (chunk.content === "") return true;
|
|
1671
|
+
if (chunk.content === "" && (chunk.replacedFrom < start || this.byStart.get(chunk.replacedFrom).replacesUntil < chunk.end)) return true;
|
|
1589
1672
|
chunk = this.byStart.get(chunk.end);
|
|
1590
1673
|
}
|
|
1591
1674
|
return false;
|
|
1592
1675
|
}
|
|
1593
1676
|
/** @internal */
|
|
1594
1677
|
_replaceRegexp(searchValue, replacement) {
|
|
1595
|
-
function getReplacement(match, str) {
|
|
1596
|
-
if (typeof replacement === "string") return expandReplacement(replacement, match[0],
|
|
1597
|
-
else return match.groups === void 0 ? replacement(match[0], ...match.slice(1),
|
|
1678
|
+
function getReplacement(match, index, str) {
|
|
1679
|
+
if (typeof replacement === "string") return expandReplacement(replacement, match[0], index, str, match.slice(1), match.groups);
|
|
1680
|
+
else return match.groups === void 0 ? replacement(match[0], ...match.slice(1), index, str) : replacement(match[0], ...match.slice(1), index, str, match.groups);
|
|
1598
1681
|
}
|
|
1599
1682
|
const replaceMatch = (match) => {
|
|
1600
1683
|
/* v8 ignore next 2 -- `match.index` is always defined for matches from `matchAll` */
|
|
1601
1684
|
if (match.index == null) return false;
|
|
1602
1685
|
if (this._hasRemovedContent(match.index, match.index + match[0].length)) return false;
|
|
1603
|
-
const replacement = getReplacement(match, this.original);
|
|
1686
|
+
const replacement = getReplacement(match, match.index, this.original);
|
|
1604
1687
|
if (replacement === match[0]) return true;
|
|
1605
1688
|
if (match[0].length === 0) this.appendRight(match.index - this.offset, replacement);
|
|
1606
1689
|
else this.overwrite(match.index - this.offset, match.index + match[0].length - this.offset, replacement);
|
|
@@ -1682,7 +1765,7 @@ var Bundle$1 = class Bundle {
|
|
|
1682
1765
|
this.separator = options.separator !== void 0 ? options.separator : "\n";
|
|
1683
1766
|
this.sources = [];
|
|
1684
1767
|
this.uniqueSources = [];
|
|
1685
|
-
this.uniqueSourceIndexByFilename =
|
|
1768
|
+
this.uniqueSourceIndexByFilename = /* @__PURE__ */ new Map();
|
|
1686
1769
|
}
|
|
1687
1770
|
/**
|
|
1688
1771
|
* Adds the specified source to the bundle, which can either be a `MagicString` object directly,
|
|
@@ -1701,30 +1784,31 @@ var Bundle$1 = class Bundle {
|
|
|
1701
1784
|
separator: this.separator
|
|
1702
1785
|
});
|
|
1703
1786
|
if (!isObject(source) || !source.content) throw new MagicStringError("addSource() requires a `content` property that is a MagicString");
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
"
|
|
1708
|
-
"
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
}
|
|
1712
|
-
if (
|
|
1713
|
-
|
|
1714
|
-
if (
|
|
1715
|
-
this.uniqueSourceIndexByFilename
|
|
1787
|
+
const content = source.content;
|
|
1788
|
+
const record = {
|
|
1789
|
+
content,
|
|
1790
|
+
filename: hasOwnProp.call(source, "filename") ? source.filename : content.filename,
|
|
1791
|
+
ignoreList: hasOwnProp.call(source, "ignoreList") ? source.ignoreList : content.ignoreList,
|
|
1792
|
+
indentExclusionRanges: hasOwnProp.call(source, "indentExclusionRanges") ? source.indentExclusionRanges : content.indentExclusionRanges,
|
|
1793
|
+
separator: source.separator ?? this.separator
|
|
1794
|
+
};
|
|
1795
|
+
if (record.filename) {
|
|
1796
|
+
const index = this.uniqueSourceIndexByFilename.get(record.filename);
|
|
1797
|
+
if (index === void 0) {
|
|
1798
|
+
this.uniqueSourceIndexByFilename.set(record.filename, this.uniqueSources.length);
|
|
1716
1799
|
this.uniqueSources.push({
|
|
1717
|
-
filename:
|
|
1718
|
-
content:
|
|
1800
|
+
filename: record.filename,
|
|
1801
|
+
content: content.original
|
|
1719
1802
|
});
|
|
1720
|
-
} else {
|
|
1721
|
-
const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
|
|
1722
|
-
if (source.content.original !== uniqueSource.content) throw new MagicStringError(`duplicate filename "${source.filename}" with different content, use unique filenames`);
|
|
1723
|
-
}
|
|
1803
|
+
} else if (content.original !== this.uniqueSources[index].content) throw new MagicStringError(`duplicate filename "${record.filename}" with different content, use unique filenames`);
|
|
1724
1804
|
}
|
|
1725
|
-
this.sources.push(
|
|
1805
|
+
this.sources.push(record);
|
|
1726
1806
|
return this;
|
|
1727
1807
|
}
|
|
1808
|
+
/**
|
|
1809
|
+
* Appends `str` as a new source without a filename. Only `options.separator` is read, and it defaults to `''`
|
|
1810
|
+
* rather than to the bundle separator.
|
|
1811
|
+
*/
|
|
1728
1812
|
append(str, options) {
|
|
1729
1813
|
this.addSource({
|
|
1730
1814
|
content: new MagicString(str),
|
|
@@ -1732,6 +1816,10 @@ var Bundle$1 = class Bundle {
|
|
|
1732
1816
|
});
|
|
1733
1817
|
return this;
|
|
1734
1818
|
}
|
|
1819
|
+
/**
|
|
1820
|
+
* Returns an independent copy of the bundle: every source's `MagicString` is cloned, so later edits to either
|
|
1821
|
+
* bundle do not affect the other.
|
|
1822
|
+
*/
|
|
1735
1823
|
clone() {
|
|
1736
1824
|
const bundle = new Bundle({
|
|
1737
1825
|
intro: this.intro,
|
|
@@ -1767,12 +1855,12 @@ var Bundle$1 = class Bundle {
|
|
|
1767
1855
|
const byStart = /* @__PURE__ */ new Map();
|
|
1768
1856
|
const byEnd = /* @__PURE__ */ new Map();
|
|
1769
1857
|
let hasMovedChunks = false;
|
|
1770
|
-
this.sources.
|
|
1858
|
+
for (const [i, source] of this.sources.entries()) {
|
|
1771
1859
|
const magicString = source.content;
|
|
1772
|
-
const separator = i > 0 ? source.separator
|
|
1860
|
+
const separator = i > 0 ? source.separator : "";
|
|
1773
1861
|
if (magicString.original.length === 0) {
|
|
1774
1862
|
pending += separator + magicString.toString();
|
|
1775
|
-
|
|
1863
|
+
continue;
|
|
1776
1864
|
}
|
|
1777
1865
|
pending += separator + magicString.intro;
|
|
1778
1866
|
let sourceFirst = null;
|
|
@@ -1782,6 +1870,8 @@ var Bundle$1 = class Bundle {
|
|
|
1782
1870
|
const chunk = originalChunk.clone();
|
|
1783
1871
|
chunk.start += offset;
|
|
1784
1872
|
chunk.end += offset;
|
|
1873
|
+
if (chunk.replacesUntil !== -1) chunk.replacesUntil += offset;
|
|
1874
|
+
if (chunk.replacedFrom !== -1) chunk.replacedFrom += offset;
|
|
1785
1875
|
chunk.previous = previous;
|
|
1786
1876
|
chunk.next = null;
|
|
1787
1877
|
if (previous) previous.next = chunk;
|
|
@@ -1800,18 +1890,14 @@ var Bundle$1 = class Bundle {
|
|
|
1800
1890
|
sourceFirst.previous = last;
|
|
1801
1891
|
} else first = sourceFirst;
|
|
1802
1892
|
last = sourceLast;
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
Object.defineProperty(combined.storedNames, name, {
|
|
1806
|
-
writable: true,
|
|
1807
|
-
value: true,
|
|
1808
|
-
enumerable: true
|
|
1809
|
-
});
|
|
1893
|
+
magicString.sourcemapLocations.forEach((index) => {
|
|
1894
|
+
if (index < magicString.original.length) combined.sourcemapLocations.add(index + offset);
|
|
1810
1895
|
});
|
|
1896
|
+
magicString.storedNames.forEach((name) => combined.storedNames.add(name));
|
|
1811
1897
|
if (magicString.hasMovedChunks) hasMovedChunks = true;
|
|
1812
1898
|
offset += magicString.original.length;
|
|
1813
|
-
}
|
|
1814
|
-
if (!first) {
|
|
1899
|
+
}
|
|
1900
|
+
if (!first || !last) {
|
|
1815
1901
|
combined.intro = pending;
|
|
1816
1902
|
return combined;
|
|
1817
1903
|
}
|
|
@@ -1824,6 +1910,10 @@ var Bundle$1 = class Bundle {
|
|
|
1824
1910
|
combined.hasMovedChunks = hasMovedChunks;
|
|
1825
1911
|
return combined;
|
|
1826
1912
|
}
|
|
1913
|
+
/**
|
|
1914
|
+
* Generates a sourcemap object with raw mappings in array form, rather than encoded as a string.
|
|
1915
|
+
* Takes the same options as `generateMap`.
|
|
1916
|
+
*/
|
|
1827
1917
|
generateDecodedMap(options = {}) {
|
|
1828
1918
|
const mappings = new Mappings(options.hires);
|
|
1829
1919
|
const { names, x_google_ignoreList } = this._generateMappings(mappings);
|
|
@@ -1833,6 +1923,10 @@ var Bundle$1 = class Bundle {
|
|
|
1833
1923
|
rangeMappings: mappings.rawRangeMappings
|
|
1834
1924
|
};
|
|
1835
1925
|
}
|
|
1926
|
+
/**
|
|
1927
|
+
* Generates a version 3 sourcemap covering every source that has a `filename`.
|
|
1928
|
+
* Options are as per `MagicString#generateMap`, except that `includeContent` can also be a per-source function.
|
|
1929
|
+
*/
|
|
1836
1930
|
generateMap(options = {}) {
|
|
1837
1931
|
const encoder = new MappingsEncoder();
|
|
1838
1932
|
const mappings = new Mappings(options.hires, encoder);
|
|
@@ -1845,32 +1939,16 @@ var Bundle$1 = class Bundle {
|
|
|
1845
1939
|
}
|
|
1846
1940
|
/** @internal */
|
|
1847
1941
|
_generateMappings(mappings) {
|
|
1848
|
-
const names = [];
|
|
1849
1942
|
let x_google_ignoreList;
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
});
|
|
1943
|
+
const storedNames = /* @__PURE__ */ new Set();
|
|
1944
|
+
this.sources.forEach((source) => source.content.storedNames.forEach((name) => storedNames.add(name)));
|
|
1945
|
+
const names = [...storedNames];
|
|
1946
|
+
const nameIndex = new Map(names.map((name, i) => [name, i]));
|
|
1855
1947
|
if (this.intro) mappings.advance(this.intro);
|
|
1856
1948
|
this.sources.forEach((source, i) => {
|
|
1857
|
-
if (i > 0)
|
|
1858
|
-
|
|
1859
|
-
mappings.
|
|
1860
|
-
const sourceIndex = source.filename ? this.uniqueSourceIndexByFilename[source.filename] : -1;
|
|
1861
|
-
const magicString = source.content;
|
|
1862
|
-
const locate = getLocator(magicString.original);
|
|
1863
|
-
if (magicString.intro) mappings.advance(magicString.intro);
|
|
1864
|
-
magicString.firstChunk.eachNext((chunk) => {
|
|
1865
|
-
const loc = locate(chunk.start);
|
|
1866
|
-
if (chunk.intro.length) mappings.advance(chunk.intro);
|
|
1867
|
-
if (source.filename) {
|
|
1868
|
-
if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
|
|
1869
|
-
else mappings.addUneditedChunk(sourceIndex, chunk, magicString.original, loc, magicString.sourcemapLocations);
|
|
1870
|
-
} else mappings.advance(chunk.content);
|
|
1871
|
-
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
1872
|
-
});
|
|
1873
|
-
if (magicString.outro) mappings.advance(magicString.outro);
|
|
1949
|
+
if (i > 0) mappings.advance(source.separator);
|
|
1950
|
+
const sourceIndex = source.filename ? this.uniqueSourceIndexByFilename.get(source.filename) ?? -1 : -1;
|
|
1951
|
+
mappings.addMagicString(source.content, sourceIndex, nameIndex);
|
|
1874
1952
|
if (source.ignoreList && sourceIndex !== -1) {
|
|
1875
1953
|
if (x_google_ignoreList === void 0) x_google_ignoreList = [];
|
|
1876
1954
|
x_google_ignoreList.push(sourceIndex);
|
|
@@ -1895,91 +1973,111 @@ var Bundle$1 = class Bundle {
|
|
|
1895
1973
|
x_google_ignoreList
|
|
1896
1974
|
};
|
|
1897
1975
|
}
|
|
1976
|
+
/**
|
|
1977
|
+
* Returns the most common indent string among the sources, falling back to a tab.
|
|
1978
|
+
*/
|
|
1898
1979
|
getIndentString() {
|
|
1899
|
-
const indentStringCounts =
|
|
1980
|
+
const indentStringCounts = /* @__PURE__ */ new Map();
|
|
1900
1981
|
this.sources.forEach((source) => {
|
|
1901
1982
|
const indentStr = source.content._getRawIndentString();
|
|
1902
|
-
if (indentStr
|
|
1903
|
-
|
|
1904
|
-
indentStringCounts[indentStr] += 1;
|
|
1983
|
+
if (indentStr == null) return;
|
|
1984
|
+
indentStringCounts.set(indentStr, (indentStringCounts.get(indentStr) ?? 0) + 1);
|
|
1905
1985
|
});
|
|
1906
|
-
return
|
|
1907
|
-
return indentStringCounts[b] - indentStringCounts[a];
|
|
1908
|
-
})[0] || " ";
|
|
1986
|
+
return [...indentStringCounts.entries()].sort(([, a], [, b]) => b - a)[0]?.[0] ?? " ";
|
|
1909
1987
|
}
|
|
1988
|
+
/**
|
|
1989
|
+
* Prefixes each line of every source and of the intro with `indentStr`, guessed with `getIndentString()`
|
|
1990
|
+
* when not supplied. Each source's `indentExclusionRanges` are left unindented.
|
|
1991
|
+
*/
|
|
1910
1992
|
indent(indentStr) {
|
|
1911
1993
|
if (!arguments.length) indentStr = this.getIndentString();
|
|
1912
1994
|
if (indentStr === "") return this;
|
|
1913
1995
|
let trailingNewline = !this.intro || this.intro.slice(-1) === "\n";
|
|
1914
1996
|
this.sources.forEach((source, i) => {
|
|
1915
|
-
|
|
1916
|
-
const separator = source.separator !== void 0 ? source.separator : this.separator;
|
|
1917
|
-
const indentStart = trailingNewline || i > 0 && /\r?\n$/.test(separator);
|
|
1997
|
+
const indentStart = trailingNewline || i > 0 && /\r?\n$/.test(source.separator);
|
|
1918
1998
|
source.content.indent(indentStr, {
|
|
1919
1999
|
exclude: source.indentExclusionRanges,
|
|
1920
2000
|
indentStart
|
|
1921
2001
|
});
|
|
1922
2002
|
trailingNewline = source.content.lastChar() === "\n";
|
|
1923
2003
|
});
|
|
1924
|
-
if (this.intro) this.intro = indentStr + this.intro.replace(/^[^\n]/gm, (match, index) => {
|
|
2004
|
+
if (this.intro) this.intro = indentStr + this.intro.replace(/^[^\r\n]/gm, (match, index) => {
|
|
1925
2005
|
return index > 0 ? indentStr + match : match;
|
|
1926
2006
|
});
|
|
1927
2007
|
return this;
|
|
1928
2008
|
}
|
|
2009
|
+
/**
|
|
2010
|
+
* Prepends `str` to the bundle's intro.
|
|
2011
|
+
*/
|
|
1929
2012
|
prepend(str) {
|
|
1930
2013
|
this.intro = str + this.intro;
|
|
1931
2014
|
return this;
|
|
1932
2015
|
}
|
|
2016
|
+
/**
|
|
2017
|
+
* Returns the intro followed by every source's generated string, joined by their separators.
|
|
2018
|
+
*/
|
|
1933
2019
|
toString() {
|
|
1934
2020
|
const body = this.sources.map((source, i) => {
|
|
1935
|
-
|
|
1936
|
-
const separator = source.separator !== void 0 ? source.separator : this.separator;
|
|
1937
|
-
return (i > 0 ? separator : "") + source.content.toString();
|
|
2021
|
+
return (i > 0 ? source.separator : "") + source.content.toString();
|
|
1938
2022
|
}).join("");
|
|
1939
2023
|
return this.intro + body;
|
|
1940
2024
|
}
|
|
2025
|
+
/**
|
|
2026
|
+
* Returns true if the bundle's output is empty (disregarding white space).
|
|
2027
|
+
*/
|
|
1941
2028
|
isEmpty() {
|
|
1942
2029
|
if (this.intro.length && this.intro.trim()) return false;
|
|
1943
2030
|
if (this.sources.some((source, i) => {
|
|
1944
|
-
|
|
1945
|
-
const separator = source.separator !== void 0 ? source.separator : this.separator;
|
|
1946
|
-
return i > 0 && separator.trim() !== "" || !source.content.isEmpty();
|
|
2031
|
+
return i > 0 && source.separator.trim() !== "" || !source.content.isEmpty();
|
|
1947
2032
|
})) return false;
|
|
1948
2033
|
return true;
|
|
1949
2034
|
}
|
|
2035
|
+
/**
|
|
2036
|
+
* Returns the length of the bundle's output; unlike `MagicString#length`, this equals `bundle.toString().length`.
|
|
2037
|
+
*/
|
|
1950
2038
|
length() {
|
|
1951
2039
|
return this.sources.reduce((length, source, i) => {
|
|
1952
|
-
|
|
1953
|
-
const separator = source.separator !== void 0 ? source.separator : this.separator;
|
|
1954
|
-
return length + (i > 0 ? separator.length : 0) + source.content.toString().length;
|
|
2040
|
+
return length + (i > 0 ? source.separator.length : 0) + source.content.length() + source.content.intro.length + source.content.outro.length;
|
|
1955
2041
|
}, this.intro.length);
|
|
1956
2042
|
}
|
|
2043
|
+
/**
|
|
2044
|
+
* Removes empty lines from the start and end.
|
|
2045
|
+
*/
|
|
1957
2046
|
trimLines() {
|
|
1958
2047
|
return this.trim("[\\r\\n]");
|
|
1959
2048
|
}
|
|
2049
|
+
/**
|
|
2050
|
+
* Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start and end.
|
|
2051
|
+
*/
|
|
1960
2052
|
trim(charType) {
|
|
1961
2053
|
return this.trimStart(charType).trimEnd(charType);
|
|
1962
2054
|
}
|
|
2055
|
+
/**
|
|
2056
|
+
* Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start.
|
|
2057
|
+
*/
|
|
1963
2058
|
trimStart(charType) {
|
|
1964
2059
|
const rx = new RegExp(`^${charType || "\\s"}+`);
|
|
1965
2060
|
this.intro = this.intro.replace(rx, "");
|
|
1966
2061
|
if (!this.intro) for (let i = 0; i < this.sources.length; i += 1) {
|
|
1967
2062
|
const source = this.sources[i];
|
|
1968
2063
|
if (i > 0) {
|
|
1969
|
-
source.separator =
|
|
2064
|
+
source.separator = source.separator.replace(rx, "");
|
|
1970
2065
|
if (source.separator) break;
|
|
1971
2066
|
}
|
|
1972
2067
|
if (source.content.trimStartAborted(charType)) break;
|
|
1973
2068
|
}
|
|
1974
2069
|
return this;
|
|
1975
2070
|
}
|
|
2071
|
+
/**
|
|
2072
|
+
* Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the end.
|
|
2073
|
+
*/
|
|
1976
2074
|
trimEnd(charType) {
|
|
1977
2075
|
const rx = new RegExp(`${charType || "\\s"}+$`);
|
|
1978
2076
|
for (let i = this.sources.length - 1; i >= 0; i -= 1) {
|
|
1979
2077
|
const source = this.sources[i];
|
|
1980
2078
|
if (source.content.trimEndAborted(charType)) return this;
|
|
1981
2079
|
if (i > 0) {
|
|
1982
|
-
source.separator =
|
|
2080
|
+
source.separator = source.separator.replace(rx, "");
|
|
1983
2081
|
if (source.separator) return this;
|
|
1984
2082
|
}
|
|
1985
2083
|
}
|
|
@@ -2214,8 +2312,8 @@ const UnknownNonAccessorKey = Symbol('Unknown Non-Accessor Key');
|
|
|
2214
2312
|
const UnknownInteger = Symbol('Unknown Integer');
|
|
2215
2313
|
const UnknownWellKnown = Symbol('Unknown Well-Known');
|
|
2216
2314
|
const SymbolToStringTag = Symbol('Symbol.toStringTag');
|
|
2217
|
-
const SymbolDispose = Symbol('Symbol.
|
|
2218
|
-
const SymbolAsyncDispose = Symbol('Symbol.
|
|
2315
|
+
const SymbolDispose = Symbol('Symbol.dispose');
|
|
2316
|
+
const SymbolAsyncDispose = Symbol('Symbol.asyncDispose');
|
|
2219
2317
|
const SymbolHasInstance = Symbol('Symbol.hasInstance');
|
|
2220
2318
|
const WELL_KNOWN_SYMBOLS_LIST = [
|
|
2221
2319
|
SymbolToStringTag,
|
|
@@ -2322,6 +2420,25 @@ class IncludedFullPathTracker {
|
|
|
2322
2420
|
}
|
|
2323
2421
|
return included;
|
|
2324
2422
|
}
|
|
2423
|
+
includeAllPaths(entity, context, basePath) {
|
|
2424
|
+
if (this.includedPaths) {
|
|
2425
|
+
includeAllSubPaths(entity, context, basePath, this.includedPaths);
|
|
2426
|
+
}
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
function includeAllSubPaths(entity, context, path, includedPaths) {
|
|
2430
|
+
if (includedPaths[UnknownKey]) {
|
|
2431
|
+
entity.includePath([...path, UnknownKey], context);
|
|
2432
|
+
return;
|
|
2433
|
+
}
|
|
2434
|
+
const keys = Reflect.ownKeys(includedPaths);
|
|
2435
|
+
if (keys.length === 0) {
|
|
2436
|
+
entity.includePath(path, context);
|
|
2437
|
+
return;
|
|
2438
|
+
}
|
|
2439
|
+
for (const key of keys) {
|
|
2440
|
+
includeAllSubPaths(entity, context, [...path, key], includedPaths[key]);
|
|
2441
|
+
}
|
|
2325
2442
|
}
|
|
2326
2443
|
const UNKNOWN_INCLUDED_TOP_LEVEL_PATH = Object.freeze({
|
|
2327
2444
|
[UnknownKey]: true
|
|
@@ -2365,13 +2482,15 @@ class IncludedTopLevelPathTracker {
|
|
|
2365
2482
|
entity.includePath([...basePath, UnknownKey], context);
|
|
2366
2483
|
}
|
|
2367
2484
|
else {
|
|
2368
|
-
const
|
|
2369
|
-
if (
|
|
2485
|
+
const keys = Reflect.ownKeys(includedPaths);
|
|
2486
|
+
if (keys.length === 0) {
|
|
2370
2487
|
entity.includePath(basePath, context);
|
|
2371
2488
|
}
|
|
2372
2489
|
else {
|
|
2373
|
-
for (const
|
|
2374
|
-
entity.includePath(
|
|
2490
|
+
for (const key of keys) {
|
|
2491
|
+
entity.includePath(includedPaths[key] === UnknownKey
|
|
2492
|
+
? [...basePath, key, UnknownKey]
|
|
2493
|
+
: [...basePath, key], context);
|
|
2375
2494
|
}
|
|
2376
2495
|
}
|
|
2377
2496
|
}
|
|
@@ -2403,6 +2522,9 @@ class ExpressionEntity {
|
|
|
2403
2522
|
deoptimizeInteraction(interaction);
|
|
2404
2523
|
}
|
|
2405
2524
|
deoptimizePath(_path) { }
|
|
2525
|
+
getKnownFunctionAtPath(_path, _recursionTracker, _origin) {
|
|
2526
|
+
return null;
|
|
2527
|
+
}
|
|
2406
2528
|
/**
|
|
2407
2529
|
* If possible it returns a stringifyable literal value for this node that
|
|
2408
2530
|
* can be used for inlining or comparing values. Otherwise, it should return
|
|
@@ -3047,6 +3169,15 @@ class LocalVariable extends Variable {
|
|
|
3047
3169
|
this.init.deoptimizePath(limitConcatenatedPathDepth(this.initPath, path));
|
|
3048
3170
|
}
|
|
3049
3171
|
}
|
|
3172
|
+
getKnownFunctionAtPath(path, recursionTracker, origin) {
|
|
3173
|
+
if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
|
|
3174
|
+
return null;
|
|
3175
|
+
}
|
|
3176
|
+
return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
|
|
3177
|
+
this.expressionsToBeDeoptimized.push(origin);
|
|
3178
|
+
return this.init.getKnownFunctionAtPath([...this.initPath, ...path], recursionTracker, origin);
|
|
3179
|
+
}, null);
|
|
3180
|
+
}
|
|
3050
3181
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
3051
3182
|
if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
|
|
3052
3183
|
return UnknownValue;
|
|
@@ -4061,6 +4192,17 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
4061
4192
|
}
|
|
4062
4193
|
this.prototypeExpression?.deoptimizePath(path.length === 1 ? [path[0], UnknownKey] : path);
|
|
4063
4194
|
}
|
|
4195
|
+
getKnownFunctionAtPath(path, recursionTracker, origin) {
|
|
4196
|
+
const key = path[0];
|
|
4197
|
+
// Setters can shadow data properties or inherited methods without appearing in the getter map.
|
|
4198
|
+
if (!isConcreteKey(key) || this.settersByKey.has(key) || this.unmatchableSetters.length > 0) {
|
|
4199
|
+
return null;
|
|
4200
|
+
}
|
|
4201
|
+
const expressionAtPath = this.getMemberExpressionAndTrackDeopt(key, origin);
|
|
4202
|
+
return expressionAtPath
|
|
4203
|
+
? expressionAtPath.getKnownFunctionAtPath(path.slice(1), recursionTracker, origin)
|
|
4204
|
+
: this.prototypeExpression?.getKnownFunctionAtPath(path, recursionTracker, origin) || null;
|
|
4205
|
+
}
|
|
4064
4206
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
4065
4207
|
if (path.length === 0) {
|
|
4066
4208
|
// This should actually be "UnknownTruthyValue". However, this currently
|
|
@@ -4317,22 +4459,25 @@ class ObjectEntity extends ExpressionEntity {
|
|
|
4317
4459
|
}
|
|
4318
4460
|
}
|
|
4319
4461
|
|
|
4320
|
-
const
|
|
4462
|
+
const isKnownToBeMissing = (property) => property === SymbolDispose ||
|
|
4463
|
+
property === SymbolAsyncDispose ||
|
|
4464
|
+
(typeof property === 'string' && /^\d+$/.test(property));
|
|
4321
4465
|
// This makes sure unknown properties are not handled as "undefined" but as
|
|
4322
4466
|
// "unknown" but without access side effects. An exception is done for numeric
|
|
4323
4467
|
// properties as we do not expect new builtin properties to be numbers, this
|
|
4324
|
-
// will improve tree-shaking for out-of-bounds array properties
|
|
4468
|
+
// will improve tree-shaking for out-of-bounds array properties. Disposal
|
|
4469
|
+
// methods are also known to be missing so that "await using" can rely on the
|
|
4470
|
+
// fallback to Symbol.dispose for plain objects.
|
|
4325
4471
|
const OBJECT_PROTOTYPE_FALLBACK = new (class ObjectPrototypeFallbackExpression extends ExpressionEntity {
|
|
4326
4472
|
deoptimizeArgumentsOnInteractionAtPath(interaction, path) {
|
|
4327
|
-
if (interaction.type === INTERACTION_CALLED &&
|
|
4473
|
+
if (interaction.type === INTERACTION_CALLED &&
|
|
4474
|
+
path.length === 1 &&
|
|
4475
|
+
!isKnownToBeMissing(path[0])) {
|
|
4328
4476
|
deoptimizeInteraction(interaction);
|
|
4329
4477
|
}
|
|
4330
4478
|
}
|
|
4331
4479
|
getLiteralValueAtPath(path) {
|
|
4332
|
-
|
|
4333
|
-
// numbers and also want to keep handling out-of-bound array elements as
|
|
4334
|
-
// "undefined"
|
|
4335
|
-
return path.length === 1 && isInteger(path[0]) ? undefined : UnknownValue;
|
|
4480
|
+
return path.length === 1 && isKnownToBeMissing(path[0]) ? undefined : UnknownValue;
|
|
4336
4481
|
}
|
|
4337
4482
|
hasEffectsOnInteractionAtPath(path, { type }) {
|
|
4338
4483
|
return path.length > 1 || type === INTERACTION_CALLED;
|
|
@@ -4346,6 +4491,9 @@ const OBJECT_PROTOTYPE = new ObjectEntity(new Map([
|
|
|
4346
4491
|
['toString', METHOD_RETURNS_STRING],
|
|
4347
4492
|
['valueOf', METHOD_RETURNS_UNKNOWN]
|
|
4348
4493
|
]), OBJECT_PROTOTYPE_FALLBACK, true);
|
|
4494
|
+
// Generator prototypes inherit disposal methods from the iterator prototypes
|
|
4495
|
+
const GENERATOR_PROTOTYPE = new ObjectEntity([{ key: SymbolDispose, kind: 'init', property: UNKNOWN_EXPRESSION }], OBJECT_PROTOTYPE, true);
|
|
4496
|
+
const ASYNC_GENERATOR_PROTOTYPE = new ObjectEntity([{ key: SymbolAsyncDispose, kind: 'init', property: UNKNOWN_EXPRESSION }], OBJECT_PROTOTYPE, true);
|
|
4349
4497
|
|
|
4350
4498
|
const NEW_ARRAY_PROPERTIES = [
|
|
4351
4499
|
{ key: UnknownInteger, kind: 'init', property: UNKNOWN_EXPRESSION },
|
|
@@ -4490,7 +4638,8 @@ const ARRAY_PROTOTYPE = new ObjectEntity(new Map([
|
|
|
4490
4638
|
|
|
4491
4639
|
class SpreadElement extends NodeBase {
|
|
4492
4640
|
deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
4493
|
-
|
|
4641
|
+
// Spread values are copied as data properties, so only calling them can still reach the argument
|
|
4642
|
+
if (path.length > 0 || interaction.type === INTERACTION_CALLED) {
|
|
4494
4643
|
this.argument.deoptimizeArgumentsOnInteractionAtPath(interaction, UNKNOWN_PATH, recursionTracker);
|
|
4495
4644
|
}
|
|
4496
4645
|
}
|
|
@@ -5665,6 +5814,9 @@ class IdentifierBase extends NodeBase {
|
|
|
5665
5814
|
// Identifier as property that might be deoptimized by default
|
|
5666
5815
|
this.variable?.deoptimizePath(path);
|
|
5667
5816
|
}
|
|
5817
|
+
getKnownFunctionAtPath(path, recursionTracker, origin) {
|
|
5818
|
+
return this.getVariableRespectingTDZ().getKnownFunctionAtPath(path, recursionTracker, origin);
|
|
5819
|
+
}
|
|
5668
5820
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
5669
5821
|
return this.getVariableRespectingTDZ().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
5670
5822
|
}
|
|
@@ -5976,6 +6128,11 @@ class PropertyBase extends NodeBase {
|
|
|
5976
6128
|
deoptimizePath(path) {
|
|
5977
6129
|
this.getAccessedValue()[0].deoptimizePath(path);
|
|
5978
6130
|
}
|
|
6131
|
+
getKnownFunctionAtPath(path, recursionTracker, origin) {
|
|
6132
|
+
return this.kind === 'get' || this.kind === 'set'
|
|
6133
|
+
? null
|
|
6134
|
+
: this.value.getKnownFunctionAtPath(path, recursionTracker, origin);
|
|
6135
|
+
}
|
|
5979
6136
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
5980
6137
|
return this.getAccessedValue()[0].getLiteralValueAtPath(path, recursionTracker, origin);
|
|
5981
6138
|
}
|
|
@@ -6489,6 +6646,8 @@ class ParameterVariable extends LocalVariable {
|
|
|
6489
6646
|
class ThisVariable extends ParameterVariable {
|
|
6490
6647
|
constructor(context) {
|
|
6491
6648
|
super('this', null, EMPTY_PATH, context);
|
|
6649
|
+
// Unlike parameters, track nested paths so receivers only keep what is accessed via "this"
|
|
6650
|
+
this.includedPathTracker = new IncludedFullPathTracker();
|
|
6492
6651
|
}
|
|
6493
6652
|
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
6494
6653
|
return (context.replacedVariableInits.get(this) || UNKNOWN_EXPRESSION).hasEffectsOnInteractionAtPath(path, interaction, context);
|
|
@@ -6793,8 +6952,11 @@ class FunctionScope extends ReturnValueScope {
|
|
|
6793
6952
|
}
|
|
6794
6953
|
includeCallArguments(interaction, context) {
|
|
6795
6954
|
super.includeCallArguments(interaction, context);
|
|
6955
|
+
const { args } = interaction;
|
|
6956
|
+
if (args[0]) {
|
|
6957
|
+
this.thisVariable.includeArgumentPaths(args[0], context);
|
|
6958
|
+
}
|
|
6796
6959
|
if (this.argumentsVariable.included) {
|
|
6797
|
-
const { args } = interaction;
|
|
6798
6960
|
for (let argumentIndex = 1; argumentIndex < args.length; argumentIndex++) {
|
|
6799
6961
|
const argument = args[argumentIndex];
|
|
6800
6962
|
if (argument) {
|
|
@@ -6979,6 +7141,11 @@ class FunctionBase extends NodeBase {
|
|
|
6979
7141
|
this.scope.deoptimizeAllParameters();
|
|
6980
7142
|
}
|
|
6981
7143
|
}
|
|
7144
|
+
getKnownFunctionAtPath(path, recursionTracker, origin) {
|
|
7145
|
+
return path.length === 0
|
|
7146
|
+
? this
|
|
7147
|
+
: this.getObjectEntity().getKnownFunctionAtPath(path, recursionTracker, origin);
|
|
7148
|
+
}
|
|
6982
7149
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
6983
7150
|
return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
6984
7151
|
}
|
|
@@ -6986,7 +7153,7 @@ class FunctionBase extends NodeBase {
|
|
|
6986
7153
|
if (path.length > 0) {
|
|
6987
7154
|
return this.getObjectEntity().getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin);
|
|
6988
7155
|
}
|
|
6989
|
-
if (this.async) {
|
|
7156
|
+
if (this.async || this.generator) {
|
|
6990
7157
|
if (!this.deoptimizedReturn) {
|
|
6991
7158
|
this.deoptimizedReturn = true;
|
|
6992
7159
|
this.scope.getReturnExpression().deoptimizePath(UNKNOWN_PATH);
|
|
@@ -7171,10 +7338,15 @@ class FunctionNode extends FunctionBase {
|
|
|
7171
7338
|
{
|
|
7172
7339
|
key: 'prototype',
|
|
7173
7340
|
kind: 'init',
|
|
7174
|
-
property: new ObjectEntity([],
|
|
7341
|
+
property: new ObjectEntity([], this.getPrototypeOfPrototype())
|
|
7175
7342
|
}
|
|
7176
7343
|
], OBJECT_PROTOTYPE));
|
|
7177
7344
|
}
|
|
7345
|
+
getPrototypeOfPrototype() {
|
|
7346
|
+
if (!this.generator)
|
|
7347
|
+
return OBJECT_PROTOTYPE;
|
|
7348
|
+
return this.async ? ASYNC_GENERATOR_PROTOTYPE : GENERATOR_PROTOTYPE;
|
|
7349
|
+
}
|
|
7178
7350
|
}
|
|
7179
7351
|
|
|
7180
7352
|
class FunctionDeclaration extends FunctionNode {
|
|
@@ -7306,12 +7478,19 @@ ExportDefaultDeclaration.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
|
|
|
7306
7478
|
ExportDefaultDeclaration.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
7307
7479
|
|
|
7308
7480
|
const needsEscapeRegEx = /[\n\r'\\\u2028\u2029]/;
|
|
7309
|
-
const
|
|
7310
|
-
const
|
|
7481
|
+
const escapeRegEx = /[\n\r'\\\u2028\u2029]/g;
|
|
7482
|
+
const escapeReplacements = {
|
|
7483
|
+
'\n': '\\n',
|
|
7484
|
+
'\r': '\\r',
|
|
7485
|
+
"'": "\\'",
|
|
7486
|
+
'\\': '\\\\',
|
|
7487
|
+
'\u2028': '\\u2028',
|
|
7488
|
+
'\u2029': '\\u2029'
|
|
7489
|
+
};
|
|
7311
7490
|
function escapeId(id) {
|
|
7312
7491
|
if (!needsEscapeRegEx.test(id))
|
|
7313
7492
|
return id;
|
|
7314
|
-
return id.replace(
|
|
7493
|
+
return id.replace(escapeRegEx, character => escapeReplacements[character]);
|
|
7315
7494
|
}
|
|
7316
7495
|
|
|
7317
7496
|
const INTEROP_DEFAULT_VARIABLE = '_interopDefault';
|
|
@@ -7727,6 +7906,20 @@ class MemberExpression extends NodeBase {
|
|
|
7727
7906
|
]);
|
|
7728
7907
|
}
|
|
7729
7908
|
}
|
|
7909
|
+
getKnownFunctionAtPath(path, recursionTracker, origin) {
|
|
7910
|
+
if (this.variable) {
|
|
7911
|
+
return this.variable.getKnownFunctionAtPath(path, recursionTracker, origin);
|
|
7912
|
+
}
|
|
7913
|
+
if (this.isUndefined)
|
|
7914
|
+
return null;
|
|
7915
|
+
const propertyKey = this.getDynamicPropertyKey();
|
|
7916
|
+
if (propertyKey !== UnknownKey && path.length < MAX_PATH_DEPTH) {
|
|
7917
|
+
if (propertyKey !== this.propertyKey)
|
|
7918
|
+
this.expressionsToBeDeoptimized.push(origin);
|
|
7919
|
+
return this.object.getKnownFunctionAtPath([propertyKey, ...path], recursionTracker, origin);
|
|
7920
|
+
}
|
|
7921
|
+
return null;
|
|
7922
|
+
}
|
|
7730
7923
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
7731
7924
|
if (this.variable) {
|
|
7732
7925
|
return this.variable.getLiteralValueAtPath(path, recursionTracker, origin);
|
|
@@ -12043,17 +12236,29 @@ function getMatcherString$1(id, resolutionBase) {
|
|
|
12043
12236
|
}
|
|
12044
12237
|
const createFilter$1 = function createFilter(include, exclude, options) {
|
|
12045
12238
|
const resolutionBase = options && options.resolve;
|
|
12046
|
-
const getMatcher = (id) =>
|
|
12047
|
-
|
|
12048
|
-
|
|
12239
|
+
const getMatcher = (id) => {
|
|
12240
|
+
if (id instanceof RegExp) {
|
|
12241
|
+
return id;
|
|
12242
|
+
}
|
|
12243
|
+
// Compiling a pattern costs far more than matching against it, so only recompile when the cwd it resolves against changes
|
|
12244
|
+
const compile = () => picomatch(getMatcherString$1(id, resolutionBase), { dot: true });
|
|
12245
|
+
// These patterns never resolve against the cwd, so there is no need to read or track it
|
|
12246
|
+
if (resolutionBase === false || isAbsolute(id) || id.startsWith('**')) {
|
|
12247
|
+
return { test: compile() };
|
|
12248
|
+
}
|
|
12249
|
+
let compiledCwd = process.cwd();
|
|
12250
|
+
let fn = compile();
|
|
12251
|
+
return {
|
|
12049
12252
|
test: (what) => {
|
|
12050
|
-
|
|
12051
|
-
|
|
12052
|
-
|
|
12053
|
-
|
|
12054
|
-
|
|
12253
|
+
const cwd = process.cwd();
|
|
12254
|
+
if (cwd !== compiledCwd) {
|
|
12255
|
+
compiledCwd = cwd;
|
|
12256
|
+
fn = compile();
|
|
12257
|
+
}
|
|
12258
|
+
return fn(what);
|
|
12055
12259
|
}
|
|
12056
12260
|
};
|
|
12261
|
+
};
|
|
12057
12262
|
const includeMatchers = ensureArray$1(include).map(getMatcher);
|
|
12058
12263
|
const excludeMatchers = ensureArray$1(exclude).map(getMatcher);
|
|
12059
12264
|
if (!includeMatchers.length && !excludeMatchers.length)
|
|
@@ -14233,19 +14438,17 @@ class JSXAttribute extends NodeBase {
|
|
|
14233
14438
|
}
|
|
14234
14439
|
if (value) {
|
|
14235
14440
|
code.overwrite(name.end, value.start, ': ', { contentOnly: true });
|
|
14236
|
-
// foo="aa \n aa"
|
|
14237
|
-
if (value instanceof Literal &&
|
|
14238
|
-
typeof value.value === 'string' &&
|
|
14239
|
-
value.value.includes('\n')) {
|
|
14240
|
-
code.overwrite(value.start, value.end, JSON.stringify(value.value), {
|
|
14241
|
-
contentOnly: true
|
|
14242
|
-
});
|
|
14243
|
-
}
|
|
14244
14441
|
}
|
|
14245
14442
|
else {
|
|
14246
14443
|
code.appendLeft(name.end, ': true');
|
|
14247
14444
|
}
|
|
14248
14445
|
}
|
|
14446
|
+
// JSX strings contain HTML entities but no escape sequences
|
|
14447
|
+
if (value instanceof Literal && typeof value.value === 'string') {
|
|
14448
|
+
code.overwrite(value.start, value.end, JSON.stringify(value.value), {
|
|
14449
|
+
contentOnly: true
|
|
14450
|
+
});
|
|
14451
|
+
}
|
|
14249
14452
|
}
|
|
14250
14453
|
}
|
|
14251
14454
|
}
|
|
@@ -15030,6 +15233,9 @@ class ObjectExpression extends NodeBase {
|
|
|
15030
15233
|
deoptimizePath(path) {
|
|
15031
15234
|
this.getObjectEntity().deoptimizePath(path);
|
|
15032
15235
|
}
|
|
15236
|
+
getKnownFunctionAtPath(path, recursionTracker, origin) {
|
|
15237
|
+
return this.getObjectEntity().getKnownFunctionAtPath(path, recursionTracker, origin);
|
|
15238
|
+
}
|
|
15033
15239
|
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
15034
15240
|
return this.getObjectEntity().getLiteralValueAtPath(path, recursionTracker, origin);
|
|
15035
15241
|
}
|
|
@@ -16280,6 +16486,14 @@ class VariableDeclarator extends NodeBase {
|
|
|
16280
16486
|
deoptimizePath(path) {
|
|
16281
16487
|
this.id.deoptimizePath(path);
|
|
16282
16488
|
}
|
|
16489
|
+
deoptimizeCache() {
|
|
16490
|
+
if (!this.hasDeoptimizedDisposal && this.init) {
|
|
16491
|
+
this.hasDeoptimizedDisposal = true;
|
|
16492
|
+
this.init.deoptimizePath(UNKNOWN_PATH);
|
|
16493
|
+
this.init.includePath(UNKNOWN_PATH, createInclusionContext());
|
|
16494
|
+
this.scope.context.requestTreeshakingPass();
|
|
16495
|
+
}
|
|
16496
|
+
}
|
|
16283
16497
|
hasEffects(context) {
|
|
16284
16498
|
const initEffect = this.init?.hasEffects(context);
|
|
16285
16499
|
this.id.markDeclarationReached();
|
|
@@ -16295,6 +16509,11 @@ class VariableDeclarator extends NodeBase {
|
|
|
16295
16509
|
const { id, init } = this;
|
|
16296
16510
|
if (!this.included)
|
|
16297
16511
|
this.includeNode(context);
|
|
16512
|
+
const { disposalCall, disposalFunction } = this;
|
|
16513
|
+
// Before including init so that newly included receiver paths are included in this pass
|
|
16514
|
+
if (disposalFunction && disposalCall) {
|
|
16515
|
+
disposalFunction.includeCallArgumentsWhenCalledAtPath(EMPTY_PATH, disposalCall, context);
|
|
16516
|
+
}
|
|
16298
16517
|
init?.include(context, includeChildrenRecursively);
|
|
16299
16518
|
id.markDeclarationReached();
|
|
16300
16519
|
if (includeChildrenRecursively) {
|
|
@@ -16336,11 +16555,16 @@ class VariableDeclarator extends NodeBase {
|
|
|
16336
16555
|
this.included = true;
|
|
16337
16556
|
const { id, init } = this;
|
|
16338
16557
|
if (init) {
|
|
16339
|
-
if (this.isUsingDeclaration) {
|
|
16340
|
-
|
|
16341
|
-
|
|
16342
|
-
|
|
16343
|
-
|
|
16558
|
+
if (this.isUsingDeclaration || this.isAsyncUsingDeclaration) {
|
|
16559
|
+
const disposalInteractions = {
|
|
16560
|
+
access: { args: [init], type: INTERACTION_ACCESSED },
|
|
16561
|
+
call: { args: [init], type: INTERACTION_CALLED, withNew: false }
|
|
16562
|
+
};
|
|
16563
|
+
if (this.isUsingDeclaration ||
|
|
16564
|
+
!this.includeDisposalMethodAndCheckIfKnownFunction(init, SYMBOL_ASYNC_DISPOSE_PATH, disposalInteractions, context)) {
|
|
16565
|
+
this.includeDisposalMethodAndCheckIfKnownFunction(init, SYMBOL_DISPOSE_PATH, disposalInteractions, context);
|
|
16566
|
+
}
|
|
16567
|
+
this.scope.context.requestTreeshakingPass();
|
|
16344
16568
|
}
|
|
16345
16569
|
if (id instanceof Identifier && init instanceof ClassExpression && !init.id) {
|
|
16346
16570
|
const { name, variable } = id;
|
|
@@ -16352,6 +16576,23 @@ class VariableDeclarator extends NodeBase {
|
|
|
16352
16576
|
}
|
|
16353
16577
|
}
|
|
16354
16578
|
}
|
|
16579
|
+
includeDisposalMethodAndCheckIfKnownFunction(init, path, { access, call }, context) {
|
|
16580
|
+
init.deoptimizeArgumentsOnInteractionAtPath(access, path, SHARED_RECURSION_TRACKER);
|
|
16581
|
+
const disposalFunction = init.getKnownFunctionAtPath(path, SHARED_RECURSION_TRACKER, this);
|
|
16582
|
+
init.includePath(path, context);
|
|
16583
|
+
if (!disposalFunction) {
|
|
16584
|
+
const disposalValue = init.getLiteralValueAtPath(path, SHARED_RECURSION_TRACKER, this);
|
|
16585
|
+
if (disposalValue !== null && disposalValue !== undefined) {
|
|
16586
|
+
init.deoptimizeArgumentsOnInteractionAtPath(call, path, SHARED_RECURSION_TRACKER);
|
|
16587
|
+
init.includeCallArgumentsWhenCalledAtPath(path, call, context);
|
|
16588
|
+
}
|
|
16589
|
+
return false;
|
|
16590
|
+
}
|
|
16591
|
+
this.disposalFunction = disposalFunction;
|
|
16592
|
+
this.disposalCall = call;
|
|
16593
|
+
disposalFunction.deoptimizeArgumentsOnInteractionAtPath(call, EMPTY_PATH, SHARED_RECURSION_TRACKER);
|
|
16594
|
+
return true;
|
|
16595
|
+
}
|
|
16355
16596
|
}
|
|
16356
16597
|
VariableDeclarator.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
16357
16598
|
const SYMBOL_DISPOSE_PATH = [SymbolDispose];
|
|
@@ -17152,6 +17393,9 @@ function decodedSourcemap(map) {
|
|
|
17152
17393
|
if (typeof map === 'string') {
|
|
17153
17394
|
map = JSON.parse(map);
|
|
17154
17395
|
}
|
|
17396
|
+
if ('sections' in map) {
|
|
17397
|
+
map = flattenIndexSourceMap(map);
|
|
17398
|
+
}
|
|
17155
17399
|
if (!map.mappings) {
|
|
17156
17400
|
return {
|
|
17157
17401
|
mappings: [],
|
|
@@ -17187,6 +17431,74 @@ function decodedSourcemap(map) {
|
|
|
17187
17431
|
sourceMapCache.set(decodedMap, cache);
|
|
17188
17432
|
return decodedMap;
|
|
17189
17433
|
}
|
|
17434
|
+
function flattenIndexSourceMap({ file, sections }) {
|
|
17435
|
+
const mappings = [];
|
|
17436
|
+
const names = [];
|
|
17437
|
+
const sources = [];
|
|
17438
|
+
const sourcesContent = [];
|
|
17439
|
+
// As when collapsing sourcemaps, sources with the same name are shared unless their contents differ
|
|
17440
|
+
const sourceIndicesByName = new Map();
|
|
17441
|
+
for (const { map, offset } of sections) {
|
|
17442
|
+
const section = decodedSourcemap(map);
|
|
17443
|
+
const { sourceRoot } = section;
|
|
17444
|
+
const sourcePrefix = sourceRoot
|
|
17445
|
+
? sourceRoot.endsWith('/')
|
|
17446
|
+
? sourceRoot
|
|
17447
|
+
: `${sourceRoot}/`
|
|
17448
|
+
: '';
|
|
17449
|
+
const sourceIndices = section.sources.map((source, index) => {
|
|
17450
|
+
const name = source == null || isAbsolute$1(source) ? source : sourcePrefix + source;
|
|
17451
|
+
const content = section.sourcesContent?.[index] ?? null;
|
|
17452
|
+
let indices = sourceIndicesByName.get(name);
|
|
17453
|
+
if (!indices) {
|
|
17454
|
+
sourceIndicesByName.set(name, (indices = []));
|
|
17455
|
+
}
|
|
17456
|
+
let sourceIndex = indices.find(candidate => content == null ||
|
|
17457
|
+
sourcesContent[candidate] == null ||
|
|
17458
|
+
sourcesContent[candidate] === content);
|
|
17459
|
+
if (sourceIndex === undefined) {
|
|
17460
|
+
sourceIndex = sources.push(name) - 1;
|
|
17461
|
+
sourcesContent.push(content);
|
|
17462
|
+
indices.push(sourceIndex);
|
|
17463
|
+
}
|
|
17464
|
+
else {
|
|
17465
|
+
sourcesContent[sourceIndex] ??= content;
|
|
17466
|
+
}
|
|
17467
|
+
return sourceIndex;
|
|
17468
|
+
});
|
|
17469
|
+
const namesOffset = names.length;
|
|
17470
|
+
for (const name of section.names ?? []) {
|
|
17471
|
+
names.push(name);
|
|
17472
|
+
}
|
|
17473
|
+
for (const [lineIndex, line] of section.mappings.entries()) {
|
|
17474
|
+
const generatedLine = offset.line + lineIndex;
|
|
17475
|
+
while (mappings.length <= generatedLine) {
|
|
17476
|
+
mappings.push([]);
|
|
17477
|
+
}
|
|
17478
|
+
// Only the first line of a section starts at the column offset
|
|
17479
|
+
const columnOffset = lineIndex === 0 ? offset.column : 0;
|
|
17480
|
+
for (const segment of line) {
|
|
17481
|
+
const flatSegment = segment.slice();
|
|
17482
|
+
flatSegment[0] += columnOffset;
|
|
17483
|
+
if (flatSegment.length !== 1) {
|
|
17484
|
+
flatSegment[1] = sourceIndices[flatSegment[1]];
|
|
17485
|
+
if (flatSegment.length === 5) {
|
|
17486
|
+
flatSegment[4] += namesOffset;
|
|
17487
|
+
}
|
|
17488
|
+
}
|
|
17489
|
+
mappings[generatedLine].push(flatSegment);
|
|
17490
|
+
}
|
|
17491
|
+
}
|
|
17492
|
+
}
|
|
17493
|
+
return {
|
|
17494
|
+
file,
|
|
17495
|
+
mappings,
|
|
17496
|
+
names,
|
|
17497
|
+
sources,
|
|
17498
|
+
sourcesContent,
|
|
17499
|
+
version: 3
|
|
17500
|
+
};
|
|
17501
|
+
}
|
|
17190
17502
|
|
|
17191
17503
|
function getId(m) {
|
|
17192
17504
|
return m.id;
|
|
@@ -17203,7 +17515,7 @@ function getOriginalLocation(sourcemapChain, location) {
|
|
|
17203
17515
|
let previousSegment = filteredLine[0];
|
|
17204
17516
|
for (let segment of filteredLine) {
|
|
17205
17517
|
if (segment[0] >= location.column || segment === lastSegment) {
|
|
17206
|
-
const notMatched = segment[0]
|
|
17518
|
+
const notMatched = segment[0] > location.column;
|
|
17207
17519
|
segment = notMatched ? previousSegment : segment;
|
|
17208
17520
|
location = {
|
|
17209
17521
|
column: segment[3],
|
|
@@ -18492,7 +18804,8 @@ function deconflictImportsEsmOrSystem(usedNames, imports, dependenciesToBeDeconf
|
|
|
18492
18804
|
for (const variable of imports) {
|
|
18493
18805
|
const module = variable.module;
|
|
18494
18806
|
const name = variable.name;
|
|
18495
|
-
if (variable.isNamespace &&
|
|
18807
|
+
if (variable.isNamespace &&
|
|
18808
|
+
(module instanceof ExternalModule || (preserveModules && !module.info.syntheticNamedExports))) {
|
|
18496
18809
|
variable.setRenderNames(null, (module instanceof ExternalModule
|
|
18497
18810
|
? externalChunkByModule.get(module)
|
|
18498
18811
|
: chunkByModule.get(module)).variableName);
|
|
@@ -18556,7 +18869,7 @@ function deconflictImportsOther(usedNames, imports, { deconflictedDefault, decon
|
|
|
18556
18869
|
}
|
|
18557
18870
|
else {
|
|
18558
18871
|
const chunk = chunkByModule.get(module);
|
|
18559
|
-
if (preserveModules && variable.isNamespace) {
|
|
18872
|
+
if (preserveModules && variable.isNamespace && !module.info.syntheticNamedExports) {
|
|
18560
18873
|
variable.setRenderNames(null, chunk.exportMode === 'default' ? chunk.namespaceVariableName : chunk.variableName);
|
|
18561
18874
|
}
|
|
18562
18875
|
else if (chunk.exportMode === 'default') {
|
|
@@ -18930,7 +19243,8 @@ class Chunk {
|
|
|
18930
19243
|
const chunkModules = new Set(orderedModules);
|
|
18931
19244
|
for (const module of orderedModules) {
|
|
18932
19245
|
chunkByModule.set(module, this);
|
|
18933
|
-
if (module.namespace.included &&
|
|
19246
|
+
if (module.namespace.included &&
|
|
19247
|
+
(!outputOptions.preserveModules || module.info.syntheticNamedExports)) {
|
|
18934
19248
|
includedNamespaces.add(module);
|
|
18935
19249
|
}
|
|
18936
19250
|
if (this.isEmpty && module.isIncluded()) {
|
|
@@ -19234,11 +19548,16 @@ class Chunk {
|
|
|
19234
19548
|
});
|
|
19235
19549
|
}
|
|
19236
19550
|
getVariableExportName(variable) {
|
|
19237
|
-
if (this.
|
|
19551
|
+
if (this.isNativeNamespace(variable)) {
|
|
19238
19552
|
return '*';
|
|
19239
19553
|
}
|
|
19240
19554
|
return this.exportNamesByVariable.get(variable)[0];
|
|
19241
19555
|
}
|
|
19556
|
+
isNativeNamespace(variable) {
|
|
19557
|
+
return (this.outputOptions.preserveModules &&
|
|
19558
|
+
variable instanceof NamespaceVariable &&
|
|
19559
|
+
!variable.module.info.syntheticNamedExports);
|
|
19560
|
+
}
|
|
19242
19561
|
link() {
|
|
19243
19562
|
this.dependencies = getStaticDependencies(this, this.orderedModules, this.chunkByModule, this.externalChunkByModule);
|
|
19244
19563
|
for (const module of this.orderedModules) {
|
|
@@ -19381,8 +19700,9 @@ class Chunk {
|
|
|
19381
19700
|
const importedVariable = isSynthetic ? exportedVariable.getBaseVariable() : exportedVariable;
|
|
19382
19701
|
this.checkCircularDependencyImport(importedVariable, module);
|
|
19383
19702
|
// When preserving modules, we do not create namespace objects but directly
|
|
19384
|
-
// use the actual namespaces, which would be broken by this logic.
|
|
19385
|
-
|
|
19703
|
+
// use the actual namespaces, which would be broken by this logic. Modules with
|
|
19704
|
+
// synthetic named exports still need a namespace object.
|
|
19705
|
+
if (!this.isNativeNamespace(importedVariable)) {
|
|
19386
19706
|
const exportingModule = importedVariable.module;
|
|
19387
19707
|
if (exportingModule instanceof Module) {
|
|
19388
19708
|
const chunk = this.chunkByModule.get(exportingModule);
|
|
@@ -19954,9 +20274,8 @@ class Chunk {
|
|
|
19954
20274
|
}
|
|
19955
20275
|
setUpChunkImportsAndExportsForModule(module) {
|
|
19956
20276
|
const moduleImports = new Set(module.includedImports);
|
|
19957
|
-
//
|
|
19958
|
-
|
|
19959
|
-
if (!this.outputOptions.preserveModules && this.includedNamespaces.has(module)) {
|
|
20277
|
+
// we need to make all namespace variables available for rendering the namespace object
|
|
20278
|
+
if (this.includedNamespaces.has(module)) {
|
|
19960
20279
|
for (const variable of module.getExportedVariablesByName().values()) {
|
|
19961
20280
|
if (variable.included) {
|
|
19962
20281
|
moduleImports.add(variable);
|
|
@@ -19976,8 +20295,9 @@ class Chunk {
|
|
|
19976
20295
|
if (variable.module instanceof Module) {
|
|
19977
20296
|
this.checkCircularDependencyImport(variable, module);
|
|
19978
20297
|
// When preserving modules, we do not create namespace objects but directly
|
|
19979
|
-
// use the actual namespaces, which would be broken by this logic.
|
|
19980
|
-
|
|
20298
|
+
// use the actual namespaces, which would be broken by this logic. Modules with
|
|
20299
|
+
// synthetic named exports still need a namespace object.
|
|
20300
|
+
if (!this.isNativeNamespace(variable)) {
|
|
19981
20301
|
chunk.exports.add(variable);
|
|
19982
20302
|
}
|
|
19983
20303
|
}
|
|
@@ -21173,7 +21493,10 @@ function getCollapsedSourcemap(id, originalCode, originalSourcemap, sourcemapCha
|
|
|
21173
21493
|
const sourcesContent = originalSourcemap.sourcesContent || [];
|
|
21174
21494
|
const directory = dirname(id) || '.';
|
|
21175
21495
|
const sourceRoot = originalSourcemap.sourceRoot || '.';
|
|
21176
|
-
|
|
21496
|
+
// A source whose name is not known is null, and mappings to it are treated as unmapped
|
|
21497
|
+
const baseSources = sources.map((source, index) => source == null
|
|
21498
|
+
? null
|
|
21499
|
+
: new Source(resolve$1(directory, sourceRoot, source), sourcesContent[index]));
|
|
21177
21500
|
source = new Link(originalSourcemap, baseSources);
|
|
21178
21501
|
}
|
|
21179
21502
|
else {
|
|
@@ -21206,13 +21529,17 @@ function collapseSourcemaps(file, map, modules, bundleSourcemapChain, excludeCon
|
|
|
21206
21529
|
});
|
|
21207
21530
|
}
|
|
21208
21531
|
function collapseSourcemap(id, originalCode, originalSourcemap, sourcemapChain, log) {
|
|
21209
|
-
if (sourcemapChain.length === 0
|
|
21532
|
+
if (sourcemapChain.length === 0 &&
|
|
21533
|
+
(!originalSourcemap || hasOnlyNamedSources(originalSourcemap))) {
|
|
21210
21534
|
return originalSourcemap;
|
|
21211
21535
|
}
|
|
21212
21536
|
const source = getCollapsedSourcemap(id, originalCode, originalSourcemap, sourcemapChain, getLinkMap(log));
|
|
21213
21537
|
const map = source.traceMappings();
|
|
21214
21538
|
return decodedSourcemap({ version: 3, ...map });
|
|
21215
21539
|
}
|
|
21540
|
+
function hasOnlyNamedSources(map) {
|
|
21541
|
+
return map.sources.every(source => source != null);
|
|
21542
|
+
}
|
|
21216
21543
|
|
|
21217
21544
|
let textEncoder;
|
|
21218
21545
|
const getHash64 = input => xxhashBase64Url(ensureBuffer(input));
|
|
@@ -21542,7 +21869,12 @@ class Bundle {
|
|
|
21542
21869
|
await renderChunks(chunks, outputBundle, this.pluginDriver, this.outputOptions, this.inputOptions.onLog);
|
|
21543
21870
|
}
|
|
21544
21871
|
catch (error_) {
|
|
21545
|
-
|
|
21872
|
+
try {
|
|
21873
|
+
await this.pluginDriver.hookParallel('renderError', [error_]);
|
|
21874
|
+
}
|
|
21875
|
+
catch (hookError) {
|
|
21876
|
+
error(logErrorInHook(error_, hookError, 'renderError'));
|
|
21877
|
+
}
|
|
21546
21878
|
throw error_;
|
|
21547
21879
|
}
|
|
21548
21880
|
removeUnreferencedAssets(outputBundle);
|
|
@@ -22254,7 +22586,7 @@ async function transform(source, module, pluginDriver, options) {
|
|
|
22254
22586
|
}
|
|
22255
22587
|
const getLogHandler = (handler) => (log, pos) => {
|
|
22256
22588
|
log = normalizeLog(log);
|
|
22257
|
-
if (pos)
|
|
22589
|
+
if (pos != null)
|
|
22258
22590
|
augmentCodeLocation(log, pos, currentSource, id);
|
|
22259
22591
|
log.id = id;
|
|
22260
22592
|
log.hook = 'transform';
|
|
@@ -22288,7 +22620,7 @@ async function transform(source, module, pluginDriver, options) {
|
|
|
22288
22620
|
error(error_, pos) {
|
|
22289
22621
|
if (typeof error_ === 'string')
|
|
22290
22622
|
error_ = { message: error_ };
|
|
22291
|
-
if (pos)
|
|
22623
|
+
if (pos != null)
|
|
22292
22624
|
augmentCodeLocation(error_, pos, currentSource, id);
|
|
22293
22625
|
error_.id = id;
|
|
22294
22626
|
error_.hook = 'transform';
|
|
@@ -22440,37 +22772,7 @@ class ModuleLoader {
|
|
|
22440
22772
|
}));
|
|
22441
22773
|
}
|
|
22442
22774
|
async addModuleSource(id, importer, module) {
|
|
22443
|
-
|
|
22444
|
-
try {
|
|
22445
|
-
source = await this.graph.fileOperationQueue.run(async () => {
|
|
22446
|
-
const content = await this.pluginDriver.hookFirst('load', [
|
|
22447
|
-
id,
|
|
22448
|
-
{ attributes: module.info.attributes, rawId: module.info.rawId }
|
|
22449
|
-
]);
|
|
22450
|
-
if (content !== null) {
|
|
22451
|
-
if (typeof content === 'object' && content.attributes) {
|
|
22452
|
-
warnDeprecation('Returning attributes from the "load" hook is deprecated.', URL_LOAD, true, this.options);
|
|
22453
|
-
}
|
|
22454
|
-
return content;
|
|
22455
|
-
}
|
|
22456
|
-
this.graph.watchFiles[module.info.rawId] = true;
|
|
22457
|
-
return (await this.options.fs.readFile(module.info.rawId, { encoding: 'utf8' }));
|
|
22458
|
-
});
|
|
22459
|
-
}
|
|
22460
|
-
catch (error_) {
|
|
22461
|
-
let message = `Could not load ${id}`;
|
|
22462
|
-
if (importer)
|
|
22463
|
-
message += ` (imported by ${relativeId(importer)})`;
|
|
22464
|
-
message += `: ${error_.message}`;
|
|
22465
|
-
error_.message = message;
|
|
22466
|
-
throw error_;
|
|
22467
|
-
}
|
|
22468
|
-
const sourceDescription = typeof source === 'string'
|
|
22469
|
-
? { code: source }
|
|
22470
|
-
: source != null && typeof source === 'object' && typeof source.code === 'string'
|
|
22471
|
-
? source
|
|
22472
|
-
: error(logBadLoader(id));
|
|
22473
|
-
sourceDescription.code = stripBom(sourceDescription.code);
|
|
22775
|
+
const sourceDescription = await this.loadSourceDescription(id, importer, module);
|
|
22474
22776
|
const cachedModule = this.graph.cachedModules.get(id);
|
|
22475
22777
|
if (cachedModule &&
|
|
22476
22778
|
!cachedModule.customTransformCache &&
|
|
@@ -22783,6 +23085,37 @@ class ModuleLoader {
|
|
|
22783
23085
|
? resolveIdResult
|
|
22784
23086
|
: { id: resolveIdResult }, attributes)), undefined, isEntry, false);
|
|
22785
23087
|
}
|
|
23088
|
+
async loadSourceDescription(id, importer, module) {
|
|
23089
|
+
let source;
|
|
23090
|
+
try {
|
|
23091
|
+
source = await this.pluginDriver.hookFirst('load', [
|
|
23092
|
+
id,
|
|
23093
|
+
{ attributes: module.info.attributes, rawId: module.info.rawId }
|
|
23094
|
+
]);
|
|
23095
|
+
if (source === null) {
|
|
23096
|
+
this.graph.watchFiles[module.info.rawId] = true;
|
|
23097
|
+
source = await this.options.fs.readFile(module.info.rawId, { encoding: 'utf8' });
|
|
23098
|
+
}
|
|
23099
|
+
else if (typeof source === 'object' && source.attributes) {
|
|
23100
|
+
warnDeprecation('Returning attributes from the "load" hook is deprecated.', URL_LOAD, true, this.options);
|
|
23101
|
+
}
|
|
23102
|
+
}
|
|
23103
|
+
catch (error_) {
|
|
23104
|
+
let message = `Could not load ${id}`;
|
|
23105
|
+
if (importer)
|
|
23106
|
+
message += ` (imported by ${relativeId(importer)})`;
|
|
23107
|
+
message += `: ${error_.message}`;
|
|
23108
|
+
error_.message = message;
|
|
23109
|
+
throw error_;
|
|
23110
|
+
}
|
|
23111
|
+
const sourceDescription = typeof source === 'string'
|
|
23112
|
+
? { code: source }
|
|
23113
|
+
: source != null && typeof source === 'object' && typeof source.code === 'string'
|
|
23114
|
+
? source
|
|
23115
|
+
: error(logBadLoader(id));
|
|
23116
|
+
sourceDescription.code = stripBom(sourceDescription.code);
|
|
23117
|
+
return sourceDescription;
|
|
23118
|
+
}
|
|
22786
23119
|
toModuleResolvedId(resolveIdResult) {
|
|
22787
23120
|
const { id, attributes } = resolveIdResult;
|
|
22788
23121
|
return {
|
|
@@ -22848,22 +23181,20 @@ async function waitForDependencyResolution(loadPromise) {
|
|
|
22848
23181
|
function generateAssetFileName(name, names, source, originalFileName, originalFileNames, sourceHash, outputOptions, bundle, inputOptions) {
|
|
22849
23182
|
const emittedName = outputOptions.sanitizeFileName(name || 'asset');
|
|
22850
23183
|
return makeUnique(renderNamePattern(typeof outputOptions.assetFileNames === 'function'
|
|
22851
|
-
? outputOptions.assetFileNames({
|
|
22852
|
-
// Additionally, this should be non-enumerable in the next major
|
|
23184
|
+
? outputOptions.assetFileNames(makeDeprecatedAssetPropertiesNonEnumerable({
|
|
22853
23185
|
get name() {
|
|
22854
|
-
warnDeprecation('Accessing the "name" property of emitted assets when generating the file name is deprecated. Use the "names" property instead.', URL_GENERATEBUNDLE,
|
|
23186
|
+
warnDeprecation('Accessing the "name" property of emitted assets when generating the file name is deprecated. Use the "names" property instead.', URL_GENERATEBUNDLE, true, inputOptions);
|
|
22855
23187
|
return name;
|
|
22856
23188
|
},
|
|
22857
23189
|
names,
|
|
22858
|
-
// Additionally, this should be non-enumerable in the next major
|
|
22859
23190
|
get originalFileName() {
|
|
22860
|
-
warnDeprecation('Accessing the "originalFileName" property of emitted assets when generating the file name is deprecated. Use the "originalFileNames" property instead.', URL_GENERATEBUNDLE,
|
|
23191
|
+
warnDeprecation('Accessing the "originalFileName" property of emitted assets when generating the file name is deprecated. Use the "originalFileNames" property instead.', URL_GENERATEBUNDLE, true, inputOptions);
|
|
22861
23192
|
return originalFileName;
|
|
22862
23193
|
},
|
|
22863
23194
|
originalFileNames,
|
|
22864
23195
|
source,
|
|
22865
23196
|
type: 'asset'
|
|
22866
|
-
})
|
|
23197
|
+
}))
|
|
22867
23198
|
: outputOptions.assetFileNames, 'output.assetFileNames', {
|
|
22868
23199
|
ext: () => extname(emittedName).slice(1),
|
|
22869
23200
|
extname: () => extname(emittedName),
|
|
@@ -23153,50 +23484,44 @@ class FileEmitter {
|
|
|
23153
23484
|
const existingAsset = bundle[fileName];
|
|
23154
23485
|
if (existingAsset?.type === 'asset') {
|
|
23155
23486
|
existingAsset.needsCodeReference &&= needsCodeReference;
|
|
23156
|
-
if (name) {
|
|
23487
|
+
if (name && !existingAsset.names.includes(name)) {
|
|
23157
23488
|
existingAsset.names.push(name);
|
|
23158
23489
|
}
|
|
23159
|
-
if (originalFileName) {
|
|
23490
|
+
if (originalFileName && !existingAsset.originalFileNames.includes(originalFileName)) {
|
|
23160
23491
|
existingAsset.originalFileNames.push(originalFileName);
|
|
23161
23492
|
}
|
|
23162
23493
|
}
|
|
23163
23494
|
else {
|
|
23164
23495
|
const { options } = this;
|
|
23165
|
-
bundle[fileName] = {
|
|
23496
|
+
bundle[fileName] = makeDeprecatedAssetPropertiesNonEnumerable({
|
|
23166
23497
|
fileName,
|
|
23167
23498
|
get name() {
|
|
23168
|
-
|
|
23169
|
-
warnDeprecation('Accessing the "name" property of emitted assets in the bundle is deprecated. Use the "names" property instead.', URL_GENERATEBUNDLE, false, options);
|
|
23499
|
+
warnDeprecation('Accessing the "name" property of emitted assets in the bundle is deprecated. Use the "names" property instead.', URL_GENERATEBUNDLE, true, options);
|
|
23170
23500
|
return name;
|
|
23171
23501
|
},
|
|
23172
23502
|
names: name ? [name] : [],
|
|
23173
23503
|
needsCodeReference,
|
|
23174
23504
|
get originalFileName() {
|
|
23175
|
-
|
|
23176
|
-
warnDeprecation('Accessing the "originalFileName" property of emitted assets in the bundle is deprecated. Use the "originalFileNames" property instead.', URL_GENERATEBUNDLE, false, options);
|
|
23505
|
+
warnDeprecation('Accessing the "originalFileName" property of emitted assets in the bundle is deprecated. Use the "originalFileNames" property instead.', URL_GENERATEBUNDLE, true, options);
|
|
23177
23506
|
return originalFileName;
|
|
23178
23507
|
},
|
|
23179
23508
|
originalFileNames: originalFileName ? [originalFileName] : [],
|
|
23180
23509
|
source,
|
|
23181
23510
|
type: 'asset'
|
|
23182
|
-
};
|
|
23511
|
+
});
|
|
23183
23512
|
}
|
|
23184
23513
|
}
|
|
23185
23514
|
finalizeAssetsWithSameSource(consumedFiles, sourceHash, { bundle, fileNamesBySourceHash, outputOptions }) {
|
|
23186
23515
|
const { names, originalFileNames } = getNamesFromAssets(consumedFiles);
|
|
23187
|
-
let
|
|
23188
|
-
let usedConsumedFile;
|
|
23516
|
+
let representative = consumedFiles[0];
|
|
23189
23517
|
let needsCodeReference = true;
|
|
23190
23518
|
for (const consumedFile of consumedFiles) {
|
|
23191
23519
|
needsCodeReference &&= consumedFile.needsCodeReference;
|
|
23192
|
-
|
|
23193
|
-
|
|
23194
|
-
assetFileName.length < fileName.length ||
|
|
23195
|
-
(assetFileName.length === fileName.length && assetFileName < fileName)) {
|
|
23196
|
-
fileName = assetFileName;
|
|
23197
|
-
usedConsumedFile = consumedFile;
|
|
23520
|
+
if (compareConsumedAssets(consumedFile, representative) < 0) {
|
|
23521
|
+
representative = consumedFile;
|
|
23198
23522
|
}
|
|
23199
23523
|
}
|
|
23524
|
+
const fileName = generateAssetFileName(representative.name, names, representative.source, representative.originalFileName, originalFileNames, sourceHash, outputOptions, bundle, this.options);
|
|
23200
23525
|
fileNamesBySourceHash.set(sourceHash, fileName);
|
|
23201
23526
|
for (const consumedFile of consumedFiles) {
|
|
23202
23527
|
// We must not modify the original assets to avoid interaction between outputs
|
|
@@ -23204,42 +23529,53 @@ class FileEmitter {
|
|
|
23204
23529
|
this.filesByReferenceId.set(consumedFile.referenceId, assetWithFileName);
|
|
23205
23530
|
}
|
|
23206
23531
|
const { options } = this;
|
|
23207
|
-
bundle[fileName] = {
|
|
23532
|
+
bundle[fileName] = makeDeprecatedAssetPropertiesNonEnumerable({
|
|
23208
23533
|
fileName,
|
|
23209
23534
|
get name() {
|
|
23210
|
-
|
|
23211
|
-
|
|
23212
|
-
return usedConsumedFile.name;
|
|
23535
|
+
warnDeprecation('Accessing the "name" property of emitted assets in the bundle is deprecated. Use the "names" property instead.', URL_GENERATEBUNDLE, true, options);
|
|
23536
|
+
return representative.name;
|
|
23213
23537
|
},
|
|
23214
23538
|
names,
|
|
23215
23539
|
needsCodeReference,
|
|
23216
23540
|
get originalFileName() {
|
|
23217
|
-
|
|
23218
|
-
|
|
23219
|
-
return usedConsumedFile.originalFileName;
|
|
23541
|
+
warnDeprecation('Accessing the "originalFileName" property of emitted assets in the bundle is deprecated. Use the "originalFileNames" property instead.', URL_GENERATEBUNDLE, true, options);
|
|
23542
|
+
return representative.originalFileName;
|
|
23220
23543
|
},
|
|
23221
23544
|
originalFileNames,
|
|
23222
|
-
source:
|
|
23545
|
+
source: representative.source,
|
|
23223
23546
|
type: 'asset'
|
|
23224
|
-
};
|
|
23547
|
+
});
|
|
23548
|
+
}
|
|
23549
|
+
}
|
|
23550
|
+
function makeDeprecatedAssetPropertiesNonEnumerable(asset) {
|
|
23551
|
+
for (const property of ['name', 'originalFileName']) {
|
|
23552
|
+
const descriptor = Object.getOwnPropertyDescriptor(asset, property);
|
|
23553
|
+
Object.defineProperty(asset, property, { ...descriptor, enumerable: false });
|
|
23225
23554
|
}
|
|
23555
|
+
return asset;
|
|
23226
23556
|
}
|
|
23557
|
+
const compareNames = (a, b) => a.length - b.length || (a < b ? -1 : a > b ? 1 : 0);
|
|
23558
|
+
const compareOptionalNames = (a, b) => a === b ? 0 : a == null ? 1 : b == null ? -1 : a < b ? -1 : 1;
|
|
23559
|
+
const compareSourceTypes = (a, b) => typeof a === 'string' ? (typeof b === 'string' ? 0 : -1) : typeof b === 'string' ? 1 : 0;
|
|
23560
|
+
const compareConsumedAssets = (a, b) => compareNames(a.name || 'asset', b.name || 'asset') ||
|
|
23561
|
+
compareOptionalNames(a.originalFileName, b.originalFileName) ||
|
|
23562
|
+
compareOptionalNames(a.name, b.name) ||
|
|
23563
|
+
compareSourceTypes(a.source, b.source);
|
|
23227
23564
|
function getNamesFromAssets(consumedFiles) {
|
|
23228
|
-
const names =
|
|
23229
|
-
const originalFileNames =
|
|
23565
|
+
const names = new Set();
|
|
23566
|
+
const originalFileNames = new Set();
|
|
23230
23567
|
for (const { name, originalFileName } of consumedFiles) {
|
|
23231
23568
|
if (typeof name === 'string') {
|
|
23232
|
-
names.
|
|
23569
|
+
names.add(name);
|
|
23233
23570
|
}
|
|
23234
23571
|
if (originalFileName) {
|
|
23235
|
-
originalFileNames.
|
|
23572
|
+
originalFileNames.add(originalFileName);
|
|
23236
23573
|
}
|
|
23237
23574
|
}
|
|
23238
|
-
|
|
23239
|
-
|
|
23240
|
-
|
|
23241
|
-
|
|
23242
|
-
return { names, originalFileNames };
|
|
23575
|
+
return {
|
|
23576
|
+
names: [...names].sort(compareNames),
|
|
23577
|
+
originalFileNames: [...originalFileNames].sort()
|
|
23578
|
+
};
|
|
23243
23579
|
}
|
|
23244
23580
|
|
|
23245
23581
|
function ensureArray(items) {
|
|
@@ -23629,37 +23965,6 @@ function validateAddonPluginHandler(handler, hookName, plugin) {
|
|
|
23629
23965
|
}
|
|
23630
23966
|
function noReturn() { }
|
|
23631
23967
|
|
|
23632
|
-
class Queue {
|
|
23633
|
-
constructor(maxParallel) {
|
|
23634
|
-
this.maxParallel = maxParallel;
|
|
23635
|
-
this.queue = [];
|
|
23636
|
-
this.workerCount = 0;
|
|
23637
|
-
}
|
|
23638
|
-
run(task) {
|
|
23639
|
-
return new Promise((resolve, reject) => {
|
|
23640
|
-
this.queue.push({ reject, resolve, task });
|
|
23641
|
-
this.work();
|
|
23642
|
-
});
|
|
23643
|
-
}
|
|
23644
|
-
async work() {
|
|
23645
|
-
if (this.workerCount >= this.maxParallel)
|
|
23646
|
-
return;
|
|
23647
|
-
this.workerCount++;
|
|
23648
|
-
let entry;
|
|
23649
|
-
while ((entry = this.queue.shift())) {
|
|
23650
|
-
const { reject, resolve, task } = entry;
|
|
23651
|
-
try {
|
|
23652
|
-
const result = await task();
|
|
23653
|
-
resolve(result);
|
|
23654
|
-
}
|
|
23655
|
-
catch (error) {
|
|
23656
|
-
reject(error);
|
|
23657
|
-
}
|
|
23658
|
-
}
|
|
23659
|
-
this.workerCount--;
|
|
23660
|
-
}
|
|
23661
|
-
}
|
|
23662
|
-
|
|
23663
23968
|
function normalizeEntryModules(entryModules) {
|
|
23664
23969
|
if (Array.isArray(entryModules)) {
|
|
23665
23970
|
return entryModules.map(id => ({
|
|
@@ -23723,7 +24028,6 @@ class Graph {
|
|
|
23723
24028
|
}
|
|
23724
24029
|
this.pluginDriver = new PluginDriver(this, options, options.plugins, this.pluginCache);
|
|
23725
24030
|
this.moduleLoader = new ModuleLoader(this, this.modulesById, this.options, this.pluginDriver);
|
|
23726
|
-
this.fileOperationQueue = new Queue(options.maxParallelFileOps);
|
|
23727
24031
|
this.pureFunctions = getPureFunctions(options);
|
|
23728
24032
|
}
|
|
23729
24033
|
async build() {
|
|
@@ -23942,6 +24246,55 @@ function getLogger(plugins, onLog, watchMode, logLevel) {
|
|
|
23942
24246
|
return logger;
|
|
23943
24247
|
}
|
|
23944
24248
|
|
|
24249
|
+
class FileOperationQueue {
|
|
24250
|
+
constructor(maxParallel) {
|
|
24251
|
+
this.maxParallel = maxParallel;
|
|
24252
|
+
this.queue = [];
|
|
24253
|
+
this.workerCount = 0;
|
|
24254
|
+
}
|
|
24255
|
+
run(task) {
|
|
24256
|
+
return new Promise((resolve, reject) => {
|
|
24257
|
+
this.queue.push({ reject, resolve, task });
|
|
24258
|
+
this.work();
|
|
24259
|
+
});
|
|
24260
|
+
}
|
|
24261
|
+
async work() {
|
|
24262
|
+
if (this.workerCount >= this.maxParallel)
|
|
24263
|
+
return;
|
|
24264
|
+
this.workerCount++;
|
|
24265
|
+
let entry;
|
|
24266
|
+
while ((entry = this.queue.shift())) {
|
|
24267
|
+
const { reject, resolve, task } = entry;
|
|
24268
|
+
try {
|
|
24269
|
+
resolve(await task());
|
|
24270
|
+
}
|
|
24271
|
+
catch (error) {
|
|
24272
|
+
reject(error);
|
|
24273
|
+
}
|
|
24274
|
+
}
|
|
24275
|
+
this.workerCount--;
|
|
24276
|
+
}
|
|
24277
|
+
}
|
|
24278
|
+
function createLimitedFs(fs, maxParallelFileOps) {
|
|
24279
|
+
const queue = new FileOperationQueue(maxParallelFileOps);
|
|
24280
|
+
const limit = (method) => ((...parameters) => queue.run(() => Reflect.apply(fs[method], fs, parameters)));
|
|
24281
|
+
return {
|
|
24282
|
+
appendFile: limit('appendFile'),
|
|
24283
|
+
copyFile: limit('copyFile'),
|
|
24284
|
+
lstat: limit('lstat'),
|
|
24285
|
+
mkdir: limit('mkdir'),
|
|
24286
|
+
mkdtemp: limit('mkdtemp'),
|
|
24287
|
+
readdir: limit('readdir'),
|
|
24288
|
+
readFile: limit('readFile'),
|
|
24289
|
+
realpath: limit('realpath'),
|
|
24290
|
+
rename: limit('rename'),
|
|
24291
|
+
rmdir: limit('rmdir'),
|
|
24292
|
+
stat: limit('stat'),
|
|
24293
|
+
unlink: limit('unlink'),
|
|
24294
|
+
writeFile: limit('writeFile')
|
|
24295
|
+
};
|
|
24296
|
+
}
|
|
24297
|
+
|
|
23945
24298
|
const fs = /*#__PURE__*/_mergeNamespaces({
|
|
23946
24299
|
__proto__: null
|
|
23947
24300
|
}, [promises]);
|
|
@@ -23962,7 +24315,7 @@ async function normalizeInputOptions(config, watchMode) {
|
|
|
23962
24315
|
experimentalCacheExpiry: config.experimentalCacheExpiry ?? 10,
|
|
23963
24316
|
experimentalLogSideEffects: config.experimentalLogSideEffects || false,
|
|
23964
24317
|
external: getIdMatcher(config.external),
|
|
23965
|
-
fs: config.fs ?? fs,
|
|
24318
|
+
fs: createLimitedFs(config.fs ?? fs, maxParallelFileOps),
|
|
23966
24319
|
input: getInput(config),
|
|
23967
24320
|
jsx: getJsx(config),
|
|
23968
24321
|
logLevel,
|
|
@@ -24002,7 +24355,8 @@ const getIdMatcher = (option) => {
|
|
|
24002
24355
|
ids.add(value);
|
|
24003
24356
|
}
|
|
24004
24357
|
}
|
|
24005
|
-
return (id, ..._arguments) => ids.has(id) ||
|
|
24358
|
+
return (id, ..._arguments) => ids.has(id) ||
|
|
24359
|
+
matchers.some(matcher => matcher.global || matcher.sticky ? id.search(matcher) !== -1 : matcher.test(id));
|
|
24006
24360
|
}
|
|
24007
24361
|
return () => false;
|
|
24008
24362
|
};
|
|
@@ -24133,7 +24487,6 @@ async function normalizeOutputOptions(config, inputOptions, unsetInputOptions) {
|
|
|
24133
24487
|
const preserveModules = getPreserveModules(config, inlineDynamicImports, inputOptions);
|
|
24134
24488
|
const file = getFile(config, preserveModules, inputOptions);
|
|
24135
24489
|
const generatedCode = getGeneratedCode(config);
|
|
24136
|
-
const externalImportAttributes = getExternalImportAttributes(config, inputOptions);
|
|
24137
24490
|
const outputOptions = {
|
|
24138
24491
|
amd: getAmd(config),
|
|
24139
24492
|
assetFileNames: config.assetFileNames ?? 'assets/[name]-[hash][extname]',
|
|
@@ -24147,8 +24500,7 @@ async function normalizeOutputOptions(config, inputOptions, unsetInputOptions) {
|
|
|
24147
24500
|
experimentalMinChunkSize: config.experimentalMinChunkSize ?? 1,
|
|
24148
24501
|
exports: getExports(config, unsetOptions),
|
|
24149
24502
|
extend: config.extend || false,
|
|
24150
|
-
|
|
24151
|
-
externalImportAttributes,
|
|
24503
|
+
externalImportAttributes: config.externalImportAttributes ?? true,
|
|
24152
24504
|
externalLiveBindings: config.externalLiveBindings ?? true,
|
|
24153
24505
|
file,
|
|
24154
24506
|
footer: getAddon(config, 'footer'),
|
|
@@ -24323,12 +24675,6 @@ function getExports(config, unsetOptions) {
|
|
|
24323
24675
|
}
|
|
24324
24676
|
return configExports || 'auto';
|
|
24325
24677
|
}
|
|
24326
|
-
const getExternalImportAttributes = (config, inputOptions) => {
|
|
24327
|
-
if (config.externalImportAssertions != undefined) {
|
|
24328
|
-
warnDeprecation(`The "output.externalImportAssertions" option is deprecated. Use the "output.externalImportAttributes" option instead.`, URL_OUTPUT_EXTERNALIMPORTATTRIBUTES, true, inputOptions);
|
|
24329
|
-
}
|
|
24330
|
-
return config.externalImportAttributes ?? config.externalImportAssertions ?? true;
|
|
24331
|
-
};
|
|
24332
24678
|
const getGeneratedCode = (config) => {
|
|
24333
24679
|
const configWithPreset = getOptionWithPreset(config.generatedCode, generatedCodePresets, 'output.generatedCode', URL_OUTPUT_GENERATEDCODE, '');
|
|
24334
24680
|
return {
|
|
@@ -24442,11 +24788,7 @@ async function rollupInternal(rawInputOptions, registerWatchHooks) {
|
|
|
24442
24788
|
await graph.pluginDriver.hookParallel('buildEnd', [error_]);
|
|
24443
24789
|
}
|
|
24444
24790
|
catch (buildEndError) {
|
|
24445
|
-
|
|
24446
|
-
const compoundError = getRollupError({
|
|
24447
|
-
...error_,
|
|
24448
|
-
message: `There was an error during the build:\n ${error_.message}\nAdditionally, handling the error in the 'buildEnd' hook caused the following error:\n ${buildEndError.message}`
|
|
24449
|
-
});
|
|
24791
|
+
const compoundError = getRollupError(logErrorInHook(error_, buildEndError, 'buildEnd'));
|
|
24450
24792
|
await graph.pluginDriver.hookParallel('closeBundle', [compoundError]).catch(() => { });
|
|
24451
24793
|
throw compoundError;
|
|
24452
24794
|
}
|
|
@@ -24540,7 +24882,7 @@ async function handleGenerateWrite(isWrite, inputOptions, unsetInputOptions, raw
|
|
|
24540
24882
|
if (!outputOptions.dir && !outputOptions.file) {
|
|
24541
24883
|
return error(logMissingFileOrDirOption());
|
|
24542
24884
|
}
|
|
24543
|
-
await Promise.all(Object.values(generated).map(chunk =>
|
|
24885
|
+
await Promise.all(Object.values(generated).map(chunk => writeOutputFile(chunk, outputOptions, inputOptions)));
|
|
24544
24886
|
await outputPluginDriver.hookParallel('writeBundle', [outputOptions, generated]);
|
|
24545
24887
|
timeEnd('WRITE', 1);
|
|
24546
24888
|
}
|
|
@@ -24876,7 +25218,6 @@ async function mergeOutputOptions(config, overrides, log) {
|
|
|
24876
25218
|
experimentalMinChunkSize: getOption('experimentalMinChunkSize'),
|
|
24877
25219
|
exports: getOption('exports'),
|
|
24878
25220
|
extend: getOption('extend'),
|
|
24879
|
-
externalImportAssertions: getOption('externalImportAssertions'),
|
|
24880
25221
|
externalImportAttributes: getOption('externalImportAttributes'),
|
|
24881
25222
|
externalLiveBindings: getOption('externalLiveBindings'),
|
|
24882
25223
|
file: getOption('file'),
|