magic-string-ast
Advanced tools
Comparing version
@@ -13,8 +13,4 @@ import MagicString__default, { MagicStringOptions, OverwriteOptions } from 'magic-string'; | ||
private prototype; | ||
offset: number; | ||
s: MagicString__default; | ||
constructor(str: string | MagicString__default, options?: MagicStringOptions & { | ||
/** offset of node */ | ||
offset?: number; | ||
}, prototype?: typeof MagicString__default); | ||
constructor(str: string | MagicString__default, options?: MagicStringOptions, prototype?: typeof MagicString__default); | ||
private getNodePos; | ||
@@ -21,0 +17,0 @@ removeNode(node: Node | Node[], { offset }?: { |
@@ -8,3 +8,2 @@ // src/index.ts | ||
this.s = typeof str === "string" ? new prototype(str, options) : str; | ||
this.offset = options?.offset ?? 0; | ||
return new Proxy(this.s, { | ||
@@ -19,9 +18,7 @@ get: (target, p, receiver) => { | ||
} | ||
offset; | ||
s; | ||
getNodePos(nodes, offset) { | ||
const _offset = offset ?? this.offset; | ||
getNodePos(nodes, offset = 0) { | ||
if (Array.isArray(nodes)) | ||
return [_offset + nodes[0].start, _offset + nodes.at(-1).end]; | ||
else return [_offset + nodes.start, _offset + nodes.end]; | ||
return [offset + nodes[0].start, offset + nodes.at(-1).end]; | ||
else return [offset + nodes.start, offset + nodes.end]; | ||
} | ||
@@ -52,10 +49,6 @@ removeNode(node, { offset } = {}) { | ||
else newS = this.s.snip(...this.getNodePos(node, offset)); | ||
return new _MagicStringAST(newS, { offset: this.offset }, this.prototype); | ||
return new _MagicStringAST(newS, void 0, this.prototype); | ||
} | ||
clone() { | ||
return new _MagicStringAST( | ||
this.s.clone(), | ||
{ offset: this.offset }, | ||
this.prototype | ||
); | ||
return new _MagicStringAST(this.s.clone(), void 0, this.prototype); | ||
} | ||
@@ -62,0 +55,0 @@ toString() { |
{ | ||
"name": "magic-string-ast", | ||
"version": "0.6.3", | ||
"version": "0.7.0", | ||
"description": "magic-string with Babel AST shortcut.", | ||
@@ -32,18 +32,18 @@ "type": "module", | ||
"dependencies": { | ||
"magic-string": "^0.30.13" | ||
"magic-string": "^0.30.17" | ||
}, | ||
"devDependencies": { | ||
"@babel/types": "^7.26.0", | ||
"@sxzz/eslint-config": "^4.4.1", | ||
"@babel/types": "^7.26.3", | ||
"@sxzz/eslint-config": "^4.5.1", | ||
"@sxzz/prettier-config": "^2.0.2", | ||
"@types/node": "^22.9.1", | ||
"bumpp": "^9.8.1", | ||
"eslint": "^9.15.0", | ||
"@types/node": "^22.10.2", | ||
"bumpp": "^9.9.1", | ||
"eslint": "^9.17.0", | ||
"fast-glob": "^3.3.2", | ||
"magic-string-stack": "^0.1.1", | ||
"prettier": "^3.3.3", | ||
"prettier": "^3.4.2", | ||
"tsup": "^8.3.5", | ||
"tsx": "^4.19.2", | ||
"typescript": "^5.6.3", | ||
"vitest": "^2.1.5" | ||
"typescript": "^5.7.2", | ||
"vitest": "^2.1.8" | ||
}, | ||
@@ -50,0 +50,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
12866
-4.87%195
-8.02%Updated