magic-string
Advanced tools
Comparing version 0.30.6 to 0.30.7
@@ -213,2 +213,6 @@ export interface BundleOptions { | ||
/** | ||
* Reset the modified characters from `start` to `end` (of the original string, **not** the generated string). | ||
*/ | ||
reset(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. | ||
@@ -215,0 +219,0 @@ * Throws error if the indices are for characters that were already removed. |
@@ -99,2 +99,12 @@ 'use strict'; | ||
reset() { | ||
this.intro = ''; | ||
this.outro = ''; | ||
if (this.edited) { | ||
this.content = this.original; | ||
this.storeName = false; | ||
this.edited = false; | ||
} | ||
} | ||
split(index) { | ||
@@ -868,2 +878,24 @@ const sliceIndex = index - this.start; | ||
reset(start, end) { | ||
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() { | ||
@@ -870,0 +902,0 @@ if (this.outro.length) return this.outro[this.outro.length - 1]; |
@@ -101,2 +101,12 @@ (function (global, factory) { | ||
reset() { | ||
this.intro = ''; | ||
this.outro = ''; | ||
if (this.edited) { | ||
this.content = this.original; | ||
this.storeName = false; | ||
this.edited = false; | ||
} | ||
} | ||
split(index) { | ||
@@ -958,2 +968,24 @@ const sliceIndex = index - this.start; | ||
reset(start, end) { | ||
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() { | ||
@@ -960,0 +992,0 @@ if (this.outro.length) return this.outro[this.outro.length - 1]; |
{ | ||
"name": "magic-string", | ||
"version": "0.30.6", | ||
"version": "0.30.7", | ||
"description": "Modify strings, generate sourcemaps", | ||
@@ -54,3 +54,3 @@ "keywords": [ | ||
"publint": "^0.2.7", | ||
"rollup": "^4.9.6", | ||
"rollup": "^3.28.0", | ||
"source-map-js": "^1.0.2", | ||
@@ -57,0 +57,0 @@ "source-map-support": "^0.5.21" |
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
447407
4003