Socket
Socket
Sign inDemoInstall

magic-string

Package Overview
Dependencies
1
Maintainers
4
Versions
114
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.30.1 to 0.30.2

4

dist/magic-string.cjs.d.ts

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

* line - but they're quicker to generate and less bulky.
* You can also set `"boundary"` to generate a semi-hi-res mappings segmented per word boundary
* instead of per character, suitable for string semantics that are separated by words.
* If sourcemap locations have been specified with s.addSourceMapLocation(), they will be used here.
*/
hires?: boolean;
hires?: boolean | 'boundary';
/**

@@ -18,0 +20,0 @@ * The filename where you plan to write the sourcemap.

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

function getBtoa () {
function getBtoa() {
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {

@@ -287,2 +287,4 @@ return (str) => window.btoa(unescape(encodeURIComponent(str)));

const wordRegex = /\w/;
class Mappings {

@@ -316,6 +318,25 @@ constructor(hires) {

let first = true;
// when iterating each char, check if it's in a word boundary
let charInHiresBoundary = false;
while (originalCharIndex < chunk.end) {
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
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);
}
}

@@ -493,3 +514,3 @@

loc,
chunk.storeName ? names.indexOf(chunk.original) : -1
chunk.storeName ? names.indexOf(chunk.original) : -1,
);

@@ -505,7 +526,9 @@ } else {

file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
sources: [options.source ? getRelativePath(options.file || '', options.source) : (options.file || '')],
sources: [
options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
],
sourcesContent: options.includeContent ? [this.original] : undefined,
names,
mappings: mappings.raw,
x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined
x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
};

@@ -624,3 +647,3 @@ }

throw new Error(
'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
);

@@ -632,3 +655,3 @@ }

console.warn(
'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'
'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
); // eslint-disable-line no-console

@@ -644,3 +667,3 @@ warned.insertLeft = true;

console.warn(
'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'
'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
); // eslint-disable-line no-console

@@ -704,3 +727,3 @@ warned.insertRight = true;

throw new Error(
'Cannot overwrite a zero-length range – use appendLeft or prependRight instead'
'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
);

@@ -714,3 +737,3 @@

console.warn(
'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'
'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
); // eslint-disable-line no-console

@@ -937,3 +960,3 @@ warned.storeName = true;

throw new Error(
`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`
`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
);

@@ -1097,3 +1120,3 @@ }

match.index + match[0].length,
getReplacement(match, this.original)
getReplacement(match, this.original),
);

@@ -1107,3 +1130,3 @@ });

match.index + match[0].length,
getReplacement(match, this.original)
getReplacement(match, this.original),
);

@@ -1154,3 +1177,3 @@ }

throw new TypeError(
'MagicString.prototype.replaceAll called with a non-global RegExp argument'
'MagicString.prototype.replaceAll called with a non-global RegExp argument',
);

@@ -1185,3 +1208,3 @@ }

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

@@ -1280,3 +1303,3 @@ }

loc,
chunk.storeName ? names.indexOf(chunk.original) : -1
chunk.storeName ? names.indexOf(chunk.original) : -1,
);

@@ -1289,3 +1312,3 @@ } else {

loc,
magicString.sourcemapLocations
magicString.sourcemapLocations,
);

@@ -1408,3 +1431,3 @@ }

(length, source) => length + source.content.length(),
this.intro.length
this.intro.length,
);

@@ -1411,0 +1434,0 @@ }

@@ -263,3 +263,3 @@ (function (global, factory) {

function getBtoa () {
function getBtoa() {
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {

@@ -377,2 +377,4 @@ return (str) => window.btoa(unescape(encodeURIComponent(str)));

const wordRegex = /\w/;
class Mappings {

@@ -406,6 +408,25 @@ constructor(hires) {

let first = true;
// when iterating each char, check if it's in a word boundary
let charInHiresBoundary = false;
while (originalCharIndex < chunk.end) {
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
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);
}
}

@@ -583,3 +604,3 @@

loc,
chunk.storeName ? names.indexOf(chunk.original) : -1
chunk.storeName ? names.indexOf(chunk.original) : -1,
);

@@ -595,7 +616,9 @@ } else {

file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
sources: [options.source ? getRelativePath(options.file || '', options.source) : (options.file || '')],
sources: [
options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
],
sourcesContent: options.includeContent ? [this.original] : undefined,
names,
mappings: mappings.raw,
x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined
x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
};

@@ -714,3 +737,3 @@ }

throw new Error(
'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
);

@@ -722,3 +745,3 @@ }

console.warn(
'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'
'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
); // eslint-disable-line no-console

@@ -734,3 +757,3 @@ warned.insertLeft = true;

console.warn(
'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'
'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
); // eslint-disable-line no-console

@@ -794,3 +817,3 @@ warned.insertRight = true;

throw new Error(
'Cannot overwrite a zero-length range – use appendLeft or prependRight instead'
'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
);

@@ -804,3 +827,3 @@

console.warn(
'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'
'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
); // eslint-disable-line no-console

@@ -1027,3 +1050,3 @@ warned.storeName = true;

throw new Error(
`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`
`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
);

@@ -1187,3 +1210,3 @@ }

match.index + match[0].length,
getReplacement(match, this.original)
getReplacement(match, this.original),
);

@@ -1197,3 +1220,3 @@ });

match.index + match[0].length,
getReplacement(match, this.original)
getReplacement(match, this.original),
);

@@ -1244,3 +1267,3 @@ }

throw new TypeError(
'MagicString.prototype.replaceAll called with a non-global RegExp argument'
'MagicString.prototype.replaceAll called with a non-global RegExp argument',
);

@@ -1275,3 +1298,3 @@ }

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

@@ -1370,3 +1393,3 @@ }

loc,
chunk.storeName ? names.indexOf(chunk.original) : -1
chunk.storeName ? names.indexOf(chunk.original) : -1,
);

@@ -1379,3 +1402,3 @@ } else {

loc,
magicString.sourcemapLocations
magicString.sourcemapLocations,
);

@@ -1498,3 +1521,3 @@ }

(length, source) => length + source.content.length(),
this.intro.length
this.intro.length,
);

@@ -1501,0 +1524,0 @@ }

{
"name": "magic-string",
"version": "0.30.1",
"version": "0.30.2",
"description": "Modify strings, generate sourcemaps",

@@ -45,12 +45,12 @@ "keywords": [

"devDependencies": {
"@rollup/plugin-node-resolve": "^14.1.0",
"@rollup/plugin-replace": "^4.0.0",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-replace": "^5.0.2",
"benchmark": "^2.1.4",
"bumpp": "^9.1.1",
"conventional-changelog-cli": "^3.0.0",
"eslint": "^8.44.0",
"eslint": "^8.45.0",
"mocha": "^10.2.0",
"prettier": "^2.8.8",
"publint": "^0.1.15",
"rollup": "^2.79.1",
"prettier": "^3.0.0",
"publint": "^0.2.0",
"rollup": "^3.26.3",
"source-map-js": "^1.0.2",

@@ -57,0 +57,0 @@ "source-map-support": "^0.5.21"

@@ -110,3 +110,3 @@ # magic-string

* `includeContent` - whether to include the original content in the map's `sourcesContent` array
* `hires` - 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` - 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. You can also set `"boundary"` to generate a semi-hi-res mappings segmented per word boundary instead of per character, suitable for string semantics that are separated by words. If sourcemap locations have been specified with `s.addSourcemapLocation()`, they will be used here.

@@ -113,0 +113,0 @@ The returned sourcemap has two (non-enumerable) methods attached for convenience:

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

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc