Convert estree compatable JavaScript AST
to babel AST
.
To use parsers like:
With babel
tools like:
- @babel/traverse
- @babel/types
- etc...
The thing is @babel/parser
has a little differences with estree
standard:
Property
ofObjectExpression
calledObjectProperty
FunctionExpression
of aProperty
located inObjectMethod
node.- etc...
estree-to-babel
aims to smooth this differences.
npm i estree-to-babel
const cherow = require('cherow');
const toBabel = require('estree-to-babel');
const traverse = require('@babel/traverse').default;
const ast = toBabel(cherow.parse(`
const const f = ({a}) => a;
`));
traverse({
ObjectProperty(path) {
console.log(path.value.name);
// output
'a';
});
});
MIT