Expand description
The parser: tokens to crate::ast.
A recursive-descent parser with precedence climbing for expressions. It follows the specification’s grammar productions closely, which keeps the early errors next to the code that can detect them.
Two productions need backtracking / reinterpretation, exactly as in an engine:
- arrow functions use the cover grammar.
(starts either a parenthesized expression or a parameter list; the parser speculatively parses a parameter list and commits only if=>follows, otherwise it restores the lexer and parses an expression. letat statement start is a declaration keyword when followed by a binding, otherwise an identifier.
Automatic semicolon insertion is implemented where the grammar allows it
(Stmt terminators, do…while, return/throw restricted productions,
postfix ++/--, async before arrow parameters, yield/await).
Early errors implemented here (not at run time):
with, legacy octal literals/escapes,delete identifier,eval/argumentsas binding or assignment target — strict mode only;superoutside a method,super()outside a derived constructor,new.targetoutside a function;await/yieldused as identifiers where they are reserved;- duplicate
__proto__in an object literal, duplicate private names; break/continuetarget validity,returnoutside a function;??mixed with&&/||without parentheses,-x ** y, assignment to a non-assignable target,newon an optional chain;- duplicate parameter names (always for arrows/methods/non-simple lists).
Not implemented yet (tracked for M1b.2): scope-analysis early errors such as
let x; let x; in the same block, and parameter/var conflicts.
Structs§
- Eval
Context - What the code that called a direct
evalallows its body to use. - Parser
- ECMAScript 2025 parser.
Constants§
- DEFAULT_
MAX_ DEPTH - Default nesting limit.
Functions§
- parse_
eval_ script - Parse
srcas a directevalbody, inheritingnew.targetfrom the caller. - parse_
eval_ script_ in - Parse
srcas a directevalbody with the caller’s privileges. - parse_
expression - Parse
srcas a singleExpression(used by tests and byeval-like entry points that need the expression grammar only). - parse_
module - Parse
srcas aModule. - parse_
script - Parse
srcas aScript. - parse_
script_ strict - Parse
srcas aScriptwhose code is strict from the first token.