pub struct Ast {Show 16 fields
pub top_level: Vec<StmtId>,
pub pattern_origins: BTreeMap<ExprId, PatternOrigin>,
pub tuple_pattern_sources: BTreeSet<ExprId>,
pub tuple_pattern_pad_defaults: BTreeMap<ExprId, Vec<Option<ExprId>>>,
pub object_pattern_pad_defaults: BTreeMap<ExprId, Vec<(String, ExprId)>>,
pub object_pattern_sources: BTreeMap<ExprId, BTreeMap<String, Option<ExprId>>>,
pub tuple_pattern_defaults: BTreeMap<ExprId, BTreeMap<usize, ExprId>>,
pub const_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>,
pub unparsed_main: bool,
/* 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).
tuple_pattern_pad_defaults: BTreeMap<ExprId, Vec<Option<ExprId>>>For a parameter’s tuple literal default shorter than its pattern, the
defaults of the slots past its end (None for a hole). TypeScript pads
the default’s type with an optional element for each, so a caller may
pass them.
object_pattern_pad_defaults: BTreeMap<ExprId, Vec<(String, ExprId)>>For a parameter’s object literal default, the properties its pattern
gives defaults that the literal lacks, with those defaults:
{ a = 1 } = {}. TypeScript adds each to the default’s type as an
optional property, so a caller may pass it.
object_pattern_sources: BTreeMap<ExprId, BTreeMap<String, Option<ExprId>>>Unannotated object literals an object pattern takes apart, with the
properties the pattern gives defaults and their defaults:
{ a, b = 0 } = { a: 1, b: 2 }. TypeScript types such a literal from
the pattern, so those properties are optional in its type (populated by
lower_patterns). A default that may read a name the pattern binds is
None: it can’t be typed ahead of the pattern as the property’s context.
tuple_pattern_defaults: BTreeMap<ExprId, BTreeMap<usize, ExprId>>For a tuple pattern source, the defaults of the pattern’s slots the
literal fills, by index: [a = 1] = [2].
const_pattern_sources: BTreeSet<ExprId>Pattern sources a const declaration takes apart, whose defaults keep
their literal types as the context of the literal’s properties.
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, such as an implicit
initializer. 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.
unparsed_main: boolA top-level function main the parser reported and dropped, so the
program is not also told it has no main.
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>
Sourcepub fn exprs_within(&self, span: Span) -> impl Iterator<Item = &Expr>
pub fn exprs_within(&self, span: Span) -> impl Iterator<Item = &Expr>
Every expression whose span lies within span, nested function bodies
included.
Sourcepub fn try_peel_parens(&self, id: ExprId) -> Result<ExprId, ArenaError>
pub fn try_peel_parens(&self, id: ExprId) -> Result<ExprId, ArenaError>
The expression id is through any parentheses around it.
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.