-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Another fast ESTree parser is oxc.
https://github.com/web-infra-dev/oxc#-ast-and-parser
However the generated ESTree AST slightly differs:
The Oxc AST differs slightly from the estree AST by removing ambiguous nodes and introducing distinct types.
For example, instead of using a generic estreeIdentifier,
the Oxc AST provides specific types such asBindingIdentifier,IdentifierReference, andIdentifierName.
This clear distinction greatly enhances the development experience by aligning more closely with the ECMAScript specification.
But it would be pretty awesome if it was supported!
The additional distinct types is quite a big change I would think:
OXC ESTree AST
const helloWorld = "Hello World";{
"type": "Program",
"start": 0,
"end": 34,
"sourceType": {
"language": {
"typeScript": {
"isDefinitionFile": false
}
},
"moduleKind": "module",
"variant": "standard",
"alwaysStrict": false
},
"directives": [],
"hashbang": null,
"body": [{
"type": "VariableDeclaration",
"start": 0,
"end": 33,
"kind": "const",
"declarations": [{
"type": "VariableDeclarator",
"start": 6,
"end": 32,
"id": {
"type": "BindingPattern",
"kind": {
"type": "BindingIdentifier",
"start": 6,
"end": 16,
"name": "helloWorld"
},
"typeAnnotation": null,
"optional": false
},
"init": {
"type": "StringLiteral",
"start": 19,
"end": 32,
"value": "Hello World"
},
"definite": false
}],
"modifiers": null
}]
} Regular ESTree AST
{
"type": "Program",
"start": 0,
"end": 33,
"body": [
{
"type": "VariableDeclaration",
"start": 0,
"end": 33,
"declarations": [
{
"type": "VariableDeclarator",
"start": 6,
"end": 32,
"id": {
"type": "Identifier",
"start": 6,
"end": 16,
"name": "helloWorld"
},
"init": {
"type": "Literal",
"start": 19,
"end": 32,
"value": "Hello World",
"raw": "\"Hello World\""
}
}
],
"kind": "const"
}
],
"sourceType": "module"
}I haven't found another library for traversing a OXC compatible ESTree in Javascript yet.
The node types are available in https://github.com/web-infra-dev/oxc/tree/main/crates/oxc_ast/src