estree-to-babel v10.5.0
Estree-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:
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-babelExample
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:
const cherow = require('cherow');
const toBabel = require('estree-to-babel');
const traverse = require('@babel/traverse').default;
const options = {
convertParens: false,
};
const ast = toBabel(cherow.parse(`
(a = b)
`), options);
traverse({
AssignmentExpression(path) {
console.log(path.parentPath.type);
// output
'ParenthesizedExpression';
},
});License
MIT
9 months ago
9 months ago
9 months ago
9 months ago
10 months ago
12 months ago
12 months ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago