Skip to main content

Module parser

Module parser 

Source
Expand description

JavaScript parser: token stream → AST.

Recursive descent with precedence climbing for binary operators. Automatic Semicolon Insertion is applied at statement boundaries using the newline_before flag the lexer records on every token. Arrow functions are detected at assignment level by looking ahead for => after a parameter list. Template-literal ${...} fields are re-parsed here from the raw source the lexer captured.

Functions§

note_error_span
Record a SyntaxError found after parsing — an early error such as a redeclaration — at the source span [pos, end), for take_error_pos.
parse
Parse a complete JS program into a statement list. Inline rust { ... } FFI blocks are desugared to __rust_compile(...) calls before lexing.
parse_eval
Parse the source text of an eval / vm script. Identical to parse except that super is accepted at the top level when allow_super says the code runs inside a method (a direct eval there may use it).
parse_module
Parse src with the Module goal (ECMA-262 16.2.1): the code is strict, await is an operator at the top level, return there is an error, and the top level may hold import/export declarations. A hashbang line is a comment only at the very start of the text.
take_error_end
One past the last character V8 underlines for that SyntaxError — the end of the offending token (0: underline the one character at the position). Taken by host::note_syntax_error alongside take_error_pos.
take_error_pos
The Pos of the token the last failed parse / parse_module stopped at (0: none, or none since the last call), which is where V8 puts a SyntaxError’s caret.