# @macro-plugin/factory

> Macro factories for creating AST.

Latest version **1.2.1** (published 2023-06-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @macro-plugin/factory
pnpm add @macro-plugin/factory
yarn add @macro-plugin/factory
bun add @macro-plugin/factory
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2023-06-23 |
| First published | 2023-04-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 356.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Raven Satir |
| Maintainers | voorjaar |
| Keywords | factory, macro, macros, macro-plugin |

## Links

- npm: https://www.npmjs.com/package/@macro-plugin/factory
- Repository: https://github.com/macro-plugin/macros
- Homepage: https://github.com/macro-plugin/macros/tree/main/packages/factory
- Issues: https://github.com/macro-plugin/macros/issues
- npm.io page: https://npm.io/package/@macro-plugin/factory

## Dependencies (1)

- [@macro-plugin/core](https://npm.io/package/@macro-plugin/core.md) 1.2.0

## Recent versions

- 1.2.1 (latest) — 2023-06-23
- 1.2.0 — 2023-06-18
- 1.1.1 — 2023-06-18
- 1.1.0 — 2023-06-16
- 1.0.11 — 2023-05-09
- 1.0.10 — 2023-05-08
- 1.0.9 — 2023-05-03
- 1.0.8 — 2023-05-02
- 1.0.7 — 2023-05-02
- 1.0.6 — 2023-04-27
- 1.0.5 — 2023-04-27
- 1.0.4 — 2023-04-24
- 1.0.3 — 2023-04-23
- 1.0.2 — 2023-04-22
- 1.0.1 — 2023-04-22
- … 1 more at https://npm.io/package/@macro-plugin/factory/versions

## README

# @macro-plugin/factory

Macro factories for simplify the process of creating swc AST.

## Installation

```sh
# 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.

```js
import { createIdentifier } from "@macro-plugin/factory"

createIdentifier("hello")

// {
//     type: "Identifier",
//     value: "hello",
//     optional: false,
//     span: {
//         start: 0,
//         end: 0,
//         ctxt: 0
//     }
// }

```

Or with macros

```js
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](./src/runtime.ts)

### Macros

See [macros](./src/macros.ts)

---
_Source: https://npm.io/package/@macro-plugin/factory · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
