Struct swc_ecma_ast::Ident
source · [−]Expand description
A complete identifier with span.
Identifier of swc consists of two parts. The first one is symbol, which is stored using an interned string, JsWord . The second one is SyntaxContext, which can be used to distinguish identifier with same symbol.
Let me explain this with an example.
let a = 5
{
let a = 3;
}
In the code above, there are two variables with the symbol a.
Other compilers typically uses type like Scope
, and store them nested, but
in rust, type like Scope
requires [Arc<Mutexfoo#1
For the example above, after applying resolver pass, it becomes.
let a#1 = 5
{
let a#2 = 3;
}
Thanks to the tag
we attached, we can now distinguish them.
See Id, which is a type alias for this.
This can be used to store all variables in a module to single hash map.
Comparison
While comparing two identifiers, you can use .to_id()
.
HashMap
There’s a type named Id which only contains minimal information to distinguish identifiers.
Fields
span: Span
sym: JsWord
optional: bool
TypeScript only. Used in case of an optional parameter.
Implementations
sourceimpl Ident
impl Ident
sourcepub fn within_ignored_ctxt<F, Ret>(op: F) -> Retwhere
F: FnOnce() -> Ret,
pub fn within_ignored_ctxt<F, Ret>(op: F) -> Retwhere
F: FnOnce() -> Ret,
In op
, EqIgnoreSpan of Ident will ignore the syntax context.
sourcepub fn without_loc(self) -> Ident
pub fn without_loc(self) -> Ident
Preserve syntax context while drop span.lo
and span.hi
.
sourcepub fn is_valid_start(c: char) -> bool
pub fn is_valid_start(c: char) -> bool
Returns true if c
is a valid character for an identifier start.
sourcepub fn is_valid_continue(c: char) -> bool
pub fn is_valid_continue(c: char) -> bool
Returns true if c
is a valid character for an identifier part after
start.