Manipulate the AST to transform your code.
100
stars
258
commits
TypeScript
primary language
Sep 11, 2026
updated
Manipulate the AST to transform your code.
npm i unplugin-ast
// vite.config.ts
import AST from 'unplugin-ast/vite'
export default defineConfig({
plugins: [AST()],
})
// rollup.config.js
import AST from 'unplugin-ast/rollup'
export default {
plugins: [AST()],
}
// rolldown.config.ts / tsdown.config.ts
import AST from 'unplugin-ast/rolldown'
export default {
plugins: [AST()],
}
import { build } from 'esbuild'
import AST from 'unplugin-ast/esbuild'
build({
plugins: [AST()],
})
// webpack.config.js
import AST from 'unplugin-ast/webpack'
export default {
/* ... */
plugins: [AST()],
}
// rspack.config.js
import AST from 'unplugin-ast/rspack'
export default {
/* ... */
plugins: [AST()],
}
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://yuku.fyi/parser/#options
parserOptions: {},
// Refer to Custom Transformers belows
transformer: [],
})
AST nodes follow ESTree / TypeScript-ESTree. Yuku's typed guards, builders,
walker, and utilities are available from the ast namespace, while its types
are directly exported from unplugin-ast/yuku. No additional Yuku packages are
required.
import { ast, type CallExpression } from 'unplugin-ast/yuku'
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 | TaggedTemplateExpression>
Transforms:
export default defineConfig(config)
To:
export default config
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
import type { Transformer } from 'unplugin-ast'
import type { CallExpression } from 'unplugin-ast/yuku'
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]
},
})
TypeScript
99.7%
Manipulate the AST to transform your code.
100
stars
258
commits
TypeScript
primary language
Sep 11, 2026
updated
Manipulate the AST to transform your code.
npm i unplugin-ast
// vite.config.ts
import AST from 'unplugin-ast/vite'
export default defineConfig({
plugins: [AST()],
})
// rollup.config.js
import AST from 'unplugin-ast/rollup'
export default {
plugins: [AST()],
}
// rolldown.config.ts / tsdown.config.ts
import AST from 'unplugin-ast/rolldown'
export default {
plugins: [AST()],
}
import { build } from 'esbuild'
import AST from 'unplugin-ast/esbuild'
build({
plugins: [AST()],
})
// webpack.config.js
import AST from 'unplugin-ast/webpack'
export default {
/* ... */
plugins: [AST()],
}
// rspack.config.js
import AST from 'unplugin-ast/rspack'
export default {
/* ... */
plugins: [AST()],
}
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://yuku.fyi/parser/#options
parserOptions: {},
// Refer to Custom Transformers belows
transformer: [],
})
AST nodes follow ESTree / TypeScript-ESTree. Yuku's typed guards, builders,
walker, and utilities are available from the ast namespace, while its types
are directly exported from unplugin-ast/yuku. No additional Yuku packages are
required.
import { ast, type CallExpression } from 'unplugin-ast/yuku'
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 | TaggedTemplateExpression>
Transforms:
export default defineConfig(config)
To:
export default config
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
import type { Transformer } from 'unplugin-ast'
import type { CallExpression } from 'unplugin-ast/yuku'
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]
},
})
TypeScript
99.7%