Socket
Socket
Sign inDemoInstall

magic-string

Package Overview
Dependencies
Maintainers
4
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

magic-string - npm Package Compare versions

Comparing version 0.25.7 to 0.25.8

143

dist/magic-string.cjs.js

@@ -32,3 +32,3 @@ 'use strict';

previous: { writable: true, value: null },
next: { writable: true, value: null }
next: { writable: true, value: null },
});

@@ -143,3 +143,2 @@ };

return true;
} else {

@@ -165,3 +164,2 @@ this.edit('', undefined, true);

return true;
} else {

@@ -351,3 +349,3 @@ this.edit('', undefined, true);

insertRight: false,
storeName: false
storeName: false,
};

@@ -361,15 +359,15 @@

Object.defineProperties(this, {
original: { writable: true, value: string },
outro: { writable: true, value: '' },
intro: { writable: true, value: '' },
firstChunk: { writable: true, value: chunk },
lastChunk: { writable: true, value: chunk },
lastSearchedChunk: { writable: true, value: chunk },
byStart: { writable: true, value: {} },
byEnd: { writable: true, value: {} },
filename: { writable: true, value: options.filename },
original: { writable: true, value: string },
outro: { writable: true, value: '' },
intro: { writable: true, value: '' },
firstChunk: { writable: true, value: chunk },
lastChunk: { writable: true, value: chunk },
lastSearchedChunk: { writable: true, value: chunk },
byStart: { writable: true, value: {} },
byEnd: { writable: true, value: {} },
filename: { writable: true, value: options.filename },
indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
sourcemapLocations: { writable: true, value: new BitSet() },
storedNames: { writable: true, value: {} },
indentStr: { writable: true, value: guessIndent(string) }
sourcemapLocations: { writable: true, value: new BitSet() },
storedNames: { writable: true, value: {} },
indentStr: { writable: true, value: guessIndent(string) },
});

@@ -460,3 +458,3 @@

MagicString.prototype.generateDecodedMap = function generateDecodedMap (options) {
var this$1 = this;
var this$1$1 = this;

@@ -488,3 +486,3 @@ options = options || {};

} else {
mappings.addUneditedChunk(sourceIndex, chunk, this$1.original, loc, this$1.sourcemapLocations);
mappings.addUneditedChunk(sourceIndex, chunk, this$1$1.original, loc, this$1$1.sourcemapLocations);
}

@@ -500,3 +498,3 @@

names: names,
mappings: mappings.raw
mappings: mappings.raw,
};

@@ -599,3 +597,5 @@ };

MagicString.prototype.insert = function insert () {
throw new Error('magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)');
throw new Error(
'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
);
};

@@ -605,3 +605,5 @@

if (!warned.insertLeft) {
console.warn('magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'); // eslint-disable-line no-console
console.warn(
'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'
); // eslint-disable-line no-console
warned.insertLeft = true;

@@ -615,3 +617,5 @@ }

if (!warned.insertRight) {
console.warn('magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'); // eslint-disable-line no-console
console.warn(
'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'
); // eslint-disable-line no-console
warned.insertRight = true;

@@ -668,3 +672,5 @@ }

if (start === end)
{ throw new Error('Cannot overwrite a zero-length range – use appendLeft or prependRight instead'); }
{ throw new Error(
'Cannot overwrite a zero-length range – use appendLeft or prependRight instead'
); }

@@ -676,3 +682,5 @@ this._split(start);

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
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;

@@ -783,15 +791,10 @@ }

MagicString.prototype.lastChar = function lastChar () {
if (this.outro.length)
{ return this.outro[this.outro.length - 1]; }
if (this.outro.length) { return this.outro[this.outro.length - 1]; }
var chunk = this.lastChunk;
do {
if (chunk.outro.length)
{ return chunk.outro[chunk.outro.length - 1]; }
if (chunk.content.length)
{ return chunk.content[chunk.content.length - 1]; }
if (chunk.intro.length)
{ return chunk.intro[chunk.intro.length - 1]; }
} while (chunk = chunk.previous);
if (this.intro.length)
{ return this.intro[this.intro.length - 1]; }
if (chunk.outro.length) { return chunk.outro[chunk.outro.length - 1]; }
if (chunk.content.length) { return chunk.content[chunk.content.length - 1]; }
if (chunk.intro.length) { return chunk.intro[chunk.intro.length - 1]; }
} while ((chunk = chunk.previous));
if (this.intro.length) { return this.intro[this.intro.length - 1]; }
return '';

@@ -802,4 +805,3 @@ };

var lineIndex = this.outro.lastIndexOf(n);
if (lineIndex !== -1)
{ return this.outro.substr(lineIndex + 1); }
if (lineIndex !== -1) { return this.outro.substr(lineIndex + 1); }
var lineStr = this.outro;

@@ -810,4 +812,3 @@ var chunk = this.lastChunk;

lineIndex = chunk.outro.lastIndexOf(n);
if (lineIndex !== -1)
{ return chunk.outro.substr(lineIndex + 1) + lineStr; }
if (lineIndex !== -1) { return chunk.outro.substr(lineIndex + 1) + lineStr; }
lineStr = chunk.outro + lineStr;

@@ -818,4 +819,3 @@ }

lineIndex = chunk.content.lastIndexOf(n);
if (lineIndex !== -1)
{ return chunk.content.substr(lineIndex + 1) + lineStr; }
if (lineIndex !== -1) { return chunk.content.substr(lineIndex + 1) + lineStr; }
lineStr = chunk.content + lineStr;

@@ -826,10 +826,8 @@ }

lineIndex = chunk.intro.lastIndexOf(n);
if (lineIndex !== -1)
{ return chunk.intro.substr(lineIndex + 1) + lineStr; }
if (lineIndex !== -1) { return chunk.intro.substr(lineIndex + 1) + lineStr; }
lineStr = chunk.intro + lineStr;
}
} while (chunk = chunk.previous);
} while ((chunk = chunk.previous));
lineIndex = this.intro.lastIndexOf(n);
if (lineIndex !== -1)
{ return this.intro.substr(lineIndex + 1) + lineStr; }
if (lineIndex !== -1) { return this.intro.substr(lineIndex + 1) + lineStr; }
return this.intro + lineStr;

@@ -948,7 +946,9 @@ };

do {
if (chunk.intro.length && chunk.intro.trim() ||
chunk.content.length && chunk.content.trim() ||
chunk.outro.length && chunk.outro.trim())
if (
(chunk.intro.length && chunk.intro.trim()) ||
(chunk.content.length && chunk.content.trim()) ||
(chunk.outro.length && chunk.outro.trim())
)
{ return false; }
} while (chunk = chunk.next);
} while ((chunk = chunk.next));
return true;

@@ -962,3 +962,3 @@ };

length += chunk.intro.length + chunk.content.length + chunk.outro.length;
} while (chunk = chunk.next);
} while ((chunk = chunk.next));
return length;

@@ -1059,3 +1059,3 @@ };

filename: source.filename,
separator: this.separator
separator: this.separator,
});

@@ -1065,3 +1065,5 @@ }

if (!isObject(source) || !source.content) {
throw new Error('bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`');
throw new Error(
'bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`'
);
}

@@ -1097,3 +1099,3 @@

content: new MagicString(str),
separator: (options && options.separator) || ''
separator: (options && options.separator) || '',
});

@@ -1107,3 +1109,3 @@

intro: this.intro,
separator: this.separator
separator: this.separator,
});

@@ -1115,3 +1117,3 @@

content: source.content.clone(),
separator: source.separator
separator: source.separator,
});

@@ -1124,3 +1126,3 @@ });

Bundle.prototype.generateDecodedMap = function generateDecodedMap (options) {
var this$1 = this;
var this$1$1 = this;
if ( options === void 0 ) options = {};

@@ -1143,6 +1145,6 @@

if (i > 0) {
mappings.advance(this$1.separator);
mappings.advance(this$1$1.separator);
}
var sourceIndex = source.filename ? this$1.uniqueSourceIndexByFilename[source.filename] : -1;
var sourceIndex = source.filename ? this$1$1.uniqueSourceIndexByFilename[source.filename] : -1;
var magicString = source.content;

@@ -1198,3 +1200,3 @@ var locate = getLocator(magicString.original);

names: names,
mappings: mappings.raw
mappings: mappings.raw,
};

@@ -1227,3 +1229,3 @@ };

Bundle.prototype.indent = function indent (indentStr) {
var this$1 = this;
var this$1$1 = this;

@@ -1239,3 +1241,3 @@ if (!arguments.length) {

this.sources.forEach(function (source, i) {
var separator = source.separator !== undefined ? source.separator : this$1.separator;
var separator = source.separator !== undefined ? source.separator : this$1$1.separator;
var indentStart = trailingNewline || (i > 0 && /\r?\n$/.test(separator));

@@ -1245,3 +1247,3 @@

exclude: source.indentExclusionRanges,
indentStart: indentStart //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
indentStart: indentStart, //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
});

@@ -1269,7 +1271,7 @@

Bundle.prototype.toString = function toString () {
var this$1 = this;
var this$1$1 = this;
var body = this.sources
.map(function (source, i) {
var separator = source.separator !== undefined ? source.separator : this$1.separator;
var separator = source.separator !== undefined ? source.separator : this$1$1.separator;
var str = (i > 0 ? separator : '') + source.content.toString();

@@ -1285,6 +1287,4 @@

Bundle.prototype.isEmpty = function isEmpty () {
if (this.intro.length && this.intro.trim())
{ return false; }
if (this.sources.some(function (source) { return !source.content.isEmpty(); }))
{ return false; }
if (this.intro.length && this.intro.trim()) { return false; }
if (this.sources.some(function (source) { return !source.content.isEmpty(); })) { return false; }
return true;

@@ -1294,3 +1294,6 @@ };

Bundle.prototype.length = function length () {
return this.sources.reduce(function (length, source) { return length + source.content.length(); }, this.intro.length);
return this.sources.reduce(
function (length, source) { return length + source.content.length(); },
this.intro.length
);
};

@@ -1297,0 +1300,0 @@

@@ -30,3 +30,3 @@ import { encode } from 'sourcemap-codec';

previous: { writable: true, value: null },
next: { writable: true, value: null }
next: { writable: true, value: null },
});

@@ -141,3 +141,2 @@ };

return true;
} else {

@@ -163,3 +162,2 @@ this.edit('', undefined, true);

return true;
} else {

@@ -349,3 +347,3 @@ this.edit('', undefined, true);

insertRight: false,
storeName: false
storeName: false,
};

@@ -359,15 +357,15 @@

Object.defineProperties(this, {
original: { writable: true, value: string },
outro: { writable: true, value: '' },
intro: { writable: true, value: '' },
firstChunk: { writable: true, value: chunk },
lastChunk: { writable: true, value: chunk },
lastSearchedChunk: { writable: true, value: chunk },
byStart: { writable: true, value: {} },
byEnd: { writable: true, value: {} },
filename: { writable: true, value: options.filename },
original: { writable: true, value: string },
outro: { writable: true, value: '' },
intro: { writable: true, value: '' },
firstChunk: { writable: true, value: chunk },
lastChunk: { writable: true, value: chunk },
lastSearchedChunk: { writable: true, value: chunk },
byStart: { writable: true, value: {} },
byEnd: { writable: true, value: {} },
filename: { writable: true, value: options.filename },
indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
sourcemapLocations: { writable: true, value: new BitSet() },
storedNames: { writable: true, value: {} },
indentStr: { writable: true, value: guessIndent(string) }
sourcemapLocations: { writable: true, value: new BitSet() },
storedNames: { writable: true, value: {} },
indentStr: { writable: true, value: guessIndent(string) },
});

@@ -458,3 +456,3 @@

MagicString.prototype.generateDecodedMap = function generateDecodedMap (options) {
var this$1 = this;
var this$1$1 = this;

@@ -486,3 +484,3 @@ options = options || {};

} else {
mappings.addUneditedChunk(sourceIndex, chunk, this$1.original, loc, this$1.sourcemapLocations);
mappings.addUneditedChunk(sourceIndex, chunk, this$1$1.original, loc, this$1$1.sourcemapLocations);
}

@@ -498,3 +496,3 @@

names: names,
mappings: mappings.raw
mappings: mappings.raw,
};

@@ -597,3 +595,5 @@ };

MagicString.prototype.insert = function insert () {
throw new Error('magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)');
throw new Error(
'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
);
};

@@ -603,3 +603,5 @@

if (!warned.insertLeft) {
console.warn('magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'); // eslint-disable-line no-console
console.warn(
'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'
); // eslint-disable-line no-console
warned.insertLeft = true;

@@ -613,3 +615,5 @@ }

if (!warned.insertRight) {
console.warn('magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'); // eslint-disable-line no-console
console.warn(
'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'
); // eslint-disable-line no-console
warned.insertRight = true;

@@ -666,3 +670,5 @@ }

if (start === end)
{ throw new Error('Cannot overwrite a zero-length range – use appendLeft or prependRight instead'); }
{ throw new Error(
'Cannot overwrite a zero-length range – use appendLeft or prependRight instead'
); }

@@ -674,3 +680,5 @@ this._split(start);

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
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;

@@ -781,15 +789,10 @@ }

MagicString.prototype.lastChar = function lastChar () {
if (this.outro.length)
{ return this.outro[this.outro.length - 1]; }
if (this.outro.length) { return this.outro[this.outro.length - 1]; }
var chunk = this.lastChunk;
do {
if (chunk.outro.length)
{ return chunk.outro[chunk.outro.length - 1]; }
if (chunk.content.length)
{ return chunk.content[chunk.content.length - 1]; }
if (chunk.intro.length)
{ return chunk.intro[chunk.intro.length - 1]; }
} while (chunk = chunk.previous);
if (this.intro.length)
{ return this.intro[this.intro.length - 1]; }
if (chunk.outro.length) { return chunk.outro[chunk.outro.length - 1]; }
if (chunk.content.length) { return chunk.content[chunk.content.length - 1]; }
if (chunk.intro.length) { return chunk.intro[chunk.intro.length - 1]; }
} while ((chunk = chunk.previous));
if (this.intro.length) { return this.intro[this.intro.length - 1]; }
return '';

@@ -800,4 +803,3 @@ };

var lineIndex = this.outro.lastIndexOf(n);
if (lineIndex !== -1)
{ return this.outro.substr(lineIndex + 1); }
if (lineIndex !== -1) { return this.outro.substr(lineIndex + 1); }
var lineStr = this.outro;

@@ -808,4 +810,3 @@ var chunk = this.lastChunk;

lineIndex = chunk.outro.lastIndexOf(n);
if (lineIndex !== -1)
{ return chunk.outro.substr(lineIndex + 1) + lineStr; }
if (lineIndex !== -1) { return chunk.outro.substr(lineIndex + 1) + lineStr; }
lineStr = chunk.outro + lineStr;

@@ -816,4 +817,3 @@ }

lineIndex = chunk.content.lastIndexOf(n);
if (lineIndex !== -1)
{ return chunk.content.substr(lineIndex + 1) + lineStr; }
if (lineIndex !== -1) { return chunk.content.substr(lineIndex + 1) + lineStr; }
lineStr = chunk.content + lineStr;

@@ -824,10 +824,8 @@ }

lineIndex = chunk.intro.lastIndexOf(n);
if (lineIndex !== -1)
{ return chunk.intro.substr(lineIndex + 1) + lineStr; }
if (lineIndex !== -1) { return chunk.intro.substr(lineIndex + 1) + lineStr; }
lineStr = chunk.intro + lineStr;
}
} while (chunk = chunk.previous);
} while ((chunk = chunk.previous));
lineIndex = this.intro.lastIndexOf(n);
if (lineIndex !== -1)
{ return this.intro.substr(lineIndex + 1) + lineStr; }
if (lineIndex !== -1) { return this.intro.substr(lineIndex + 1) + lineStr; }
return this.intro + lineStr;

@@ -946,7 +944,9 @@ };

do {
if (chunk.intro.length && chunk.intro.trim() ||
chunk.content.length && chunk.content.trim() ||
chunk.outro.length && chunk.outro.trim())
if (
(chunk.intro.length && chunk.intro.trim()) ||
(chunk.content.length && chunk.content.trim()) ||
(chunk.outro.length && chunk.outro.trim())
)
{ return false; }
} while (chunk = chunk.next);
} while ((chunk = chunk.next));
return true;

@@ -960,3 +960,3 @@ };

length += chunk.intro.length + chunk.content.length + chunk.outro.length;
} while (chunk = chunk.next);
} while ((chunk = chunk.next));
return length;

@@ -1057,3 +1057,3 @@ };

filename: source.filename,
separator: this.separator
separator: this.separator,
});

@@ -1063,3 +1063,5 @@ }

if (!isObject(source) || !source.content) {
throw new Error('bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`');
throw new Error(
'bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`'
);
}

@@ -1095,3 +1097,3 @@

content: new MagicString(str),
separator: (options && options.separator) || ''
separator: (options && options.separator) || '',
});

@@ -1105,3 +1107,3 @@

intro: this.intro,
separator: this.separator
separator: this.separator,
});

@@ -1113,3 +1115,3 @@

content: source.content.clone(),
separator: source.separator
separator: source.separator,
});

@@ -1122,3 +1124,3 @@ });

Bundle.prototype.generateDecodedMap = function generateDecodedMap (options) {
var this$1 = this;
var this$1$1 = this;
if ( options === void 0 ) options = {};

@@ -1141,6 +1143,6 @@

if (i > 0) {
mappings.advance(this$1.separator);
mappings.advance(this$1$1.separator);
}
var sourceIndex = source.filename ? this$1.uniqueSourceIndexByFilename[source.filename] : -1;
var sourceIndex = source.filename ? this$1$1.uniqueSourceIndexByFilename[source.filename] : -1;
var magicString = source.content;

@@ -1196,3 +1198,3 @@ var locate = getLocator(magicString.original);

names: names,
mappings: mappings.raw
mappings: mappings.raw,
};

@@ -1225,3 +1227,3 @@ };

Bundle.prototype.indent = function indent (indentStr) {
var this$1 = this;
var this$1$1 = this;

@@ -1237,3 +1239,3 @@ if (!arguments.length) {

this.sources.forEach(function (source, i) {
var separator = source.separator !== undefined ? source.separator : this$1.separator;
var separator = source.separator !== undefined ? source.separator : this$1$1.separator;
var indentStart = trailingNewline || (i > 0 && /\r?\n$/.test(separator));

@@ -1243,3 +1245,3 @@

exclude: source.indentExclusionRanges,
indentStart: indentStart //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
indentStart: indentStart, //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
});

@@ -1267,7 +1269,7 @@

Bundle.prototype.toString = function toString () {
var this$1 = this;
var this$1$1 = this;
var body = this.sources
.map(function (source, i) {
var separator = source.separator !== undefined ? source.separator : this$1.separator;
var separator = source.separator !== undefined ? source.separator : this$1$1.separator;
var str = (i > 0 ? separator : '') + source.content.toString();

@@ -1283,6 +1285,4 @@

Bundle.prototype.isEmpty = function isEmpty () {
if (this.intro.length && this.intro.trim())
{ return false; }
if (this.sources.some(function (source) { return !source.content.isEmpty(); }))
{ return false; }
if (this.intro.length && this.intro.trim()) { return false; }
if (this.sources.some(function (source) { return !source.content.isEmpty(); })) { return false; }
return true;

@@ -1292,3 +1292,6 @@ };

Bundle.prototype.length = function length () {
return this.sources.reduce(function (length, source) { return length + source.content.length(); }, this.intro.length);
return this.sources.reduce(
function (length, source) { return length + source.content.length(); },
this.intro.length
);
};

@@ -1340,4 +1343,3 @@

export default MagicString;
export { Bundle, SourceMap };
export { Bundle, SourceMap, MagicString as default };
//# sourceMappingURL=magic-string.es.js.map
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.MagicString = factory());
}(this, function () { 'use strict';
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.MagicString = factory());
})(this, (function () { 'use strict';

@@ -34,3 +34,3 @@ var BitSet = function BitSet(arg) {

previous: { writable: true, value: null },
next: { writable: true, value: null }
next: { writable: true, value: null },
});

@@ -145,3 +145,2 @@ };

return true;
} else {

@@ -167,3 +166,2 @@ this.edit('', undefined, true);

return true;
} else {

@@ -177,3 +175,7 @@ this.edit('', undefined, true);

var charToInteger = {};
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
for (var i = 0; i < chars.length; i++) {
charToInteger[chars.charCodeAt(i)] = i;
}
function encode(decoded) {

@@ -221,3 +223,3 @@ var sourceFileIndex = 0; // second field

var clamped = num & 31;
num >>= 5;
num >>>= 5;
if (num > 0) {

@@ -407,3 +409,3 @@ clamped |= 32;

insertRight: false,
storeName: false
storeName: false,
};

@@ -417,15 +419,15 @@

Object.defineProperties(this, {
original: { writable: true, value: string },
outro: { writable: true, value: '' },
intro: { writable: true, value: '' },
firstChunk: { writable: true, value: chunk },
lastChunk: { writable: true, value: chunk },
lastSearchedChunk: { writable: true, value: chunk },
byStart: { writable: true, value: {} },
byEnd: { writable: true, value: {} },
filename: { writable: true, value: options.filename },
original: { writable: true, value: string },
outro: { writable: true, value: '' },
intro: { writable: true, value: '' },
firstChunk: { writable: true, value: chunk },
lastChunk: { writable: true, value: chunk },
lastSearchedChunk: { writable: true, value: chunk },
byStart: { writable: true, value: {} },
byEnd: { writable: true, value: {} },
filename: { writable: true, value: options.filename },
indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
sourcemapLocations: { writable: true, value: new BitSet() },
storedNames: { writable: true, value: {} },
indentStr: { writable: true, value: guessIndent(string) }
sourcemapLocations: { writable: true, value: new BitSet() },
storedNames: { writable: true, value: {} },
indentStr: { writable: true, value: guessIndent(string) },
});

@@ -516,3 +518,3 @@

MagicString.prototype.generateDecodedMap = function generateDecodedMap (options) {
var this$1 = this;
var this$1$1 = this;

@@ -544,3 +546,3 @@ options = options || {};

} else {
mappings.addUneditedChunk(sourceIndex, chunk, this$1.original, loc, this$1.sourcemapLocations);
mappings.addUneditedChunk(sourceIndex, chunk, this$1$1.original, loc, this$1$1.sourcemapLocations);
}

@@ -556,3 +558,3 @@

names: names,
mappings: mappings.raw
mappings: mappings.raw,
};

@@ -655,3 +657,5 @@ };

MagicString.prototype.insert = function insert () {
throw new Error('magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)');
throw new Error(
'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
);
};

@@ -661,3 +665,5 @@

if (!warned.insertLeft) {
console.warn('magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'); // eslint-disable-line no-console
console.warn(
'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'
); // eslint-disable-line no-console
warned.insertLeft = true;

@@ -671,3 +677,5 @@ }

if (!warned.insertRight) {
console.warn('magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'); // eslint-disable-line no-console
console.warn(
'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'
); // eslint-disable-line no-console
warned.insertRight = true;

@@ -724,3 +732,5 @@ }

if (start === end)
{ throw new Error('Cannot overwrite a zero-length range – use appendLeft or prependRight instead'); }
{ throw new Error(
'Cannot overwrite a zero-length range – use appendLeft or prependRight instead'
); }

@@ -732,3 +742,5 @@ this._split(start);

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
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;

@@ -839,15 +851,10 @@ }

MagicString.prototype.lastChar = function lastChar () {
if (this.outro.length)
{ return this.outro[this.outro.length - 1]; }
if (this.outro.length) { return this.outro[this.outro.length - 1]; }
var chunk = this.lastChunk;
do {
if (chunk.outro.length)
{ return chunk.outro[chunk.outro.length - 1]; }
if (chunk.content.length)
{ return chunk.content[chunk.content.length - 1]; }
if (chunk.intro.length)
{ return chunk.intro[chunk.intro.length - 1]; }
} while (chunk = chunk.previous);
if (this.intro.length)
{ return this.intro[this.intro.length - 1]; }
if (chunk.outro.length) { return chunk.outro[chunk.outro.length - 1]; }
if (chunk.content.length) { return chunk.content[chunk.content.length - 1]; }
if (chunk.intro.length) { return chunk.intro[chunk.intro.length - 1]; }
} while ((chunk = chunk.previous));
if (this.intro.length) { return this.intro[this.intro.length - 1]; }
return '';

@@ -858,4 +865,3 @@ };

var lineIndex = this.outro.lastIndexOf(n);
if (lineIndex !== -1)
{ return this.outro.substr(lineIndex + 1); }
if (lineIndex !== -1) { return this.outro.substr(lineIndex + 1); }
var lineStr = this.outro;

@@ -866,4 +872,3 @@ var chunk = this.lastChunk;

lineIndex = chunk.outro.lastIndexOf(n);
if (lineIndex !== -1)
{ return chunk.outro.substr(lineIndex + 1) + lineStr; }
if (lineIndex !== -1) { return chunk.outro.substr(lineIndex + 1) + lineStr; }
lineStr = chunk.outro + lineStr;

@@ -874,4 +879,3 @@ }

lineIndex = chunk.content.lastIndexOf(n);
if (lineIndex !== -1)
{ return chunk.content.substr(lineIndex + 1) + lineStr; }
if (lineIndex !== -1) { return chunk.content.substr(lineIndex + 1) + lineStr; }
lineStr = chunk.content + lineStr;

@@ -882,10 +886,8 @@ }

lineIndex = chunk.intro.lastIndexOf(n);
if (lineIndex !== -1)
{ return chunk.intro.substr(lineIndex + 1) + lineStr; }
if (lineIndex !== -1) { return chunk.intro.substr(lineIndex + 1) + lineStr; }
lineStr = chunk.intro + lineStr;
}
} while (chunk = chunk.previous);
} while ((chunk = chunk.previous));
lineIndex = this.intro.lastIndexOf(n);
if (lineIndex !== -1)
{ return this.intro.substr(lineIndex + 1) + lineStr; }
if (lineIndex !== -1) { return this.intro.substr(lineIndex + 1) + lineStr; }
return this.intro + lineStr;

@@ -1004,7 +1006,9 @@ };

do {
if (chunk.intro.length && chunk.intro.trim() ||
chunk.content.length && chunk.content.trim() ||
chunk.outro.length && chunk.outro.trim())
if (
(chunk.intro.length && chunk.intro.trim()) ||
(chunk.content.length && chunk.content.trim()) ||
(chunk.outro.length && chunk.outro.trim())
)
{ return false; }
} while (chunk = chunk.next);
} while ((chunk = chunk.next));
return true;

@@ -1018,3 +1022,3 @@ };

length += chunk.intro.length + chunk.content.length + chunk.outro.length;
} while (chunk = chunk.next);
} while ((chunk = chunk.next));
return length;

@@ -1115,3 +1119,3 @@ };

filename: source.filename,
separator: this.separator
separator: this.separator,
});

@@ -1121,3 +1125,5 @@ }

if (!isObject(source) || !source.content) {
throw new Error('bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`');
throw new Error(
'bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`'
);
}

@@ -1153,3 +1159,3 @@

content: new MagicString(str),
separator: (options && options.separator) || ''
separator: (options && options.separator) || '',
});

@@ -1163,3 +1169,3 @@

intro: this.intro,
separator: this.separator
separator: this.separator,
});

@@ -1171,3 +1177,3 @@

content: source.content.clone(),
separator: source.separator
separator: source.separator,
});

@@ -1180,3 +1186,3 @@ });

Bundle.prototype.generateDecodedMap = function generateDecodedMap (options) {
var this$1 = this;
var this$1$1 = this;
if ( options === void 0 ) options = {};

@@ -1199,6 +1205,6 @@

if (i > 0) {
mappings.advance(this$1.separator);
mappings.advance(this$1$1.separator);
}
var sourceIndex = source.filename ? this$1.uniqueSourceIndexByFilename[source.filename] : -1;
var sourceIndex = source.filename ? this$1$1.uniqueSourceIndexByFilename[source.filename] : -1;
var magicString = source.content;

@@ -1254,3 +1260,3 @@ var locate = getLocator(magicString.original);

names: names,
mappings: mappings.raw
mappings: mappings.raw,
};

@@ -1283,3 +1289,3 @@ };

Bundle.prototype.indent = function indent (indentStr) {
var this$1 = this;
var this$1$1 = this;

@@ -1295,3 +1301,3 @@ if (!arguments.length) {

this.sources.forEach(function (source, i) {
var separator = source.separator !== undefined ? source.separator : this$1.separator;
var separator = source.separator !== undefined ? source.separator : this$1$1.separator;
var indentStart = trailingNewline || (i > 0 && /\r?\n$/.test(separator));

@@ -1301,3 +1307,3 @@

exclude: source.indentExclusionRanges,
indentStart: indentStart //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
indentStart: indentStart, //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
});

@@ -1325,7 +1331,7 @@

Bundle.prototype.toString = function toString () {
var this$1 = this;
var this$1$1 = this;
var body = this.sources
.map(function (source, i) {
var separator = source.separator !== undefined ? source.separator : this$1.separator;
var separator = source.separator !== undefined ? source.separator : this$1$1.separator;
var str = (i > 0 ? separator : '') + source.content.toString();

@@ -1341,6 +1347,4 @@

Bundle.prototype.isEmpty = function isEmpty () {
if (this.intro.length && this.intro.trim())
{ return false; }
if (this.sources.some(function (source) { return !source.content.isEmpty(); }))
{ return false; }
if (this.intro.length && this.intro.trim()) { return false; }
if (this.sources.some(function (source) { return !source.content.isEmpty(); })) { return false; }
return true;

@@ -1350,3 +1354,6 @@ };

Bundle.prototype.length = function length () {
return this.sources.reduce(function (length, source) { return length + source.content.length(); }, this.intro.length);
return this.sources.reduce(
function (length, source) { return length + source.content.length(); },
this.intro.length
);
};

@@ -1353,0 +1360,0 @@

@@ -7,5 +7,22 @@ export interface BundleOptions {

export interface SourceMapOptions {
/**
* Whether the mapping should be high-resolution.
* Hi-res mappings map every single character, meaning (for example) your devtools will always
* be able to pinpoint the exact location of function calls and so on.
* With lo-res mappings, devtools may only be able to identify the correct
* line - but they're quicker to generate and less bulky.
* If sourcemap locations have been specified with s.addSourceMapLocation(), they will be used here.
*/
hires: boolean;
/**
* The filename where you plan to write the sourcemap.
*/
file: string;
/**
* The filename of the file containing the original source.
*/
source: string;
/**
* Whether to include the original content in the map's sourcesContent array.
*/
includeContent: boolean;

@@ -37,3 +54,10 @@ }

/**
* Returns the equivalent of `JSON.stringify(map)`
*/
toString(): string;
/**
* Returns a DataURI containing the sourcemap. Useful for doing this sort of thing:
* `generateMap(options?: Partial<SourceMapOptions>): SourceMap;`
*/
toUrl(): string;

@@ -80,27 +104,106 @@ }

export default class MagicString {
constructor(str: string, options?: MagicStringOptions);
constructor(str: string, options?: Partial<MagicStringOptions>);
/**
* Adds the specified character index (with respect to the original string) to sourcemap mappings, if `hires` is false.
*/
addSourcemapLocation(char: number): void;
/**
* Appends the specified content to the end of the string.
*/
append(content: string): MagicString;
/**
* Appends the specified content at the index in the original string.
* If a range *ending* with index is subsequently moved, the insert will be moved with it.
* See also `s.prependLeft(...)`.
*/
appendLeft(index: number, content: string): MagicString;
/**
* Appends the specified content at the index in the original string.
* If a range *starting* with index is subsequently moved, the insert will be moved with it.
* See also `s.prependRight(...)`.
*/
appendRight(index: number, content: string): MagicString;
/**
* Does what you'd expect.
*/
clone(): MagicString;
/**
* Generates a version 3 sourcemap.
*/
generateMap(options?: Partial<SourceMapOptions>): SourceMap;
/**
* Generates a sourcemap object with raw mappings in array form, rather than encoded as a string.
* Useful if you need to manipulate the sourcemap further, but most of the time you will use `generateMap` instead.
*/
generateDecodedMap(options?: Partial<SourceMapOptions>): DecodedSourceMap;
getIndentString(): string;
/**
* Prefixes each line of the string with prefix.
* If prefix is not supplied, the indentation will be guessed from the original content, falling back to a single tab character.
*/
indent(options?: IndentOptions): MagicString;
/**
* Prefixes each line of the string with prefix.
* If prefix is not supplied, the indentation will be guessed from the original content, falling back to a single tab character.
*
* The options argument can have an exclude property, which is an array of [start, end] character ranges.
* These ranges will be excluded from the indentation - useful for (e.g.) multiline strings.
*/
indent(indentStr?: string, options?: IndentOptions): MagicString;
indentExclusionRanges: ExclusionRange | Array<ExclusionRange>;
/**
* Moves the characters from `start and `end` to `index`.
*/
move(start: number, end: number, index: number): MagicString;
/**
* Replaces the characters from `start` to `end` with `content`. The same restrictions as `s.remove()` apply.
*
* The fourth argument is optional. It can have a storeName property — if true, the original name will be stored
* for later inclusion in a sourcemap's names array — and a contentOnly property which determines whether only
* the content is overwritten, or anything that was appended/prepended to the range as well.
*/
overwrite(start: number, end: number, content: string, options?: boolean | OverwriteOptions): MagicString;
/**
* Prepends the string with the specified content.
*/
prepend(content: string): MagicString;
/**
* Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at index
*/
prependLeft(index: number, content: string): MagicString;
/**
* Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
*/
prependRight(index: number, content: string): MagicString;
/**
* Removes the characters from `start` to `end` (of the original string, **not** the generated string).
* Removing the same content twice, or making removals that partially overlap, will cause an error.
*/
remove(start: number, end: number): MagicString;
/**
* Returns the content of the generated string that corresponds to the slice between `start` and `end` of the original string.
* Throws error if the indices are for characters that were already removed.
*/
slice(start: number, end: number): string;
/**
* Returns a clone of `s`, with all content before the `start` and `end` characters of the original string removed.
*/
snip(start: number, end: number): MagicString;
/**
* Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start and end.
*/
trim(charType?: string): MagicString;
/**
* Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start.
*/
trimStart(charType?: string): MagicString;
/**
* Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the end.
*/
trimEnd(charType?: string): MagicString;
/**
* Removes empty lines from the start and end.
*/
trimLines(): MagicString;

@@ -110,2 +213,5 @@

lastLine(): string;
/**
* Returns true if the resulting source is empty (disregarding white space).
*/
isEmpty(): boolean;

@@ -115,2 +221,6 @@ length(): number;

original: string;
/**
* Returns the generated string.
*/
toString(): string;
}

@@ -5,3 +5,3 @@ {

"author": "Rich Harris",
"version": "0.25.7",
"version": "0.25.8",
"repository": "https://github.com/rich-harris/magic-string",

@@ -14,14 +14,16 @@ "main": "dist/magic-string.cjs.js",

"dependencies": {
"sourcemap-codec": "^1.4.4"
"sourcemap-codec": "^1.4.8"
},
"devDependencies": {
"eslint": "^5.16.0",
"mocha": "^5.2.0",
"prettier": "^1.18.2",
"rollup": "^1.16.3",
"rollup-plugin-buble": "^0.19.6",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0",
"@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-node-resolve": "^13.1.3",
"@rollup/plugin-replace": "^4.0.0",
"bumpp": "^7.1.1",
"conventional-changelog-cli": "^2.2.2",
"eslint": "^8.10.0",
"mocha": "^9.2.1",
"prettier": "^2.5.1",
"rollup": "^2.69.0",
"source-map": "^0.6.1",
"source-map-support": "^0.5.12"
"source-map-support": "^0.5.21"
},

@@ -43,3 +45,5 @@ "keywords": [

"lint": "eslint src test",
"watch": "rollup -cw"
"watch": "rollup -cw",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"release": "bumpp -x \"npm run changelog\" --all --commit --tag --push && npm publish"
},

@@ -46,0 +50,0 @@ "files": [

@@ -41,15 +41,17 @@ # magic-string

```js
var MagicString = require( 'magic-string' );
var s = new MagicString( 'problems = 99' );
import MagicString from 'magic-string';
import fs from 'fs'
s.overwrite( 0, 8, 'answer' );
const s = new MagicString('problems = 99');
s.overwrite(0, 8, 'answer');
s.toString(); // 'answer = 99'
s.overwrite( 11, 13, '42' ); // character indices always refer to the original string
s.overwrite(11, 13, '42'); // character indices always refer to the original string
s.toString(); // 'answer = 42'
s.prepend( 'var ' ).append( ';' ); // most methods are chainable
s.prepend('var ').append(';'); // most methods are chainable
s.toString(); // 'var answer = 42;'
var map = s.generateMap({
const map = s.generateMap({
source: 'source.js',

@@ -60,4 +62,4 @@ file: 'converted.js.map',

require( 'fs' ).writeFile( 'converted.js', s.toString() );
require( 'fs' ).writeFile( 'converted.js.map', map.toString() );
fs.writeFileSync('converted.js', s.toString());
fs.writeFileSync('converted.js.map', map.toString());
```

@@ -68,3 +70,3 @@

```js
var s = new MagicString( someCode, {
const s = new MagicString(someCode, {
// both these options will be used if you later

@@ -206,7 +208,7 @@ // call `bundle.addSource( s )` - see below

```js
var bundle = new MagicString.Bundle();
const bundle = new MagicString.Bundle();
bundle.addSource({
filename: 'foo.js',
content: new MagicString( 'var answer = 42;' )
content: new MagicString('var answer = 42;')
});

@@ -216,3 +218,3 @@

filename: 'bar.js',
content: new MagicString( 'console.log( answer )' )
content: new MagicString('console.log( answer )')
});

@@ -225,4 +227,4 @@

bundle.indent() // optionally, pass an indent string, otherwise it will be guessed
.prepend( '(function () {\n' )
.append( '}());' );
.prepend('(function () {\n')
.append('}());');

@@ -236,3 +238,3 @@ bundle.toString();

// options are as per `s.generateMap()` above
var map = bundle.generateMap({
const map = bundle.generateMap({
file: 'bundle.js',

@@ -247,8 +249,8 @@ includeContent: true,

```js
var bundle = new MagicString.Bundle();
var source = new MagicString( someCode, {
const bundle = new MagicString.Bundle();
const source = new MagicString(someCode, {
filename: 'foo.js'
});
bundle.addSource( source );
bundle.addSource(source);
```

@@ -255,0 +257,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc