1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use rustc_hash::{FxHashMap, FxHashSet};
use oxc_ast::ast::AssignmentExpression;
use oxc_span::Span;
use crate::cursor::ParserCheckpoint;
pub struct ParserState<'a> {
pub not_parenthesized_arrow: FxHashSet<u32>,
/// Temporary storage for `CoverInitializedName` `({ foo = bar })`.
/// Keyed by `ObjectProperty`'s span.start.
pub cover_initialized_name: FxHashMap<u32, AssignmentExpression<'a>>,
/// Trailing comma spans for `ArrayExpression` and `ObjectExpression`.
/// Used for error reporting.
/// Keyed by start span of `ArrayExpression` / `ObjectExpression`.
/// Valued by position of the trailing_comma.
pub trailing_commas: FxHashMap<u32, Span>,
/// Statements that may need reparsing when `sourceType` is `unambiguous`.
///
/// In unambiguous mode, we initially parse top-level `await ...` as
/// `await(...)` (identifier/function call). But if ESM syntax is detected
/// later, we need to reparse these as await expressions.
///
/// Each entry contains: (statement_index, checkpoint_before_statement)
pub potential_await_reparse: Vec<(usize, ParserCheckpoint<'a>)>,
/// Flag to track if an `await` identifier was encountered during statement parsing.
/// Used to determine if a statement needs to be stored for potential reparsing
/// in unambiguous mode.
pub encountered_await_identifier: bool,
}
impl ParserState<'_> {
pub fn new() -> Self {
Self {
not_parenthesized_arrow: FxHashSet::default(),
cover_initialized_name: FxHashMap::default(),
trailing_commas: FxHashMap::default(),
potential_await_reparse: Vec::new(),
encountered_await_identifier: false,
}
}
}