$ cnpm install estree-to-babel
Convert estree compatible JavaScript AST
to babel AST
.
To use parsers like:
With babel
tools like:
The thing is @babel/parser
has a little differences with estree
standard:
Property
of ObjectExpression
called ObjectProperty
;FunctionExpression
of a Property
located in ObjectMethod
node;File
node;StringLiteral
, NumericLiteral
, NullLiteral
, RegExpLiteral
, BooleanLiteral
instead of Literal
;ClassMethod
instead of MethodDefinition
;ClassPrivateMethod
;ClassPrivateName
stores name as Identifier
in id
field;ClassPrivateProperty
instead of FieldDefinition
;CallExpression
instead of ImportExpression
;OptionalMemberExpression
and OptionalCallExpression
instead of ChainExpression
;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 f = ({a}) => a;
`));
traverse({
ObjectProperty(path) {
console.log(path.value.name);
// output
'a';
},
});
MIT
Copyright 2013 - present © cnpmjs.org