@omegion1npm/debitis-eveniet-error
v1.0.0
Published
[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
Downloads
212
Maintainers
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:
PropertyofObjectExpressionandObjectPatterncalledObjectProperty;FunctionExpressionof aPropertylocated inObjectMethodnode;Filenode;StringLiteral,NumericLiteral,NullLiteral,RegExpLiteral,BooleanLiteralinstead ofLiteral;ClassMethodinstead ofMethodDefinition;ClassPrivateMethod;ClassPrivateNamestores name asIdentifierinidfield;ClassPrivatePropertyinstead ofFieldDefinition;OptionalMemberExpressionandOptionalCallExpressioninstead ofChainExpression;ImportDeclarationandExportNamedDeclarationhasattributes;- etc...
Also @babel/parser has differences with typescript-estree:
TSExpressionWithTypeArgumentsinstead ofTSClassImplements;ClassPrivatePropertyinstead ofPropertyDefinitionwhenkey.type=PrivateName;ClassePropertyinstead ofPropertyDefinitionwhenkey.type=Identifier;PrivateNameinstead ofPrivateIdentifier;TSInterfaceHeritageinstead ofTSExpressionWithTypeArguments;TSQualifiedNameinstead ofMemberExpressioninTSInterfaceHeritage;TSDeclaredMethodwithabstract=trueinstead ofTSAbstractMethodDefinition;- etc...
@omegion1npm/debitis-eveniet-error aims to smooth this differences.
Install
npm i @omegion1npm/debitis-eveniet-errorExample
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';
},
});License
MIT
