Socket
Book a DemoInstallSign in
Socket

@macro-plugin/factory

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@macro-plugin/factory

Macro factories for creating AST.

latest
Source
npmnpm
Version
1.2.1
Version published
Maintainers
1
Created
Source

@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

Keywords

factory

FAQs

Package last updated on 23 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts