Estree-to-babel [![NPM version][NPMIMGURL]][NPMURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]
January 7, 2026 ยท View on GitHub
Convert ESTree-compatible JavaScript AST to Babel AST.
To use parsers like:
With babel tools like:
@babel/traverse@babel/types- etc...
The thing is @babel/parser has a little differences with estree standard:
PropertyofObjectExpressionandObjectPatterncalledObjectProperty;FunctionExpressionof aPropertylocated inObjectMethodnode;Filenode;StringLiteral,NumericLiteral,NullLiteral,RegExpLiteral,BooleanLiteralinstead ofLiteral;ClassMethodinstead ofMethodDefinition;ClassPrivateMethod;ClassPrivateNamestores name asIdentifierinidfield;ClassPrivatePropertyinstead ofFieldDefinition;OptionalMemberExpressionandOptionalCallExpressioninstead ofChainExpression;ImportDeclarationandExportNamedDeclarationhasattributes;JSXTexthasextrafield;extra.parenthesized=trueinstead ofParenthesizedExpression;- etc...
Also @babel/parser has differences with typescript-estree:
ClassPrivatePropertyinstead ofPropertyDefinitionwhenkey.type=PrivateName;ClassePropertyinstead ofPropertyDefinitionwhenkey.type=Identifier;PrivateNameinstead ofPrivateIdentifier;TSQualifiedNameinstead ofMemberExpressioninTSInterfaceHeritage;TSDeclaredMethodwithabstract=trueinstead ofTSAbstractMethodDefinition;extra.parenthesized=trueinstead ofTSParenthesizedType;- 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