Assume I have such Javascript code
import someFunc from 'somewhere';
const prefix = 'Planet';
someFunc(prefix + 'Earth');
If I use babeljs in my project I can write simple transform plugin
export default function({types: t}) {
return {
visitor: {
CallExpression: {
enter(path, {opts, file}) {
if (path.node.callee.name !== 'someFunc') {
return;
}
<...>
}
}
}
}
}
How can I take 'prefix' variable value inside plugin or evaluate whole BinaryExpression expression to replace it with result string to get this?
import someFunc from 'somewhere';
someFunc('PlanetEarth');