Skip to main content

Crate hermes_ast

Crate hermes_ast 

Source
Expand description

Hermes ESTree AST — GC arena (juno-derived) + node model.

The node set in node is generated from include/hermes/AST/ESTree.def with every parse family enabled — Flow, TypeScript, JSX, and the parser’s “cover” grammar nodes — so a single node::Node enum spans all of them.

The pieces a consumer touches:

  • context::Context and context::GCLock — the arena that owns the nodes and the lock through which they are allocated and read.
  • node::Node — one enum arm per node kind, over #[repr(C)] structs whose fields mirror the .def entry: structural children are &'gc references or node_child::NodeLists, everything else is a Cell.
  • visitor::VisitorMut plus Node::visit_children_mut — transforms that rebuild only the spine whose children changed.
  • dump::ESTreeJSONDumper — ESTree JSON matching hermesc -dump-ast -dump-source-location=both byte for byte.

See rust/ARCHITECTURE.md for the design rationale and doc/superpowers/specs/2026-06-03-ast-design.md for the port spec.

Modules§

context
Garbage-collected Storage structures for AST nodes.
dump
Port of lib/AST/ESTreeJSONDumper.cpp. Emits an AST as ESTree JSON — the byte-for-byte differential-oracle surface (the gate lands at Parser time). The per-kind field walk + the "type" name live in the generated node.rs (Node::dump_children / Node::node_type_str); this module is the driver: modes, locations, the raw prop, value emission, and the public entry points.
node
@generated by gen_nodes.py from include/hermes/AST/ESTree.def — DO NOT EDIT. Run python3 rust/crates/ast/gen_nodes.py to regenerate.
node_child
Child/leaf field types and the NodeList for the AST.
visitor
AST traversal.

Structs§

NodeId
Unique, never-reused identity of an AST node within its Context. Assigned by Context::alloc from a monotonic counter (starting at 1); UNASSIGNED (0) only exists on metadata not yet stored in the arena. Consumers outside sema key side tables by NodeId (see the Sema design spec §3.1): unlike raw addresses, ids never alias after arena slot reuse; unlike NodeRc keys, they don’t pin garbage. Insert entries only with the node in hand under GCLock — a stored id may already be dead.
SemaId
Opaque handle to a resolved Sema entity (scope / decl / function info). The AST only stores the raw index in a Cell; the sema crate wraps it in the typed newtypes of its ids module and owns the interpretation.

Traits§

HeapSize
Trait for allowing users to query how much memory a type uses in the heap.