Socket
Socket
Sign inDemoInstall

estree-to-babel

Package Overview
Dependencies
1
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    estree-to-babel

convert estree ast to babel


Version published
Weekly downloads
2M
increased by2.47%
Maintainers
1
Install size
2.25 MB
Created
Weekly downloads
 

Readme

Source

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...

estree-to-babel aims to smooth this differences.

Install

npm i estree-to-babel

Example

const cherow = require('cherow');
const toBabel = require('estree-to-babel');
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

Keywords

FAQs

Last updated on 11 Dec 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc