Slide 17
Slide 17 text
17
Create a babel plugin
index.js
const { transform } = require("babel-core");
const src = "var foo = 'foooooo'"
const plugin = ({ types }) => ({
visitor: {
VariableDeclaration: nodePath => {
if (nodePath.node.kind === "var") {
nodePath.node.kind = "const";
}
}
}
});
const { code } = transform(src, { plugins: [plugin] });
console.log(code); // -> const foo = 'foooooo'