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.
sourcepub fn with_prefix(&self, prefix: &str) -> Ident
pub fn with_prefix(&self, prefix: &str) -> Ident
Create a new identifier with the given prefix.
sourcepub fn into_private(self) -> Ident
pub fn into_private(self) -> Ident
Create a private identifier that is unique in the file, but with the same symbol.
pub fn is_dummy(&self) -> bool
Trait Implementations§
source§impl<'a> Arbitrary<'a> for Ident
Available on crate feature arbitrary
only.
impl<'a> Arbitrary<'a> for Ident
arbitrary
only.source§fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'_>) -> Result<Self>
Self
from the given unstructured data. Read moresource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self
from the entirety of the given
unstructured data. Read moresource§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 EqIgnoreSpan for Ident
impl EqIgnoreSpan for Ident
fn eq_ignore_span(&self, other: &Self) -> bool
source§impl EsReserved for Ident
impl EsReserved 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
fn is_reserved_in_any(&self) -> bool
source§impl From<BindingIdent> for Ident
impl From<BindingIdent> for Ident
source§fn from(bi: BindingIdent) -> Self
fn from(bi: BindingIdent) -> Self
source§impl From<Ident> for AssignTarget
impl From<Ident> for AssignTarget
source§fn from(src: Ident) -> AssignTarget
fn from(src: Ident) -> AssignTarget
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 SimpleAssignTarget
impl From<Ident> for SimpleAssignTarget
source§fn from(src: Ident) -> SimpleAssignTarget
fn from(src: Ident) -> SimpleAssignTarget
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 PartialEq for Ident
impl PartialEq for Ident
impl Eq for Ident
impl StructuralPartialEq for Ident
Auto Trait Implementations§
impl Freeze for Ident
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 T
impl<T> CallHasher for T
source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more