1.0.0 • Published 2 years ago
@omegion1npm/debitis-eveniet-error v1.0.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:
- Propertyof- ObjectExpressionand- ObjectPatterncalled- ObjectProperty;
- FunctionExpressionof a- Propertylocated in- ObjectMethodnode;
- Filenode;
- StringLiteral,- NumericLiteral,- NullLiteral,- RegExpLiteral,- BooleanLiteralinstead of- Literal;
- ClassMethodinstead of- MethodDefinition;
- ClassPrivateMethod;
- ClassPrivateNamestores name as- Identifierin- idfield;
- ClassPrivatePropertyinstead of- FieldDefinition;
- OptionalMemberExpressionand- OptionalCallExpressioninstead of- ChainExpression;
- ImportDeclarationand- ExportNamedDeclarationhas- attributes;
- etc...
Also @babel/parser has differences with typescript-estree:
- TSExpressionWithTypeArgumentsinstead of- TSClassImplements;
- ClassPrivatePropertyinstead of- PropertyDefinitionwhen- key.type=PrivateName;
- ClassePropertyinstead of- PropertyDefinitionwhen- key.type=Identifier;
- PrivateNameinstead of- PrivateIdentifier;
- TSInterfaceHeritageinstead of- TSExpressionWithTypeArguments;
- TSQualifiedNameinstead of- MemberExpressionin- TSInterfaceHeritage;
- TSDeclaredMethodwith- abstract=trueinstead of- TSAbstractMethodDefinition;
- etc...
@omegion1npm/debitis-eveniet-error aims to smooth this differences.
Install
npm i @omegion1npm/debitis-eveniet-errorExample
const cherow = require('cherow');
const toBabel = require('@omegion1npm/debitis-eveniet-error');
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
1.0.0
2 years ago