magic-string-ast
Advanced tools
Comparing version 0.6.1 to 0.6.2
@@ -38,10 +38,11 @@ import MagicString__default, { MagicStringOptions, OverwriteOptions } from 'magic-string'; | ||
} | ||
interface CodeTransform { | ||
code: string; | ||
map: any; | ||
} | ||
/** | ||
* Generate an object of code and source map from MagicString. | ||
*/ | ||
declare function generateTransform(s: MagicString__default | undefined, id: string): { | ||
code: string; | ||
map: any; | ||
} | undefined; | ||
declare function generateTransform(s: MagicString__default | undefined, id: string): CodeTransform | undefined; | ||
export { MagicStringAST, generateTransform }; | ||
export { type CodeTransform, MagicStringAST, generateTransform }; |
@@ -11,7 +11,5 @@ // src/index.ts | ||
get: (target, p, receiver) => { | ||
if (Reflect.has(this, p)) | ||
return Reflect.get(this, p, receiver); | ||
if (Reflect.has(this, p)) return Reflect.get(this, p, receiver); | ||
let parent = Reflect.get(target, p, receiver); | ||
if (typeof parent === "function") | ||
parent = parent.bind(target); | ||
if (typeof parent === "function") parent = parent.bind(target); | ||
return parent; | ||
@@ -27,8 +25,6 @@ } | ||
return [_offset + nodes[0].start, _offset + nodes.at(-1).end]; | ||
else | ||
return [_offset + nodes.start, _offset + nodes.end]; | ||
else return [_offset + nodes.start, _offset + nodes.end]; | ||
} | ||
removeNode(node, { offset } = {}) { | ||
if (isEmptyNodes(node)) | ||
return this; | ||
if (isEmptyNodes(node)) return this; | ||
this.s.remove(...this.getNodePos(node, offset)); | ||
@@ -38,4 +34,3 @@ return this; | ||
moveNode(node, index, { offset } = {}) { | ||
if (isEmptyNodes(node)) | ||
return this; | ||
if (isEmptyNodes(node)) return this; | ||
this.s.move(...this.getNodePos(node, offset), index); | ||
@@ -45,9 +40,7 @@ return this; | ||
sliceNode(node, { offset } = {}) { | ||
if (isEmptyNodes(node)) | ||
return ""; | ||
if (isEmptyNodes(node)) return ""; | ||
return this.s.slice(...this.getNodePos(node, offset)); | ||
} | ||
overwriteNode(node, content, { offset, ...options } = {}) { | ||
if (isEmptyNodes(node)) | ||
return this; | ||
if (isEmptyNodes(node)) return this; | ||
const _content = typeof content === "string" ? content : this.sliceNode(content); | ||
@@ -59,6 +52,4 @@ this.s.overwrite(...this.getNodePos(node, offset), _content, options); | ||
let newS; | ||
if (isEmptyNodes(node)) | ||
newS = this.s.snip(0, 0); | ||
else | ||
newS = this.s.snip(...this.getNodePos(node, offset)); | ||
if (isEmptyNodes(node)) newS = this.s.snip(0, 0); | ||
else newS = this.s.snip(...this.getNodePos(node, offset)); | ||
return new _MagicStringAST(newS, { offset: this.offset }, this.prototype); | ||
@@ -65,0 +56,0 @@ } |
{ | ||
"name": "magic-string-ast", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"description": "magic-string with Babel AST shortcut.", | ||
@@ -35,14 +35,14 @@ "type": "module", | ||
"devDependencies": { | ||
"@babel/types": "^7.24.5", | ||
"@sxzz/eslint-config": "^3.11.0", | ||
"@babel/types": "^7.24.7", | ||
"@sxzz/eslint-config": "^3.13.0", | ||
"@sxzz/prettier-config": "^2.0.2", | ||
"@types/node": "^20.12.12", | ||
"@types/node": "^20.14.8", | ||
"bumpp": "^9.4.1", | ||
"eslint": "^9.2.0", | ||
"eslint": "^9.5.0", | ||
"fast-glob": "^3.3.2", | ||
"magic-string-stack": "^0.1.1", | ||
"prettier": "^3.2.5", | ||
"tsup": "^8.0.2", | ||
"tsx": "^4.10.3", | ||
"typescript": "^5.4.5", | ||
"prettier": "^3.3.2", | ||
"tsup": "^8.1.0", | ||
"tsx": "^4.15.7", | ||
"typescript": "^5.5.2", | ||
"vitest": "^1.6.0" | ||
@@ -59,4 +59,6 @@ }, | ||
"test": "vitest", | ||
"typecheck": "tsc --noEmit", | ||
"format": "prettier --cache --write .", | ||
"release": "bumpp && pnpm publish" | ||
} | ||
} |
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
13434
209