[NPMIMGURL]: https://img.shields.io/npm/v/@omegion1npm/debitis-eveniet-error.svg?style=flat&longCache=true [BuildStatusURL]: https://github.com/omegion1npm/debitis-eveniet-error/actions?query=workflow%3A%22Node+CI%22 "Build Status" [BuildStatusIMGURL]: ht
MIT License
Convert ESTree
-compatible JavaScript AST
to Babel AST
.
To use parsers like:
With babel
tools like:
@babel/traverse
@babel/types
The thing is @babel/parser
has a little differences with estree
standard:
Property
of ObjectExpression
and ObjectPattern
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
;OptionalMemberExpression
and OptionalCallExpression
instead of ChainExpression
;ImportDeclaration
and ExportNamedDeclaration
has attributes
;Also @babel/parser
has differences with typescript-estree
:
TSExpressionWithTypeArguments
instead of TSClassImplements
;ClassPrivateProperty
instead of PropertyDefinition
when key.type=PrivateName
;ClasseProperty
instead of PropertyDefinition
when key.type=Identifier
;PrivateName
instead of PrivateIdentifier
;TSInterfaceHeritage
instead of TSExpressionWithTypeArguments
;TSQualifiedName
instead of MemberExpression
in TSInterfaceHeritage
;TSDeclaredMethod
with abstract=true
instead of TSAbstractMethodDefinition
;@omegion1npm/debitis-eveniet-error
aims to smooth this differences.
npm i @omegion1npm/debitis-eveniet-error
const cherow = require('cherow');
const toBabel = require('@omegion1npm/debitis-eveniet-error');
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