🔧 npm update
This commit is contained in:
171
node_modules/magic-string/dist/magic-string.cjs.js
generated
vendored
171
node_modules/magic-string/dist/magic-string.cjs.js
generated
vendored
@@ -96,6 +96,16 @@ class Chunk {
|
||||
this.intro = content + this.intro;
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.intro = '';
|
||||
this.outro = '';
|
||||
if (this.edited) {
|
||||
this.content = this.original;
|
||||
this.storeName = false;
|
||||
this.edited = false;
|
||||
}
|
||||
}
|
||||
|
||||
split(index) {
|
||||
const sliceIndex = index - this.start;
|
||||
|
||||
@@ -117,7 +127,7 @@ class Chunk {
|
||||
// ' test'.trim()
|
||||
// split -> ' ' + 'test'
|
||||
// ✔️ edit -> '' + 'test'
|
||||
// ✖️ edit -> 'test' + ''
|
||||
// ✖️ edit -> 'test' + ''
|
||||
// TODO is this block necessary?...
|
||||
newChunk.edit('', false);
|
||||
this.content = '';
|
||||
@@ -186,8 +196,8 @@ class Chunk {
|
||||
}
|
||||
|
||||
function getBtoa() {
|
||||
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
|
||||
return (str) => window.btoa(unescape(encodeURIComponent(str)));
|
||||
if (typeof globalThis !== 'undefined' && typeof globalThis.btoa === 'function') {
|
||||
return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
|
||||
} else if (typeof Buffer === 'function') {
|
||||
return (str) => Buffer.from(str, 'utf-8').toString('base64');
|
||||
} else {
|
||||
@@ -210,6 +220,9 @@ class SourceMap {
|
||||
if (typeof properties.x_google_ignoreList !== 'undefined') {
|
||||
this.x_google_ignoreList = properties.x_google_ignoreList;
|
||||
}
|
||||
if (typeof properties.debugId !== 'undefined') {
|
||||
this.debugId = properties.debugId;
|
||||
}
|
||||
}
|
||||
|
||||
toString() {
|
||||
@@ -312,9 +325,12 @@ class Mappings {
|
||||
|
||||
addEdit(sourceIndex, content, loc, nameIndex) {
|
||||
if (content.length) {
|
||||
const contentLengthMinusOne = content.length - 1;
|
||||
let contentLineEnd = content.indexOf('\n', 0);
|
||||
let previousContentLineEnd = -1;
|
||||
while (contentLineEnd >= 0) {
|
||||
// Loop through each line in the content and add a segment, but stop if the last line is empty,
|
||||
// else code afterwards would fill one line too many
|
||||
while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
|
||||
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
||||
if (nameIndex >= 0) {
|
||||
segment.push(nameIndex);
|
||||
@@ -351,27 +367,6 @@ class Mappings {
|
||||
let charInHiresBoundary = false;
|
||||
|
||||
while (originalCharIndex < chunk.end) {
|
||||
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
||||
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
||||
|
||||
if (this.hires === 'boundary') {
|
||||
// in hires "boundary", group segments per word boundary than per char
|
||||
if (wordRegex.test(original[originalCharIndex])) {
|
||||
// for first char in the boundary found, start the boundary by pushing a segment
|
||||
if (!charInHiresBoundary) {
|
||||
this.rawSegments.push(segment);
|
||||
charInHiresBoundary = true;
|
||||
}
|
||||
} else {
|
||||
// for non-word char, end the boundary by pushing a segment
|
||||
this.rawSegments.push(segment);
|
||||
charInHiresBoundary = false;
|
||||
}
|
||||
} else {
|
||||
this.rawSegments.push(segment);
|
||||
}
|
||||
}
|
||||
|
||||
if (original[originalCharIndex] === '\n') {
|
||||
loc.line += 1;
|
||||
loc.column = 0;
|
||||
@@ -379,7 +374,29 @@ class Mappings {
|
||||
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
||||
this.generatedCodeColumn = 0;
|
||||
first = true;
|
||||
charInHiresBoundary = false;
|
||||
} else {
|
||||
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
||||
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
||||
|
||||
if (this.hires === 'boundary') {
|
||||
// in hires "boundary", group segments per word boundary than per char
|
||||
if (wordRegex.test(original[originalCharIndex])) {
|
||||
// for first char in the boundary found, start the boundary by pushing a segment
|
||||
if (!charInHiresBoundary) {
|
||||
this.rawSegments.push(segment);
|
||||
charInHiresBoundary = true;
|
||||
}
|
||||
} else {
|
||||
// for non-word char, end the boundary by pushing a segment
|
||||
this.rawSegments.push(segment);
|
||||
charInHiresBoundary = false;
|
||||
}
|
||||
} else {
|
||||
this.rawSegments.push(segment);
|
||||
}
|
||||
}
|
||||
|
||||
loc.column += 1;
|
||||
this.generatedCodeColumn += 1;
|
||||
first = false;
|
||||
@@ -435,6 +452,7 @@ class MagicString {
|
||||
storedNames: { writable: true, value: {} },
|
||||
indentStr: { writable: true, value: undefined },
|
||||
ignoreList: { writable: true, value: options.ignoreList },
|
||||
offset: { writable: true, value: options.offset || 0 },
|
||||
});
|
||||
|
||||
this.byStart[0] = chunk;
|
||||
@@ -453,6 +471,8 @@ class MagicString {
|
||||
}
|
||||
|
||||
appendLeft(index, content) {
|
||||
index = index + this.offset;
|
||||
|
||||
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
||||
|
||||
this._split(index);
|
||||
@@ -468,6 +488,8 @@ class MagicString {
|
||||
}
|
||||
|
||||
appendRight(index, content) {
|
||||
index = index + this.offset;
|
||||
|
||||
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
||||
|
||||
this._split(index);
|
||||
@@ -483,7 +505,7 @@ class MagicString {
|
||||
}
|
||||
|
||||
clone() {
|
||||
const cloned = new MagicString(this.original, { filename: this.filename });
|
||||
const cloned = new MagicString(this.original, { filename: this.filename, offset: this.offset });
|
||||
|
||||
let originalChunk = this.firstChunk;
|
||||
let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
|
||||
@@ -681,7 +703,7 @@ class MagicString {
|
||||
if (!warned.insertLeft) {
|
||||
console.warn(
|
||||
'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
|
||||
); // eslint-disable-line no-console
|
||||
);
|
||||
warned.insertLeft = true;
|
||||
}
|
||||
|
||||
@@ -692,7 +714,7 @@ class MagicString {
|
||||
if (!warned.insertRight) {
|
||||
console.warn(
|
||||
'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
|
||||
); // eslint-disable-line no-console
|
||||
);
|
||||
warned.insertRight = true;
|
||||
}
|
||||
|
||||
@@ -700,6 +722,10 @@ class MagicString {
|
||||
}
|
||||
|
||||
move(start, end, index) {
|
||||
start = start + this.offset;
|
||||
end = end + this.offset;
|
||||
index = index + this.offset;
|
||||
|
||||
if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
|
||||
|
||||
this._split(start);
|
||||
@@ -742,10 +768,15 @@ class MagicString {
|
||||
}
|
||||
|
||||
update(start, end, content, options) {
|
||||
start = start + this.offset;
|
||||
end = end + this.offset;
|
||||
|
||||
if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
|
||||
|
||||
while (start < 0) start += this.original.length;
|
||||
while (end < 0) end += this.original.length;
|
||||
if (this.original.length !== 0) {
|
||||
while (start < 0) start += this.original.length;
|
||||
while (end < 0) end += this.original.length;
|
||||
}
|
||||
|
||||
if (end > this.original.length) throw new Error('end is out of bounds');
|
||||
if (start === end)
|
||||
@@ -760,7 +791,7 @@ class MagicString {
|
||||
if (!warned.storeName) {
|
||||
console.warn(
|
||||
'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
|
||||
); // eslint-disable-line no-console
|
||||
);
|
||||
warned.storeName = true;
|
||||
}
|
||||
|
||||
@@ -811,6 +842,8 @@ class MagicString {
|
||||
}
|
||||
|
||||
prependLeft(index, content) {
|
||||
index = index + this.offset;
|
||||
|
||||
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
||||
|
||||
this._split(index);
|
||||
@@ -826,6 +859,8 @@ class MagicString {
|
||||
}
|
||||
|
||||
prependRight(index, content) {
|
||||
index = index + this.offset;
|
||||
|
||||
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
||||
|
||||
this._split(index);
|
||||
@@ -841,8 +876,13 @@ class MagicString {
|
||||
}
|
||||
|
||||
remove(start, end) {
|
||||
while (start < 0) start += this.original.length;
|
||||
while (end < 0) end += this.original.length;
|
||||
start = start + this.offset;
|
||||
end = end + this.offset;
|
||||
|
||||
if (this.original.length !== 0) {
|
||||
while (start < 0) start += this.original.length;
|
||||
while (end < 0) end += this.original.length;
|
||||
}
|
||||
|
||||
if (start === end) return this;
|
||||
|
||||
@@ -864,6 +904,33 @@ class MagicString {
|
||||
return this;
|
||||
}
|
||||
|
||||
reset(start, end) {
|
||||
start = start + this.offset;
|
||||
end = end + this.offset;
|
||||
|
||||
if (this.original.length !== 0) {
|
||||
while (start < 0) start += this.original.length;
|
||||
while (end < 0) end += this.original.length;
|
||||
}
|
||||
|
||||
if (start === end) return this;
|
||||
|
||||
if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
|
||||
if (start > end) throw new Error('end must be greater than start');
|
||||
|
||||
this._split(start);
|
||||
this._split(end);
|
||||
|
||||
let chunk = this.byStart[start];
|
||||
|
||||
while (chunk) {
|
||||
chunk.reset();
|
||||
|
||||
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
lastChar() {
|
||||
if (this.outro.length) return this.outro[this.outro.length - 1];
|
||||
let chunk = this.lastChunk;
|
||||
@@ -905,9 +972,14 @@ class MagicString {
|
||||
return this.intro + lineStr;
|
||||
}
|
||||
|
||||
slice(start = 0, end = this.original.length) {
|
||||
while (start < 0) start += this.original.length;
|
||||
while (end < 0) end += this.original.length;
|
||||
slice(start = 0, end = this.original.length - this.offset) {
|
||||
start = start + this.offset;
|
||||
end = end + this.offset;
|
||||
|
||||
if (this.original.length !== 0) {
|
||||
while (start < 0) start += this.original.length;
|
||||
while (end < 0) end += this.original.length;
|
||||
}
|
||||
|
||||
let result = '';
|
||||
|
||||
@@ -1136,21 +1208,21 @@ class MagicString {
|
||||
if (searchValue.global) {
|
||||
const matches = matchAll(searchValue, this.original);
|
||||
matches.forEach((match) => {
|
||||
if (match.index != null)
|
||||
this.overwrite(
|
||||
match.index,
|
||||
match.index + match[0].length,
|
||||
getReplacement(match, this.original),
|
||||
);
|
||||
if (match.index != null) {
|
||||
const replacement = getReplacement(match, this.original);
|
||||
if (replacement !== match[0]) {
|
||||
this.overwrite(match.index, match.index + match[0].length, replacement);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const match = this.original.match(searchValue);
|
||||
if (match && match.index != null)
|
||||
this.overwrite(
|
||||
match.index,
|
||||
match.index + match[0].length,
|
||||
getReplacement(match, this.original),
|
||||
);
|
||||
if (match && match.index != null) {
|
||||
const replacement = getReplacement(match, this.original);
|
||||
if (replacement !== match[0]) {
|
||||
this.overwrite(match.index, match.index + match[0].length, replacement);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -1182,7 +1254,8 @@ class MagicString {
|
||||
index !== -1;
|
||||
index = original.indexOf(string, index + stringLength)
|
||||
) {
|
||||
this.overwrite(index, index + stringLength, replacement);
|
||||
const previous = original.slice(index, index + stringLength);
|
||||
if (previous !== replacement) this.overwrite(index, index + stringLength, replacement);
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
Reference in New Issue
Block a user