This document specifies the extensions to the core ESTree AST types to support the ES2020 grammar.
extend interface Literal <: Expression {
type: "Literal";
value: string | boolean | null | number | RegExp | bigint;
}valueproperty can be aBigIntvalue to representBigIntliterals such as100n.
interface BigIntLiteral <: Literal {
bigint: string;
}bigintproperty is the string representation of theBigIntvalue. It must contain only decimal digits and not include numeric separators (_) or the suffixn.- In environments that don't support
BigIntvalues,valueproperty will benullas theBigIntvalue can't be represented natively.
interface ChainExpression <: Expression {
type: "ChainExpression";
expression: ChainElement;
}
interface ChainElement <: Node {
optional: boolean;
}
extend interface CallExpression <: ChainElement {}
extend interface MemberExpression <: ChainElement {}- The
ChainExpressionnode is the root of optional chaining. - The
ChainExpressionnode contains one or moreChainElementnodes that areoptional:true. On the other hand,ChainElementnodes that areoptional:truebelong to aChainExpressionnode. - For backward compatibility, if all
ChainElementnodes of a chain areoptional:false, theChainExpressionnode isn't inserted as the root of the chain. - Evaluation:
- The
ChainExpressionnode is evaluated to the result of theexpressionproperty's node. - If the
callee|objectproperty is evaluated to nullish and theoptionalproperty istrue, then the node and ancestor nodes are skipped until the closestChainExpressionnode, and the result of theChainExpressionnode becomesundefined.
- The
For Examples:
// obj.aaa?.bbb
{
"type": "ChainExpression",
"expression": {
"type": "MemberExpression",
"optional": true,
"object": {
"type": "MemberExpression",
"optional": false,
"object": { "type": "Identifier", "name": "obj" },
"property": { "type": "Identifier", "name": "aaa" }
},
"property": { "type": "Identifier", "name": "bbb" }
}
}// obj?.aaa.bbb
{
"type": "ChainExpression",
"expression": {
"type": "MemberExpression",
"optional": false,
"object": {
"type": "MemberExpression",
"optional": true,
"object": { "type": "Identifier", "name": "obj" },
"property": { "type": "Identifier", "name": "aaa" }
},
"property": { "type": "Identifier", "name": "bbb" }
}
}// obj?.aaa?.bbb
{
"type": "ChainExpression",
"expression": {
"type": "MemberExpression",
"optional": true,
"object": {
"type": "MemberExpression",
"optional": true,
"object": { "type": "Identifier", "name": "obj" },
"property": { "type": "Identifier", "name": "aaa" }
},
"property": { "type": "Identifier", "name": "bbb" }
}
}// (obj.aaa).bbb
{
"type": "MemberExpression",
"optional": false,
"object": {
"type": "MemberExpression",
"optional": false,
"object": { "type": "Identifier", "name": "obj" },
"property": { "type": "Identifier", "name": "aaa" }
},
"property": { "type": "Identifier", "name": "bbb" }
}// (obj.aaa)?.bbb
{
"type": "ChainExpression",
"expression": {
"type": "MemberExpression",
"optional": true,
"object": {
"type": "MemberExpression",
"optional": false,
"object": { "type": "Identifier", "name": "obj" },
"property": { "type": "Identifier", "name": "aaa" }
},
"property": { "type": "Identifier", "name": "bbb" }
}
}// (obj?.aaa).bbb
{
"type": "MemberExpression",
"optional": false,
"object": {
"type": "ChainExpression",
"expression": {
"type": "MemberExpression",
"optional": true,
"object": { "type": "Identifier", "name": "obj" },
"property": { "type": "Identifier", "name": "aaa" }
}
},
"property": { "type": "Identifier", "name": "bbb" }
}// (obj?.aaa)?.bbb
{
"type": "ChainExpression",
"expression": {
"type": "MemberExpression",
"optional": true,
"object": {
"type": "ChainExpression",
"expression": {
"type": "MemberExpression",
"optional": true,
"object": { "type": "Identifier", "name": "obj" },
"property": { "type": "Identifier", "name": "aaa" }
}
},
"property": { "type": "Identifier", "name": "bbb" }
}
}interface ImportExpression <: Expression {
type: "ImportExpression";
source: Expression;
}ImportExpressionnode represents Dynamic Imports such asimport(source). Thesourceproperty is the importing source as similar to ImportDeclaration node, but it can be an arbitrary expression node.
extend enum LogicalOperator {
"??"
}- The
operatorproperty of theLogicalExpressionnode can be"??"to represent Nullish Coalescing syntax.
Existing MetaProperty node represents import.meta meta property as well.
extend interface ExportAllDeclaration {
exported: Identifier | null;
}The exported property contains an Identifier when a different exported name is specified using as, e.g., export * as foo from "mod";.