estree-to-babel
convert estree ast to babel
Last updated 3 months ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install estree-to-babel 
SYNC missed versions from official npm registry.

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;
  • JSXText has extra field;
  • extra.parenthesized=true instead of ParenthesizedExpression;
  • etc...

Also @babel/parser has differences with typescript-estree:

  • ClassPrivateProperty instead of PropertyDefinition when key.type=PrivateName;
  • ClasseProperty instead of PropertyDefinition when key.type=Identifier;
  • PrivateName instead of PrivateIdentifier;
  • TSQualifiedName instead of MemberExpression in TSInterfaceHeritage;
  • TSDeclaredMethod with abstract=true instead of TSAbstractMethodDefinition;
  • extra.parenthesized=true instead of TSParenthesizedType;
  • etc...

estree-to-babel aims to smooth this differences.

Install

npm i estree-to-babel

Example

import {parse} from 'cherow';
import {estreeToBabel} from 'estree-to-babel';
import {traverse} from '@babel/traverse';

const ast = estreeToBabel(parse(`
    const f = ({a}) => a;
`));

traverse({
    ObjectProperty(path) {
        console.log(path.value.name);
        // output
        'a';
    },
});

You can provide options:

import * as cherow from 'cherow';
import {estreeToBabel} from 'estree-to-babel';
import traverse from '@babel/traverse';

const options = {
    convertParens: false,
};

const ast = estreeToBabel(cherow.parse(`
    (a = b)
`), options);

traverse({
    AssignmentExpression(path) {
        console.log(path.parentPath.type);
        // output
        'ParenthesizedExpression';
    },
});

License

MIT

Current Tags

  • 12.0.0                                ...           latest (3 months ago)

64 Versions

  • 12.0.0                                ...           3 months ago
  • 11.1.0                                ...           7 months ago
  • 11.0.3                                ...           10 months ago
  • 11.0.2                                ...           a year ago
  • 11.0.1                                ...           a year ago
  • 11.0.0                                ...           a year ago
  • 10.5.0                                ...           a year ago
  • 10.4.0                                ...           a year ago
  • 10.3.0                                ...           a year ago
  • 10.2.0                                ...           a year ago
  • 10.1.0                                ...           a year ago
  • 10.0.1                                ...           a year ago
  • 10.0.0                                ...           a year ago
  • 9.1.0                                ...           2 years ago
  • 9.0.0                                ...           2 years ago
  • 8.1.1                                ...           2 years ago
  • 8.1.0                                ...           2 years ago
  • 8.0.0                                ...           3 years ago
  • 7.0.0                                ...           3 years ago
  • 6.0.0                                ...           3 years ago
  • 5.2.0                                ...           3 years ago
  • 5.1.0                                ...           3 years ago
  • 5.0.1                                ...           4 years ago
  • 5.0.0                                ...           4 years ago
  • 4.9.0                                ...           4 years ago
  • 4.8.0                                ...           4 years ago
  • 4.7.0                                ...           4 years ago
  • 4.6.0                                ...           4 years ago
  • 4.5.0                                ...           4 years ago
  • 4.4.0                                ...           4 years ago
  • 4.3.0                                ...           5 years ago
  • 4.2.0                                ...           5 years ago
  • 4.1.1                                ...           5 years ago
  • 4.1.0                                ...           5 years ago
  • 4.0.2                                ...           5 years ago
  • 4.0.1                                ...           5 years ago
  • 4.0.0                                ...           5 years ago
  • 3.2.1                                ...           5 years ago
  • 3.2.0                                ...           5 years ago
  • 3.1.1                                ...           5 years ago
  • 3.1.0                                ...           5 years ago
  • 3.0.1                                ...           5 years ago
  • 3.0.0                                ...           6 years ago
  • 2.1.0                                ...           7 years ago
  • 2.0.5                                ...           7 years ago
  • 2.0.4                                ...           7 years ago
  • 2.0.3                                ...           7 years ago
  • 2.0.2                                ...           7 years ago
  • 2.0.1                                ...           7 years ago
  • 2.0.0                                ...           7 years ago
  • 1.8.2                                ...           7 years ago
  • 1.8.1                                ...           7 years ago
  • 1.8.0                                ...           7 years ago
  • 1.7.0                                ...           7 years ago
  • 1.6.0                                ...           7 years ago
  • 1.5.0                                ...           7 years ago
  • 1.4.2                                ...           7 years ago
  • 1.4.1                                ...           7 years ago
  • 1.4.0                                ...           7 years ago
  • 1.3.0                                ...           7 years ago
  • 1.2.0                                ...           7 years ago
  • 1.1.0                                ...           7 years ago
  • 1.0.1                                ...           7 years ago
  • 1.0.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 13
Last Day 0
Last Week 13
Last Month 1
Dependencies (1)
Dev Dependencies (16)

Copyright 2013 - present © cnpmjs.org | Home |