@dtwo/unplugin-ast
v0.5.5
Published
Manipulate the AST to transform your code.
Downloads
6
Maintainers
Readme
@dtwo/unplugin-ast
Manipulate the AST to transform your code.
Installation
npm i @dtwo/unplugin-ast
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
Bultin Transformers
import { RemoveWrapperFunction } from '@dtwo/unplugin-ast/transformers'
/**
* Removes wrapper function. e.g `defineComponent`, `defineConfig`...
* @param functionNames - function names to remove
*/
declare const RemoveWrapperFunction: (
functionNames: Arrayable<string>
) => Transformer<CallExpression>
Custom Transformers
import type { CallExpression } from '@babel/types'
import type { Transformer } from '@dtwo/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]
},
})
License
MIT License