@macro-plugin/factory
v1.2.1
Published
Macro factories for creating AST.
Downloads
47
Maintainers
Readme
@macro-plugin/factory
Macro factories for simplify the process of creating swc AST.
Installation
# if you use npm
npm i -D @macro-plugin/factory
# if you use pnpm
pnpm i -D @macro-plugin/factory
# if you use yarn
yarn add -D @macro-plugin/factory
Usage
Given an exmaple.
import { createIdentifier } from "@macro-plugin/factory"
createIdentifier("hello")
// {
// type: "Identifier",
// value: "hello",
// optional: false,
// span: {
// start: 0,
// end: 0,
// ctxt: 0
// }
// }
Or with macros
import { $Identifier } from "@macro-plugin/factory"
$Identifier("hello")
Runtime vs Macros
The results generated by macros and runtime are the same in theory, but macros performance may be better.
For example, with runtime, if you use createIdentifier
api, then the function createIdentifier
will be bundled to your macro plugin.
If you use $Identifier
, macro-plugin will replace your call with raw object { type: "Identifier", ... }
. So it will perform better.
Built-in factory
Runtime
See runtime
Macros
See macros