#[repr(C)]pub struct TypePredicate<'gc> {
pub metadata: NodeMetadata<'gc>,
pub parameter_name: &'gc Node<'gc>,
pub type_annotation: Option<&'gc Node<'gc>>,
pub kind: Cell<NodeString>,
}Expand description
The TypePredicate AST node.
Fields§
§metadata: NodeMetadata<'gc>Source range, debug location, paren count, and node id.
parameter_name: &'gc Node<'gc>ESTree parameterName property.
type_annotation: Option<&'gc Node<'gc>>ESTree typeAnnotation property.
kind: Cell<NodeString>ESTree kind property.
Implementations§
Source§impl<'gc> TypePredicate<'gc>
impl<'gc> TypePredicate<'gc>
Sourcepub fn new(
metadata: NodeMetadata<'gc>,
parameter_name: &'gc Node<'gc>,
type_annotation: Option<&'gc Node<'gc>>,
kind: NodeString,
) -> Self
pub fn new( metadata: NodeMetadata<'gc>, parameter_name: &'gc Node<'gc>, type_annotation: Option<&'gc Node<'gc>>, kind: NodeString, ) -> Self
Build TypePredicate from its metadata and ESTree.def fields.
Sourcepub fn try_kind_str<'a>(&self, gc: &'a GCLock<'_, '_>) -> Option<&'a str>
pub fn try_kind_str<'a>(&self, gc: &'a GCLock<'_, '_>) -> Option<&'a str>
The kind string value as UTF-8, or None if it has no UTF-8 form.
A JS string value is a sequence of UTF-16 code units, so it may legally
contain an unpaired surrogate ("\uD800" parses, and is not an
error). That, and only that, is what None reports: the value is
intact, it simply cannot be spelled in UTF-8. Read it losslessly with
GCLock::bytes.
Only an unpaired surrogate is unrepresentable. A WTF-8 surrogate
pair is not: the lexer interns an astral character in surrogate-pair
form, and it is folded back into the character it encodes, so a "😀"
literal yields Some("😀"), not None.
There is deliberately no plain kind_str: an unrepresentable identifier
means something is broken, but an unrepresentable string literal is
legal JS, and a codegen or refactoring tool that let U+FFFD be
substituted here would silently rewrite the user’s program. Reach for
Self::kind_str_lossy only when a best-effort rendering is what you
want.
Valid UTF-8 is borrowed from the atom’s own bytes and allocates nothing;
folding a surrogate pair allocates once per atom, cached in the context.
The returned &str borrows from gc, not from self.
Sourcepub fn kind_str_lossy<'a>(&self, gc: &'a GCLock<'_, '_>) -> &'a str
pub fn kind_str_lossy<'a>(&self, gc: &'a GCLock<'_, '_>) -> &'a str
The kind string value as UTF-8, substituting U+FFFD for anything
unrepresentable.
This is lossy. A JS string value may legally contain an unpaired
surrogate ("\uD800" parses), which has no UTF-8 form; each one becomes
exactly one U+FFFD here. Do not use this to re-emit source: a codegen or
refactoring tool would silently rewrite the user’s program.
Only an unpaired surrogate is unrepresentable. A WTF-8 surrogate
pair is not: the lexer interns an astral character in surrogate-pair
form, and it is folded back into the character it encodes, so a "😀"
literal comes out intact.
Use Self::try_kind_str or
GCLock::bytes when the exact value
matters. The returned &str borrows from gc, not from self.