import { types as t, template } from '@babel/core';
import { get } from '@babel/helper-plugin-utils';
export default function transformExamplePlugin({ types: t }) {
return {
visitor: {
Identifier(path) {
if (path.node.name === 'example') {
path.node.name = 'transformedExample';
}
},
VariableDeclaration(path) {
if (path.node.kind === 'const') {
const newNode = template.expression.ast('console.log("const declaration found")');
path.replaceWith(newNode);
}
},
},
};
}
npm install @babel/core @babel/helper-plugin-utils --save-dev
script
module.exports = {
plugins: [
'./transformExamplePlugin',
],
};
npx babel src --out-dir dist