mirror of
https://github.com/developit/microbundle.git
synced 2026-01-18 13:56:35 +00:00
21 lines
599 B
JavaScript
21 lines
599 B
JavaScript
import { createMacro } from 'babel-plugin-macros';
|
|
|
|
function myMacro({ references, state, babel }) {
|
|
const { types: t } = babel;
|
|
|
|
references.macro.forEach(referencePath => {
|
|
const parentPath = referencePath.findParent(t.isCallExpression);
|
|
let variableName = referencePath.findParent(t.isVariableDeclarator).node.id
|
|
.name;
|
|
if (
|
|
parentPath.node.arguments.length > 0 &&
|
|
parentPath.node.arguments[0] !== ''
|
|
) {
|
|
variableName = parentPath.node.arguments[0].value;
|
|
}
|
|
parentPath.replaceWith(t.stringLiteral(`${variableName}-macro`));
|
|
});
|
|
}
|
|
|
|
module.exports = createMacro(myMacro);
|