Skip to content

Commit

Permalink
feat: snipNode return MagicStringAST instance
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Apr 17, 2024
1 parent e307b88 commit 8914922
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,11 @@ export class MagicStringAST implements MagicString {
snipNode(
node: Node | Node[],
{ offset }: { offset?: number } = {},
): MagicString {
if (isEmptyNodes(node))
return new MagicString('', {
// @ts-expect-error
filename: super.filename,
})
return this.s.snip(...this.getNodePos(node, offset))
): MagicStringAST {
let newS: MagicString
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 })
}

clone(): MagicStringAST {
Expand Down

0 comments on commit 8914922

Please sign in to comment.