Skip to main content

Built and signed on GitHub Actions

magic-string with Babel AST shortcut.

This package works with Bun, Cloudflare Workers, Node.js, Deno, Browsers
JSR Score
100%
Published
a month ago (0.6.1)

magic-string-ast npm JSR

Unit Test

magic-string with Babel AST shortcut.

Install

# npm
npm i magic-string-ast

# jsr
npx jsr add -D @sxzz/magic-string-ast

Usage

import { MagicStringAST } from 'magic-string-ast'

const offset = 0
const node = {
  // AST node from @babel/parser
  start: 6,
  end: 7,
  // ...
}

const s = new MagicStringAST('const a = 1')
s.sliceNode(node, { offset }) // 'a'
s.removeNode(node)
s.moveNode(node, 0)
s.overwriteNode(node, 'foo')

For more APIs, see docs and magic-string.

Sponsors

License

MIT License © 2023-PRESENT 三咲智子

Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @sxzz/magic-string-ast

Import symbol

import * as mod from "@sxzz/magic-string-ast";

Add Package

npx jsr add @sxzz/magic-string-ast

Import symbol

import * as mod from "@sxzz/magic-string-ast";

Add Package

yarn dlx jsr add @sxzz/magic-string-ast

Import symbol

import * as mod from "@sxzz/magic-string-ast";

Add Package

pnpm dlx jsr add @sxzz/magic-string-ast

Import symbol

import * as mod from "@sxzz/magic-string-ast";

Add Package

bunx jsr add @sxzz/magic-string-ast

Import symbol

import * as mod from "@sxzz/magic-string-ast";