Huáng Jùnliàng 4bf36e64da
Create File class for babel helpers (#10575)
* add test

* fix: pass File to helper traverser

* pass babel.File to helpers.ensure
2020-03-17 09:58:46 +01:00

23 lines
507 B
JavaScript

const defineHelper = require("../../../helpers/define-helper").default;
const main = defineHelper(__dirname, "main", `
export default function helper() {}
`);
module.exports = function() {
return {
visitor: {
Identifier(path) {
if (path.node.name !== "REPLACE_ME") {
if (path.hub) {
path.node.name += "_hub_is_found";
}
return;
}
const helper = this.addHelper(main);
path.replaceWith(helper);
},
},
};
};