magic-string
Advanced tools
Comparing version 0.26.0 to 0.26.1
@@ -688,3 +688,7 @@ 'use strict'; | ||
const original = this.original.slice(start, end); | ||
Object.defineProperty(this.storedNames, original, { writable: true, value: true, enumerable: true }); | ||
Object.defineProperty(this.storedNames, original, { | ||
writable: true, | ||
value: true, | ||
enumerable: true, | ||
}); | ||
} | ||
@@ -1025,19 +1029,15 @@ | ||
replace(searchValue, replacement) { | ||
function getReplacement(match) { | ||
function getReplacement(match, str) { | ||
if (typeof replacement === 'string') { | ||
return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => { | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter | ||
if (i === '$') | ||
return '$'; | ||
if (i === '&') | ||
return match[0]; | ||
if (i === '$') return '$'; | ||
if (i === '&') return match[0]; | ||
const num = +i; | ||
if (num < match.length) | ||
return match[+i]; | ||
if (num < match.length) return match[+i]; | ||
return `$${i}`; | ||
}); | ||
} else { | ||
return replacement(...match, match.index, str, match.groups); | ||
} | ||
else { | ||
return replacement(...match); | ||
} | ||
} | ||
@@ -1047,3 +1047,3 @@ function matchAll(re, str) { | ||
const matches = []; | ||
while (match = re.exec(str)) { | ||
while ((match = re.exec(str))) { | ||
matches.push(match); | ||
@@ -1057,9 +1057,16 @@ } | ||
if (match.index != null) | ||
this.overwrite(match.index, match.index + match[0].length, getReplacement(match)); | ||
this.overwrite( | ||
match.index, | ||
match.index + match[0].length, | ||
getReplacement(match, this.original) | ||
); | ||
}); | ||
} | ||
else { | ||
} else { | ||
const match = this.original.match(searchValue); | ||
if (match && match.index != null) | ||
this.overwrite(match.index, match.index + match[0].length, getReplacement(match)); | ||
this.overwrite( | ||
match.index, | ||
match.index + match[0].length, | ||
getReplacement(match, this.original) | ||
); | ||
} | ||
@@ -1066,0 +1073,0 @@ return this; |
@@ -746,3 +746,7 @@ (function (global, factory) { | ||
const original = this.original.slice(start, end); | ||
Object.defineProperty(this.storedNames, original, { writable: true, value: true, enumerable: true }); | ||
Object.defineProperty(this.storedNames, original, { | ||
writable: true, | ||
value: true, | ||
enumerable: true, | ||
}); | ||
} | ||
@@ -1083,19 +1087,15 @@ | ||
replace(searchValue, replacement) { | ||
function getReplacement(match) { | ||
function getReplacement(match, str) { | ||
if (typeof replacement === 'string') { | ||
return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => { | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter | ||
if (i === '$') | ||
return '$'; | ||
if (i === '&') | ||
return match[0]; | ||
if (i === '$') return '$'; | ||
if (i === '&') return match[0]; | ||
const num = +i; | ||
if (num < match.length) | ||
return match[+i]; | ||
if (num < match.length) return match[+i]; | ||
return `$${i}`; | ||
}); | ||
} else { | ||
return replacement(...match, match.index, str, match.groups); | ||
} | ||
else { | ||
return replacement(...match); | ||
} | ||
} | ||
@@ -1105,3 +1105,3 @@ function matchAll(re, str) { | ||
const matches = []; | ||
while (match = re.exec(str)) { | ||
while ((match = re.exec(str))) { | ||
matches.push(match); | ||
@@ -1115,9 +1115,16 @@ } | ||
if (match.index != null) | ||
this.overwrite(match.index, match.index + match[0].length, getReplacement(match)); | ||
this.overwrite( | ||
match.index, | ||
match.index + match[0].length, | ||
getReplacement(match, this.original) | ||
); | ||
}); | ||
} | ||
else { | ||
} else { | ||
const match = this.original.match(searchValue); | ||
if (match && match.index != null) | ||
this.overwrite(match.index, match.index + match[0].length, getReplacement(match)); | ||
this.overwrite( | ||
match.index, | ||
match.index + match[0].length, | ||
getReplacement(match, this.original) | ||
); | ||
} | ||
@@ -1124,0 +1131,0 @@ return this; |
{ | ||
"name": "magic-string", | ||
"version": "0.26.0", | ||
"version": "0.26.1", | ||
"description": "Modify strings, generate sourcemaps", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
382934
3499
0