const babel = require('@babel/core'); const code = `const greet = message => console.log(message); greet('Hello, World!');`; const result = babel.transform(code, { presets: ['@babel/preset-env'] }); console.log(result.code);
const babel = require('@babel/core'); const code = `const upper = text => text.toUpperCase(); console.log(upper('hello, world!'));`; const result = babel.transform(code, { plugins: [ function (babel) { return { visitor: { CallExpression(path) { if (path.node.callee.name === 'upper') { path.node.arguments[0].value = path.node.arguments[0].value.toUpperCase(); } } } }; } ] }); console.log(result.code);In this example, we are adding a custom plugin that converts the argument of the `upper` function to uppercase. Overall, the `@babel/core` package provides a powerful toolset for transforming and compiling JavaScript code to make it compatible with various browsers and environments.