#[repr(C)]pub struct Identifier<'gc> {
pub metadata: NodeMetadata<'gc>,
pub name: Cell<NodeLabel>,
pub type_annotation: Option<&'gc Node<'gc>>,
pub optional: Cell<bool>,
pub unresolvable: Cell<bool>,
pub decl_state: Cell<u8>,
pub decl: Cell<Option<SemaId>>,
}Expand description
The Identifier AST node.
Fields§
§metadata: NodeMetadata<'gc>Source range, debug location, paren count, and node id.
name: Cell<NodeLabel>ESTree name property.
type_annotation: Option<&'gc Node<'gc>>ESTree typeAnnotation property.
optional: Cell<bool>ESTree optional property.
unresolvable: Cell<bool>Sema: unresolvable because of an enclosing eval or with.
decl_state: Cell<u8>Sema: how to read decl — the BitHave* bits of ESTree.h’s
IdentifierDecoration.
decl: Cell<Option<SemaId>>Sema: the declaration this identifier resolves to; None until a
resolution is recorded.
Implementations§
Source§impl<'gc> Identifier<'gc>
impl<'gc> Identifier<'gc>
Sourcepub fn new(
metadata: NodeMetadata<'gc>,
name: NodeLabel,
type_annotation: Option<&'gc Node<'gc>>,
optional: bool,
) -> Self
pub fn new( metadata: NodeMetadata<'gc>, name: NodeLabel, type_annotation: Option<&'gc Node<'gc>>, optional: bool, ) -> Self
Build Identifier from its metadata and ESTree.def fields.
Decoration fields start at their defaults.
Sourcepub fn name_str<'a>(&self, gc: &'a GCLock<'_, '_>) -> &'a str
pub fn name_str<'a>(&self, gc: &'a GCLock<'_, '_>) -> &'a str
The name label as UTF-8 text.
Label fields hold identifier names, operators, keyword-like kinds and raw source spans. An identifier cannot contain an unpaired surrogate — the lexer rejects one with a dedicated diagnostic — and the remaining labels are literal source text, so in practice the bytes are already valid UTF-8 and this borrows them directly, allocating nothing.
A label that is nevertheless unrepresentable, which realistically means
a hand-built AST rather than a parsed one, has each unpaired surrogate
rendered as a single U+FFFD instead of being reported. Only an unpaired
surrogate is affected: a WTF-8 surrogate pair is folded back into the
character it encodes, so a "😀" label comes out intact.
Use GCLock::bytes for the exact
bytes, or
GCLock::try_bytes_str to
detect the substitution. The returned &str borrows from gc, not from
self.