pub struct Ast {
pub top_level: Vec<StmtId>,
pub pattern_origins: BTreeMap<ExprId, PatternOrigin>,
pub tuple_pattern_sources: BTreeSet<ExprId>,
pub parameter_bindings: HashMap<Span, Vec<StmtId>>,
pub for_of_pattern_bindings: BTreeMap<StmtId, Vec<Ident>>,
pub for_pattern_init_bindings: BTreeMap<StmtId, Vec<Ident>>,
pub exported_decls: Vec<ExportedDecl>,
pub implicit_initializers: BTreeSet<ExprId>,
pub synthetic_undefined: BTreeSet<ExprId>,
pub binding_defaults: BTreeMap<ExprId, BindingDefault>,
/* private fields */
}Fields§
§top_level: Vec<StmtId>§pattern_origins: BTreeMap<ExprId, PatternOrigin>Maps synthesized IndexAccess IDs → their source pattern (populated by lower_patterns).
BTreeMap is precautionary: the compiler only ever looks entries up by ExprId, and
the parser snapshots that render Ast’s Debug all run before lower_patterns
populates this, so order is unobserved today. An ordered map keeps any future walk —
or post-lowering snapshot — independent of the hash seed.
tuple_pattern_sources: BTreeSet<ExprId>Array literals that an array pattern destructures directly, as in
let [a, b] = [1, "s"]. TypeScript types such a literal as a tuple from
the pattern, so each name gets its element’s type and a pattern longer
than the literal is a compile error (populated by lower_patterns).
parameter_bindings: HashMap<Span, Vec<StmtId>>Pattern decomposition statements, run immediately after their parameter initializes.
for_of_pattern_bindings: BTreeMap<StmtId, Vec<Ident>>Source names in lowered for-of heads, whose TDZ includes the iterable.
for_pattern_init_bindings: BTreeMap<StmtId, Vec<Ident>>The let names a destructuring for initializer declared, by the
lowered for, whose initializer now precedes it (populated by
lower_patterns).
exported_decls: Vec<ExportedDecl>Top-level declarations carrying a leading export (Form 1).
implicit_initializers: BTreeSet<ExprId>The undefined a typed let x: T; starts with, synthesized by the parser.
synthetic_undefined: BTreeSet<ExprId>Every undefined the compiler writes itself: implicit initializers and
the padding of a destructured tuple. Each reads the value undefined,
even where a binding named undefined is in scope.
binding_defaults: BTreeMap<ExprId, BindingDefault>Destructuring defaults, keyed by the ternary lower_patterns makes of each.
Implementations§
Source§impl Ast
impl Ast
pub fn validate_source( &self, source: &str, file: FileId, ) -> Result<(), SourceError>
pub fn new() -> Self
Sourcepub fn try_push_expr(&mut self, expr: Expr) -> Result<ExprId, ArenaError>
pub fn try_push_expr(&mut self, expr: Expr) -> Result<ExprId, ArenaError>
Checked allocation; failure leaves the arena unchanged.
Sourcepub fn try_push_stmt(&mut self, stmt: Stmt) -> Result<StmtId, ArenaError>
pub fn try_push_stmt(&mut self, stmt: Stmt) -> Result<StmtId, ArenaError>
Checked allocation; failure leaves the arena unchanged.
pub fn try_expr(&self, id: ExprId) -> Result<&Expr, ArenaError>
pub fn try_stmt(&self, id: StmtId) -> Result<&Stmt, ArenaError>
pub fn try_expr_mut(&mut self, id: ExprId) -> Result<&mut Expr, ArenaError>
pub fn try_stmt_mut(&mut self, id: StmtId) -> Result<&mut Stmt, ArenaError>
Sourcepub fn expr_ids(
&self,
) -> Result<impl DoubleEndedIterator<Item = ExprId> + use<>, ArenaError>
pub fn expr_ids( &self, ) -> Result<impl DoubleEndedIterator<Item = ExprId> + use<>, ArenaError>
Snapshot of allocated expression IDs, usable while appending new nodes.
Sourcepub fn stmt_ids(
&self,
) -> Result<impl DoubleEndedIterator<Item = StmtId> + use<>, ArenaError>
pub fn stmt_ids( &self, ) -> Result<impl DoubleEndedIterator<Item = StmtId> + use<>, ArenaError>
Snapshot of allocated statement IDs, usable while appending new nodes.