debitis-eveniet-error

[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

Downloads
3
Stars
0
Committers
1

Estree-to-babel NPM version Build Status Coverage Status

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 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;
  • etc...

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;
  • etc...

@omegion1npm/debitis-eveniet-error aims to smooth this differences.

Install

npm i @omegion1npm/debitis-eveniet-error

Example

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

Package Rankings
Top 36.89% on Npmjs.org
Badges
Extracted from project README
NPM version Build Status Coverage Status
Related Projects