A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/coderaiser/estree-to-babel below:

coderaiser/estree-to-babel: convert estree ast 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:

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

estree-to-babel aims to smooth this differences.

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';
    },
});

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';
    },
});

MIT


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4