Skip to content

coderaiser/estree-to-babel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Estree-to-babel NPM version Dependency Status Build Status Coverage Status

Convert estree compatable 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 called ObjectProperty
  • FunctionExpression of a Property located in ObjectMethod node.
  • 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 const f = ({a}) => a;
`));

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

License

MIT