This document specifies the extensions to the core ESTree AST types to support the ES2015 grammar.
extend interface Program {
sourceType: "script" | "module";
body: [ Statement | ModuleDeclaration ];
}
Parsers must specify sourceType
as "module"
if the source has been parsed as an ES6 module. Otherwise, sourceType
must be "script"
.
extend interface Function {
generator: boolean;
}
interface ForOfStatement <: ForInStatement {
type: "ForOfStatement";
}
extend interface VariableDeclaration {
kind: "var" | "let" | "const";
}
interface Super <: Node {
type: "Super";
}
extend interface CallExpression {
callee: Expression | Super;
}
extend interface MemberExpression {
object: Expression | Super;
}
A super
pseudo-expression.
interface SpreadElement <: Node {
type: "SpreadElement";
argument: Expression;
}
extend interface ArrayExpression {
elements: [ Expression | SpreadElement | null ];
}
extend interface CallExpression {
arguments: [ Expression | SpreadElement ];
}
Spread expression, e.g., [head, ...iter, tail]
, f(head, ...iter, ...tail)
.
FIXME: This describes the Esprima and Acorn behaviors, which is not currently aligned with the SpiderMonkey behavior.
extend interface AssignmentExpression {
left: Pattern;
}
Note that pre-ES6 code was allowed to pass references around and so left
was much more liberal; an implementation might choose to continue using old definition if it needs to support such legacy code.
extend interface Property {
key: Expression;
method: boolean;
shorthand: boolean;
computed: boolean;
}
interface ArrowFunctionExpression <: Function, Expression {
type: "ArrowFunctionExpression";
body: BlockStatement | Expression;
expression: boolean;
}
A fat arrow function expression, e.g., let foo = (bar) => { /* body */ }
.
interface YieldExpression <: Expression {
type: "YieldExpression";
argument: Expression | null;
delegate: boolean;
}
A yield
expression.
interface TemplateLiteral <: Expression {
type: "TemplateLiteral";
quasis: [ TemplateElement ];
expressions: [ Expression ];
}
interface TaggedTemplateExpression <: Expression {
type: "TaggedTemplateExpression";
tag: Expression;
quasi: TemplateLiteral;
}
interface TemplateElement <: Node {
type: "TemplateElement";
tail: boolean;
value: {
cooked: string;
raw: string;
};
}
interface AssignmentProperty <: Property {
type: "Property"; // inherited
value: Pattern;
kind: "init";
method: false;
}
interface ObjectPattern <: Pattern {
type: "ObjectPattern";
properties: [ AssignmentProperty ];
}
interface ArrayPattern <: Pattern {
type: "ArrayPattern";
elements: [ Pattern | null ];
}
interface RestElement <: Pattern {
type: "RestElement";
argument: Pattern;
}
interface AssignmentPattern <: Pattern {
type: "AssignmentPattern";
left: Pattern;
right: Expression;
}
interface Class <: Node {
id: Identifier | null;
superClass: Expression | null;
body: ClassBody;
}
interface ClassBody <: Node {
type: "ClassBody";
body: [ MethodDefinition ];
}
interface MethodDefinition <: Node {
type: "MethodDefinition";
key: Expression;
value: FunctionExpression;
kind: "constructor" | "method" | "get" | "set";
computed: boolean;
static: boolean;
}
interface ClassDeclaration <: Class, Declaration {
type: "ClassDeclaration";
id: Identifier;
}
interface ClassExpression <: Class, Expression {
type: "ClassExpression";
}
interface MetaProperty <: Expression {
type: "MetaProperty";
meta: Identifier;
property: Identifier;
}
interface ModuleDeclaration <: Node { }
A module import
or export
declaration.
interface ModuleSpecifier <: Node {
local: Identifier;
}
A specifier in an import or export declaration.
interface ImportDeclaration <: ModuleDeclaration {
type: "ImportDeclaration";
specifiers: [ ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier ];
source: Literal;
}
An import declaration, e.g., import foo from "mod";
.
interface ImportSpecifier <: ModuleSpecifier {
type: "ImportSpecifier";
imported: Identifier;
}
An imported variable binding, e.g., {foo}
in import {foo} from "mod"
or {foo as bar}
in import {foo as bar} from "mod"
. The imported
field refers to the name of the export imported from the module. The local
field refers to the binding imported into the local module scope. If it is a basic named import, such as in import {foo} from "mod"
, both imported
and local
are equivalent Identifier
nodes; in this case an Identifier
node representing foo
. If it is an aliased import, such as in import {foo as bar} from "mod"
, the imported
field is an Identifier
node representing foo
, and the local
field is an Identifier
node representing bar
.
interface ImportDefaultSpecifier <: ModuleSpecifier {
type: "ImportDefaultSpecifier";
}
A default import specifier, e.g., foo
in import foo from "mod.js"
.
interface ImportNamespaceSpecifier <: ModuleSpecifier {
type: "ImportNamespaceSpecifier";
}
A namespace import specifier, e.g., * as foo
in import * as foo from "mod.js"
.
interface ExportNamedDeclaration <: ModuleDeclaration {
type: "ExportNamedDeclaration";
declaration: Declaration | null;
specifiers: [ ExportSpecifier ];
source: Literal | null;
}
An export named declaration, e.g., export {foo, bar};
, export {foo} from "mod";
or export var foo = 1;
.
Note: Having declaration
populated with non-empty specifiers
or non-null source
results in an invalid state.
interface ExportSpecifier <: ModuleSpecifier {
type: "ExportSpecifier";
exported: Identifier;
}
An exported variable binding, e.g., {foo}
in export {foo}
or {bar as foo}
in export {bar as foo}
. The exported
field refers to the name exported in the module. The local
field refers to the binding into the local module scope. If it is a basic named export, such as in export {foo}
, both exported
and local
are equivalent Identifier
nodes; in this case an Identifier
node representing foo
. If it is an aliased export, such as in export {bar as foo}
, the exported
field is an Identifier
node representing foo
, and the local
field is an Identifier
node representing bar
.
interface ExportDefaultDeclaration <: ModuleDeclaration {
type: "ExportDefaultDeclaration";
declaration: Declaration | Expression;
}
An export default declaration, e.g., export default function () {};
or export default 1;
.
interface ExportAllDeclaration <: ModuleDeclaration {
type: "ExportAllDeclaration";
source: Literal;
}
An export batch declaration, e.g., export * from "mod";
.