@macro-plugin/factory
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

@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

Package Sidebar

Install

npm i @macro-plugin/factory

Weekly Downloads

17

Version

1.2.1

License

MIT

Unpacked Size

365 kB

Total Files

13

Last publish

Collaborators

  • voorjaar