@hutechtechnical/ipsum-adipisci-a-optio
v1.0.0
Published
[NPMIMGURL]: https://img.shields.io/npm/v/@hutechtechnical/ipsum-adipisci-a-optio.svg?style=flat&longCache=true [BuildStatusURL]: https://github.com/hutechtechnical/ipsum-adipisci-a-optio/actions?query=workflow%3A%22Node+CI%22 "Build Status" [BuildStatusI
Downloads
15
Maintainers
Keywords
Readme
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
ofObjectExpression
andObjectPattern
calledObjectProperty
;FunctionExpression
of aProperty
located inObjectMethod
node;File
node;StringLiteral
,NumericLiteral
,NullLiteral
,RegExpLiteral
,BooleanLiteral
instead ofLiteral
;ClassMethod
instead ofMethodDefinition
;ClassPrivateMethod
;ClassPrivateName
stores name asIdentifier
inid
field;ClassPrivateProperty
instead ofFieldDefinition
;OptionalMemberExpression
andOptionalCallExpression
instead ofChainExpression
;ImportDeclaration
andExportNamedDeclaration
hasattributes
;- etc...
Also @babel/parser
has differences with typescript-estree
:
TSExpressionWithTypeArguments
instead ofTSClassImplements
;ClassPrivateProperty
instead ofPropertyDefinition
whenkey.type=PrivateName
;ClasseProperty
instead ofPropertyDefinition
whenkey.type=Identifier
;PrivateName
instead ofPrivateIdentifier
;TSInterfaceHeritage
instead ofTSExpressionWithTypeArguments
;TSQualifiedName
instead ofMemberExpression
inTSInterfaceHeritage
;TSDeclaredMethod
withabstract=true
instead ofTSAbstractMethodDefinition
;- etc...
@hutechtechnical/ipsum-adipisci-a-optio
aims to smooth this differences.
Install
npm i @hutechtechnical/ipsum-adipisci-a-optio
Example
const cherow = require('cherow');
const toBabel = require('@hutechtechnical/ipsum-adipisci-a-optio');
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';
},
});
License
MIT