Closed vedantroy closed 4 years ago
Hi @vedantroy,
The macro must be the default export. If you want to transform non-default exports then use the references
object.
import { createMacro } from "babel-plugin-macros"
function gemmafyMacro({references, state, babel}) {
references.default.forEach(referencePath => {
// do macro stuff
})
references.gemmafyCopy.forEach(referencePath => {
// do macro stuff for the named import
})
}
export default createMacro(gemmafyMacro)
See the documentation for more info.
Oh, I'm silly! I should get better at reading docs :facepalm:
babel-plugin-macros
version: 2.8.0node
version: 13.9.0npm
(oryarn
) version: 6.14.4Relevant code:
src/macro.js (this file is compiled to "dist/macro.js" with "@babel/plugin-transform-modules-commonjs"):
test.js:
test_compiled.js:
What happened:
Only
gemmafy
was applied.gemmafyCopy
was not applied.Reproduction repository: https://github.com/vedantroy/babel-plugin-macros-repro
Run
npm run build-macro
and thennpm run build-test
. Then look attest_compiled.js
in the "tests" folder. You will see that only 1 of the macros has been applied.Problem description:
Macros are not applied, unless they are the default export?
Suggested solution: Not sure. If this is a bug, I'd be willing to look into a PR.