Struct swc_ecma_ast::Ident
source · pub struct Ident {
pub span: Span,
pub sym: Atom,
pub optional: bool,
}
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, Atom . 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: Atom
§optional: bool
TypeScript only. Used in case of an optional parameter.
Implementations§
source§impl 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.
pub fn is_dummy(&self) -> bool
Trait Implementations§
source§impl Archive for Ident
impl Archive for Ident
source§impl<'de> Deserialize<'de> for Ident
impl<'de> Deserialize<'de> for Ident
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl<__D> Deserialize<Ident, __D> for Archived<Ident>where
__D: SharedDeserializeRegistry + Fallible + ?Sized,
impl<__D> Deserialize<Ident, __D> for Archived<Ident>where __D: SharedDeserializeRegistry + Fallible + ?Sized,
source§impl EqIgnoreSpan for Ident
impl EqIgnoreSpan for Ident
fn eq_ignore_span(&self, other: &Self) -> bool
source§impl From<Ident> for BindingIdent
impl From<Ident> for BindingIdent
source§impl From<Ident> for JSXAttrName
impl From<Ident> for JSXAttrName
source§impl From<Ident> for JSXElementName
impl From<Ident> for JSXElementName
source§impl From<Ident> for MemberProp
impl From<Ident> for MemberProp
source§impl From<Ident> for ModuleExportName
impl From<Ident> for ModuleExportName
source§impl From<Ident> for TsEntityName
impl From<Ident> for TsEntityName
source§impl From<Ident> for TsEnumMemberId
impl From<Ident> for TsEnumMemberId
source§impl From<Ident> for TsModuleName
impl From<Ident> for TsModuleName
source§impl From<Ident> for TsThisTypeOrIdent
impl From<Ident> for TsThisTypeOrIdent
source§impl IdentExt for Ident
impl IdentExt for Ident
fn is_reserved(&self) -> bool
fn is_reserved_in_strict_mode(&self, is_module: bool) -> bool
fn is_reserved_in_strict_bind(&self) -> bool
fn is_reserved_in_es3(&self) -> bool
source§impl PartialEq for Ident
impl PartialEq for Ident
source§impl<__S> Serialize<__S> for Identwhere
__S: Serializer + ScratchSpace + SharedSerializeRegistry + Fallible + ?Sized,
impl<__S> Serialize<__S> for Identwhere __S: Serializer + ScratchSpace + SharedSerializeRegistry + Fallible + ?Sized,
impl Eq for Ident
impl StructuralEq for Ident
impl StructuralPartialEq for Ident
Auto Trait Implementations§
impl RefUnwindSafe for Ident
impl Send for Ident
impl Sync for Ident
impl Unpin for Ident
impl UnwindSafe for Ident
Blanket Implementations§
source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata
source§impl<T> ArchiveUnsized for Twhere
T: Archive,
impl<T> ArchiveUnsized for Twhere T: Archive,
§type Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
Archive
, it may be unsized. Read more§type MetadataResolver = ()
type MetadataResolver = ()
source§unsafe fn resolve_metadata(
&self,
_: usize,
_: <T as ArchiveUnsized>::MetadataResolver,
_: *mut <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
)
unsafe fn resolve_metadata( &self, _: usize, _: <T as ArchiveUnsized>::MetadataResolver, _: *mut <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata )
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CallHasher for Twhere
T: Hash + ?Sized,
impl<T> CallHasher for Twhere T: Hash + ?Sized,
source§impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.