A tool to create user-defined helpers that can be used in your babel plugin.
The usability is like that of @babel/helpers.
npm install --save-dev babel-udf-helpers
- node.js (>=10.15)
- typescript target (ES2018)
Use in your babel plugin as follows.
It works the same as babel-helpers addHelper, so you can use it anywhere in your visitor.
import { useDangerousUDFHelpers } from 'babel-udf-helpers';
import helpers from './helpers';
export default function({types: t}){
pre(){
useDangerousUDFHelpers(this, { helpers });
},
visitor: {
Program(path){
this.addUDFHelper("programHelper")
},
ImportDeclaration(path) {
this.addUDFHelper("importHelper")
}
}
}
helpers.js
looks like the following.
import { helper } from 'babel-udf-helpers';
const helpers = Object.create(null);
export default helpers;
helpers.programHelper = helper`
export default function _programHelper(){
return "programHelper";
};
`
helpers.importHelper = helper`
export default function _importHelper(){
return "importHelper";
};
`
Full docs are available at https://yukihirop.github.io/babel-udf-helpers
Run the plugin test with babel-udf-helpers
in typescript and javascript.
{
make all-deps
make example-test
}
The gem is available as open source under the terms of the MIT License.
- Fork it ( http://github.com/yukihirop/babel-udf-helpers/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request