pub struct TsExpr(pub Expr);Expand description
Wrapper for swc_core::ecma::ast::Expr that implements [Display] and ToTsString.
This allows expressions to be interpolated into string-based templates
using @{expr} syntax, where the expression will be emitted as TypeScript code.
§Example
use macroforge_ts_syn::{TsExpr, swc_ecma_ast::Expr};
let expr: Expr = /* ... */;
let wrapped = TsExpr(expr);
println!("const x = {};", wrapped); // Emits: const x = <expr>;Tuple Fields§
§0: ExprMethods from Deref<Target = Expr>§
Sourcepub fn as_this(&self) -> Option<&ThisExpr>
pub fn as_this(&self) -> Option<&ThisExpr>
Returns Some if self is a reference of variant This, and None otherwise.
Sourcepub fn as_array(&self) -> Option<&ArrayLit>
pub fn as_array(&self) -> Option<&ArrayLit>
Returns Some if self is a reference of variant Array, and None otherwise.
Sourcepub fn as_object(&self) -> Option<&ObjectLit>
pub fn as_object(&self) -> Option<&ObjectLit>
Returns Some if self is a reference of variant Object, and None otherwise.
Sourcepub fn is_fn_expr(&self) -> bool
pub fn is_fn_expr(&self) -> bool
Returns true if self is of variant Fn.
Sourcepub fn as_fn_expr(&self) -> Option<&FnExpr>
pub fn as_fn_expr(&self) -> Option<&FnExpr>
Returns Some if self is a reference of variant Fn, and None otherwise.
Sourcepub fn as_unary(&self) -> Option<&UnaryExpr>
pub fn as_unary(&self) -> Option<&UnaryExpr>
Returns Some if self is a reference of variant Unary, and None otherwise.
Sourcepub fn as_update(&self) -> Option<&UpdateExpr>
pub fn as_update(&self) -> Option<&UpdateExpr>
Returns Some if self is a reference of variant Update, and None otherwise.
Sourcepub fn as_bin(&self) -> Option<&BinExpr>
pub fn as_bin(&self) -> Option<&BinExpr>
Returns Some if self is a reference of variant Bin, and None otherwise.
Sourcepub fn as_assign(&self) -> Option<&AssignExpr>
pub fn as_assign(&self) -> Option<&AssignExpr>
Returns Some if self is a reference of variant Assign, and None otherwise.
Sourcepub fn as_member(&self) -> Option<&MemberExpr>
pub fn as_member(&self) -> Option<&MemberExpr>
Returns Some if self is a reference of variant Member, and None otherwise.
Sourcepub fn is_super_prop(&self) -> bool
pub fn is_super_prop(&self) -> bool
Returns true if self is of variant SuperProp.
Sourcepub fn as_super_prop(&self) -> Option<&SuperPropExpr>
pub fn as_super_prop(&self) -> Option<&SuperPropExpr>
Returns Some if self is a reference of variant SuperProp, and None otherwise.
Sourcepub fn as_cond(&self) -> Option<&CondExpr>
pub fn as_cond(&self) -> Option<&CondExpr>
Returns Some if self is a reference of variant Cond, and None otherwise.
Sourcepub fn as_call(&self) -> Option<&CallExpr>
pub fn as_call(&self) -> Option<&CallExpr>
Returns Some if self is a reference of variant Call, and None otherwise.
Sourcepub fn as_new(&self) -> Option<&NewExpr>
pub fn as_new(&self) -> Option<&NewExpr>
Returns Some if self is a reference of variant New, and None otherwise.
Sourcepub fn as_seq(&self) -> Option<&SeqExpr>
pub fn as_seq(&self) -> Option<&SeqExpr>
Returns Some if self is a reference of variant Seq, and None otherwise.
Sourcepub fn as_ident(&self) -> Option<&Ident>
pub fn as_ident(&self) -> Option<&Ident>
Returns Some if self is a reference of variant Ident, and None otherwise.
Sourcepub fn as_lit(&self) -> Option<&Lit>
pub fn as_lit(&self) -> Option<&Lit>
Returns Some if self is a reference of variant Lit, and None otherwise.
Sourcepub fn as_tpl(&self) -> Option<&Tpl>
pub fn as_tpl(&self) -> Option<&Tpl>
Returns Some if self is a reference of variant Tpl, and None otherwise.
Sourcepub fn is_tagged_tpl(&self) -> bool
pub fn is_tagged_tpl(&self) -> bool
Returns true if self is of variant TaggedTpl.
Sourcepub fn as_tagged_tpl(&self) -> Option<&TaggedTpl>
pub fn as_tagged_tpl(&self) -> Option<&TaggedTpl>
Returns Some if self is a reference of variant TaggedTpl, and None otherwise.
Sourcepub fn as_arrow(&self) -> Option<&ArrowExpr>
pub fn as_arrow(&self) -> Option<&ArrowExpr>
Returns Some if self is a reference of variant Arrow, and None otherwise.
Sourcepub fn as_class(&self) -> Option<&ClassExpr>
pub fn as_class(&self) -> Option<&ClassExpr>
Returns Some if self is a reference of variant Class, and None otherwise.
Sourcepub fn is_yield_expr(&self) -> bool
pub fn is_yield_expr(&self) -> bool
Returns true if self is of variant Yield.
Sourcepub fn as_yield_expr(&self) -> Option<&YieldExpr>
pub fn as_yield_expr(&self) -> Option<&YieldExpr>
Returns Some if self is a reference of variant Yield, and None otherwise.
Sourcepub fn is_meta_prop(&self) -> bool
pub fn is_meta_prop(&self) -> bool
Returns true if self is of variant MetaProp.
Sourcepub fn as_meta_prop(&self) -> Option<&MetaPropExpr>
pub fn as_meta_prop(&self) -> Option<&MetaPropExpr>
Returns Some if self is a reference of variant MetaProp, and None otherwise.
Sourcepub fn is_await_expr(&self) -> bool
pub fn is_await_expr(&self) -> bool
Returns true if self is of variant Await.
Sourcepub fn as_await_expr(&self) -> Option<&AwaitExpr>
pub fn as_await_expr(&self) -> Option<&AwaitExpr>
Returns Some if self is a reference of variant Await, and None otherwise.
Sourcepub fn as_paren(&self) -> Option<&ParenExpr>
pub fn as_paren(&self) -> Option<&ParenExpr>
Returns Some if self is a reference of variant Paren, and None otherwise.
Sourcepub fn is_jsx_member(&self) -> bool
pub fn is_jsx_member(&self) -> bool
Returns true if self is of variant JSXMember.
Sourcepub fn as_jsx_member(&self) -> Option<&JSXMemberExpr>
pub fn as_jsx_member(&self) -> Option<&JSXMemberExpr>
Returns Some if self is a reference of variant JSXMember, and None otherwise.
Sourcepub fn is_jsx_namespaced_name(&self) -> bool
pub fn is_jsx_namespaced_name(&self) -> bool
Returns true if self is of variant JSXNamespacedName.
Sourcepub fn as_jsx_namespaced_name(&self) -> Option<&JSXNamespacedName>
pub fn as_jsx_namespaced_name(&self) -> Option<&JSXNamespacedName>
Returns Some if self is a reference of variant JSXNamespacedName, and None otherwise.
Sourcepub fn is_jsx_empty(&self) -> bool
pub fn is_jsx_empty(&self) -> bool
Returns true if self is of variant JSXEmpty.
Sourcepub fn as_jsx_empty(&self) -> Option<&JSXEmptyExpr>
pub fn as_jsx_empty(&self) -> Option<&JSXEmptyExpr>
Returns Some if self is a reference of variant JSXEmpty, and None otherwise.
Sourcepub fn is_jsx_element(&self) -> bool
pub fn is_jsx_element(&self) -> bool
Returns true if self is of variant JSXElement.
Sourcepub fn as_jsx_element(&self) -> Option<&Box<JSXElement>>
pub fn as_jsx_element(&self) -> Option<&Box<JSXElement>>
Returns Some if self is a reference of variant JSXElement, and None otherwise.
Sourcepub fn is_jsx_fragment(&self) -> bool
pub fn is_jsx_fragment(&self) -> bool
Returns true if self is of variant JSXFragment.
Sourcepub fn as_jsx_fragment(&self) -> Option<&JSXFragment>
pub fn as_jsx_fragment(&self) -> Option<&JSXFragment>
Returns Some if self is a reference of variant JSXFragment, and None otherwise.
Sourcepub fn is_ts_type_assertion(&self) -> bool
pub fn is_ts_type_assertion(&self) -> bool
Returns true if self is of variant TsTypeAssertion.
Sourcepub fn as_ts_type_assertion(&self) -> Option<&TsTypeAssertion>
pub fn as_ts_type_assertion(&self) -> Option<&TsTypeAssertion>
Returns Some if self is a reference of variant TsTypeAssertion, and None otherwise.
Sourcepub fn is_ts_const_assertion(&self) -> bool
pub fn is_ts_const_assertion(&self) -> bool
Returns true if self is of variant TsConstAssertion.
Sourcepub fn as_ts_const_assertion(&self) -> Option<&TsConstAssertion>
pub fn as_ts_const_assertion(&self) -> Option<&TsConstAssertion>
Returns Some if self is a reference of variant TsConstAssertion, and None otherwise.
Sourcepub fn is_ts_non_null(&self) -> bool
pub fn is_ts_non_null(&self) -> bool
Returns true if self is of variant TsNonNull.
Sourcepub fn as_ts_non_null(&self) -> Option<&TsNonNullExpr>
pub fn as_ts_non_null(&self) -> Option<&TsNonNullExpr>
Returns Some if self is a reference of variant TsNonNull, and None otherwise.
Sourcepub fn as_ts_as(&self) -> Option<&TsAsExpr>
pub fn as_ts_as(&self) -> Option<&TsAsExpr>
Returns Some if self is a reference of variant TsAs, and None otherwise.
Sourcepub fn is_ts_instantiation(&self) -> bool
pub fn is_ts_instantiation(&self) -> bool
Returns true if self is of variant TsInstantiation.
Sourcepub fn as_ts_instantiation(&self) -> Option<&TsInstantiation>
pub fn as_ts_instantiation(&self) -> Option<&TsInstantiation>
Returns Some if self is a reference of variant TsInstantiation, and None otherwise.
Sourcepub fn is_ts_satisfies(&self) -> bool
pub fn is_ts_satisfies(&self) -> bool
Returns true if self is of variant TsSatisfies.
Sourcepub fn as_ts_satisfies(&self) -> Option<&TsSatisfiesExpr>
pub fn as_ts_satisfies(&self) -> Option<&TsSatisfiesExpr>
Returns Some if self is a reference of variant TsSatisfies, and None otherwise.
Sourcepub fn is_private_name(&self) -> bool
pub fn is_private_name(&self) -> bool
Returns true if self is of variant PrivateName.
Sourcepub fn as_private_name(&self) -> Option<&PrivateName>
pub fn as_private_name(&self) -> Option<&PrivateName>
Returns Some if self is a reference of variant PrivateName, and None otherwise.
Sourcepub fn is_opt_chain(&self) -> bool
pub fn is_opt_chain(&self) -> bool
Returns true if self is of variant OptChain.
Sourcepub fn as_opt_chain(&self) -> Option<&OptChainExpr>
pub fn as_opt_chain(&self) -> Option<&OptChainExpr>
Returns Some if self is a reference of variant OptChain, and None otherwise.
Sourcepub fn is_invalid(&self) -> bool
pub fn is_invalid(&self) -> bool
Returns true if self is of variant Invalid.
Sourcepub fn as_invalid(&self) -> Option<&Invalid>
pub fn as_invalid(&self) -> Option<&Invalid>
Returns Some if self is a reference of variant Invalid, and None otherwise.
pub fn is_null(&self) -> bool
pub fn leftmost(&self) -> Option<&Ident>
pub fn is_ident_ref_to<S>(&self, ident: &S) -> bool
Sourcepub fn unwrap_with<'a, F>(&'a self, op: F) -> &'a Expr
pub fn unwrap_with<'a, F>(&'a self, op: F) -> &'a Expr
Sourcepub fn unwrap_parens(&self) -> &Expr
pub fn unwrap_parens(&self) -> &Expr
Normalize parenthesized expressions.
This will normalize (foo), ((foo)), … to foo.
If self is not a parenthesized expression, it will be returned as is.
Sourcepub fn unwrap_seqs_and_parens(&self) -> &Expr
pub fn unwrap_seqs_and_parens(&self) -> &Expr
Normalize sequences and parenthesized expressions.
This returns the last expression of a sequence expression or the expression of a parenthesized expression.
pub fn directness_maters(&self) -> bool
directness_matters insteadSourcepub fn directness_matters(&self) -> bool
pub fn directness_matters(&self) -> bool
Returns true for eval and member expressions.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TsExpr
impl RefUnwindSafe for TsExpr
impl Send for TsExpr
impl Sync for TsExpr
impl Unpin for TsExpr
impl UnsafeUnpin for TsExpr
impl UnwindSafe for TsExpr
Blanket Implementations§
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ImplicitClone for Twhere
T: Clone,
impl<T> ImplicitClone for Twhere
T: Clone,
fn clone_quote_var(&self) -> Self
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 moreSource§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more