Module ecmascript::ast[][src]

This module contains type definitions for the Abstract Syntax elements that make up the ECMAScript language.

These types have been translated from the estree spec.

The macros build_ast and match_ast are meant to be the public API of this module as they abstract away the types in such a way so that the user of the library feels as if they are working with source text almost directly.

Structs

BooleanLiteral

BooleanLiteral is the syntax element for true and false. Reference

Identifier

Id is an identifier in the ecmascript language. eg. var foo = {}; foo is the identifier. Reference.

NullLiteral

NullLiteral is the syntax element for null. Reference

NumericLiteral

NumericLiteral is the syntax element for numbers. The parser will convert the string values into an f64 for the sake of simplicity. Reference

Position

Position is a line and a column. The line is 1 indexed, and column is 0 indexed.

Property

An object property is a tuple of a key, value, and a tag representing what kind of property it is.

RegExpLiteral

RegExpLiteral is the syntax element of a regular expression. eg. /abc[123]/gi Reference

SourceLocation

A SourceLocation is where the node starts, and ends.

StringLiteral

StringLiteral is a syntax element with quotes (single or double). eg. 'my string literal' or "my other string literal" Reference

TemplateElement

TemplateElement is any text between interpolated expressions inside a template literal. eg. abc ${} \u{2028} "abc " and " \u{2028}" would be the TemplateElements for this template literal. Reference

VariableDeclarator

VariableDeclarator is a struct that has a pattern and an initializer. The pattern can be an identifier, or an object destructuring pattern or array destructuring pattern.

Enums

ArrowFunctionBody

This represents what the arrow function body can be

AssignmentOperator

Assignment operators are ones that signify a chnage to the left hand side of the expression.

BinaryOperator

All the operators that have 2 arguments are merged into one big enum here for simplicity sake.

Expression

Expression is an enumeration of all possible expressions merged into one big enum. This also includes language extensions, such as JSX.

ExpressionListItem

A pattern is any way you can destructure an object or array.

FunctionBodyStatement

A function body is either a statement or a directive.

JsxAttribute

A JSX attribute is either a simple key={value} attribute, or a spread of an object containing multiple attributes.

Literal

This represents the Literal production of the PrimaryExpression rule. Reference

LogicalOperator

All the operators that have 2 arguments are merged into one big enum here for simplicity sake.

ObjectExpressionProperty

An object expression property can be a property or a spread property.

ObjectPatternProperty

This is a restricted version of a Property that only allows patterns as the value.

Pattern

A pattern is any way you can destructure an object or array.

Program

This is the main entry point to the syntax tree. A program is a list of statements, and statements include declarations.

PropertyKind

An object property can be a getter, setter, or basic initializer.

ReferenceError

ReferenceError represents a failure when trying to convert an expression into a pattern.

SourceType

This enum represents whether or not the source code contains an ECMAScript module. An ECMAScript module can have import and export declarations in it, and has some other subtle behaviour differences.

SpreadElement

A spread element is something that be spread, eg. an array or an object.

Statement

A statement is either a declaration (var, const, let, function, export) or an instruction to the interpreter to evaluate an expression. For the sake of simplicity, declarations will get merged into this struct as well.

Super

This is a super call or object.

SuperExpression

This is a super call or object.

TemplateLiteralElement

A template literal element can either be the string between backticks and ${ or the expression between ${ and }. This is easier than trying to re-construct the order.

UnaryOperator

These operators take 1 operand, and are a prefix of the operand. Reference

UpdateOperator

These operators take 1 operand, update the operands mathematical value in the background, then return an updated version of the operand.

VariableDeclarationKind

This represents the different kinds of declarations that can occur, eg. let, const or var.

VariableDeclaratorInit

This enum is internal, to maintain estree compatibility Alternatively, we could write a custom serializer / deserializer to map "null" to an Option, but this was easier in the short term.