New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

unplugin-ast

Package Overview
Dependencies
Maintainers
0
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unplugin-ast

Manipulate the AST to transform your code.

  • 0.14.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
61K
decreased by-2.26%
Maintainers
0
Weekly downloads
 
Created
Source

unplugin-ast npm jsr

Unit Test

Manipulate the AST to transform your code.

Installation

npm i unplugin-ast
Vite
// vite.config.ts
import AST from 'unplugin-ast/vite'

export default defineConfig({
  plugins: [AST()],
})


Rollup
// rollup.config.js
import AST from 'unplugin-ast/rollup'

export default {
  plugins: [AST()],
}


esbuild
// esbuild.config.js
import { build } from 'esbuild'

build({
  plugins: [require('unplugin-ast/esbuild')()],
})


Webpack
// webpack.config.js
module.exports = {
  /* ... */
  plugins: [require('unplugin-ast/webpack')()],
}


Configuration

The following show the default values of the configuration

AST({
  // filters for transforming targets
  include: [/\.[jt]sx?$/],
  exclude: undefined,

  // Rollup and esbuild do not support using enforce to control the order of plugins. Users need to maintain the order manually.
  enforce: undefined,

  // https://babeljs.io/docs/en/babel-parser#options
  parserOptions: {},

  // Refer to Custom Transformers belows
  transformer: [],
})

Transformers

Built-in Transformers

RemoveWrapperFunction
import { RemoveWrapperFunction } from 'unplugin-ast/transformers'

/**
 * Removes wrapper function. e.g `defineComponent`, `defineConfig`...
 * @param functionNames - function names to remove
 *
 * @example defineComponent()
 * @example tw`text-red-500 ${expr}`
 */
export function RemoveWrapperFunction(
  functionNames: Arrayable<string>,
): Transformer<CallExpression>

Transforms:

export default defineConfig(config)

To:

export default config
RemoveNode
import { RemoveNode } from 'unplugin-ast/transformers'

/**
 * Removes arbitrary nodes.
 */
export function RemoveNode(
  onNode: (
    node: Node,
    parent: Node | null | undefined,
    index: number | null | undefined,
  ) => Awaitable<boolean>,
): Transformer

Custom Transformers

import type { CallExpression } from '@babel/types'
import type { Transformer } from 'unplugin-ast'

export const RemoveWrapperFunction = (
  functionNames: string[],
): Transformer<CallExpression> => ({
  onNode: (node) =>
    node.type === 'CallExpression' &&
    node.callee.type === 'Identifier' &&
    functionNames.includes(node.callee.name),

  transform(node) {
    return node.arguments[0]
  },
})

Sponsors

License

MIT License © 2022-PRESENT 三咲智子

Keywords

FAQs

Package last updated on 03 Mar 2025

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc