#[non_exhaustive]pub struct ParserReturn<'a> {
pub program: Program<'a>,
pub module_record: ModuleRecord<'a>,
pub diagnostics: Diagnostics,
pub irregular_whitespaces: Box<[Span]>,
pub tokens: ArenaVec<'a, Token>,
pub fatal_error: bool,
pub is_flow_language: bool,
}Expand description
Return value of Parser::parse consisting of AST, errors and comments
§AST Validity
program will always contain a structurally valid AST, even if there are syntax errors.
However, the AST may be semantically invalid. To ensure a valid AST,
- Check that
diagnosticsis empty - Run semantic analysis with syntax error checking enabled
§Errors
Oxc’s Parser is able to recover from some syntax errors and continue parsing.
When this happens:
diagnosticswill be non-emptyprogramwill contain a full ASTfatal_errorwill be false
When the parser cannot recover, it will abort and terminate parsing early.
program will be empty and fatal_error will be true.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.program: Program<'a>The parsed AST.
Will be empty (e.g. no statements, directives, etc) if the parser encountered a fatal error.
Every node has a unique node ID within this AST. Program has ID zero; other IDs follow construction order and may have gaps from discarded nodes. Semantic analysis replaces these with its own dense node IDs.
§Validity
It is possible for the AST to be present and semantically invalid. This will happen if
- The
Parserencounters a recoverable syntax error - The logic for checking the violation is in the semantic analyzer
To ensure a valid AST, check that diagnostics is empty. Then, run
semantic analysis with syntax error checking enabled.
module_record: ModuleRecord<'a>§diagnostics: DiagnosticsSyntax errors encountered while parsing.
This list is not comprehensive. Oxc offloads more-expensive checks to semantic
analysis, which can be enabled using
SemanticBuilder::with_check_syntax_error.
irregular_whitespaces: Box<[Span]>Irregular whitespaces for Oxlint
tokens: ArenaVec<'a, Token>Lexed tokens in source order.
Tokens are only collected when tokens are enabled in ParserConfig.
fatal_error: boolWhether the parser encountered a fatal error and terminated early.
If false, either parsing was successful, or parsing was able to recover from a syntax error.
diagnostics may still contain errors, indicating that the program is not syntactically valid,
but parser was able to recover enough to produce an AST.
If true, parser was unable to parse the source.
program will be empty and diagnostics will contain at least one error.
is_flow_language: boolWhether the file is flow.