Skip to main content

TsExpr

Struct TsExpr 

Source
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: Expr

Methods from Deref<Target = Expr>§

Source

pub fn is_this(&self) -> bool

Returns true if self is of variant This.

Source

pub fn as_this(&self) -> Option<&ThisExpr>

Returns Some if self is a reference of variant This, and None otherwise.

Source

pub fn is_array(&self) -> bool

Returns true if self is of variant Array.

Source

pub fn as_array(&self) -> Option<&ArrayLit>

Returns Some if self is a reference of variant Array, and None otherwise.

Source

pub fn is_object(&self) -> bool

Returns true if self is of variant Object.

Source

pub fn as_object(&self) -> Option<&ObjectLit>

Returns Some if self is a reference of variant Object, and None otherwise.

Source

pub fn is_fn_expr(&self) -> bool

Returns true if self is of variant Fn.

Source

pub fn as_fn_expr(&self) -> Option<&FnExpr>

Returns Some if self is a reference of variant Fn, and None otherwise.

Source

pub fn is_unary(&self) -> bool

Returns true if self is of variant Unary.

Source

pub fn as_unary(&self) -> Option<&UnaryExpr>

Returns Some if self is a reference of variant Unary, and None otherwise.

Source

pub fn is_update(&self) -> bool

Returns true if self is of variant Update.

Source

pub fn as_update(&self) -> Option<&UpdateExpr>

Returns Some if self is a reference of variant Update, and None otherwise.

Source

pub fn is_bin(&self) -> bool

Returns true if self is of variant Bin.

Source

pub fn as_bin(&self) -> Option<&BinExpr>

Returns Some if self is a reference of variant Bin, and None otherwise.

Source

pub fn is_assign(&self) -> bool

Returns true if self is of variant Assign.

Source

pub fn as_assign(&self) -> Option<&AssignExpr>

Returns Some if self is a reference of variant Assign, and None otherwise.

Source

pub fn is_member(&self) -> bool

Returns true if self is of variant Member.

Source

pub fn as_member(&self) -> Option<&MemberExpr>

Returns Some if self is a reference of variant Member, and None otherwise.

Source

pub fn is_super_prop(&self) -> bool

Returns true if self is of variant SuperProp.

Source

pub fn as_super_prop(&self) -> Option<&SuperPropExpr>

Returns Some if self is a reference of variant SuperProp, and None otherwise.

Source

pub fn is_cond(&self) -> bool

Returns true if self is of variant Cond.

Source

pub fn as_cond(&self) -> Option<&CondExpr>

Returns Some if self is a reference of variant Cond, and None otherwise.

Source

pub fn is_call(&self) -> bool

Returns true if self is of variant Call.

Source

pub fn as_call(&self) -> Option<&CallExpr>

Returns Some if self is a reference of variant Call, and None otherwise.

Source

pub fn is_new(&self) -> bool

Returns true if self is of variant New.

Source

pub fn as_new(&self) -> Option<&NewExpr>

Returns Some if self is a reference of variant New, and None otherwise.

Source

pub fn is_seq(&self) -> bool

Returns true if self is of variant Seq.

Source

pub fn as_seq(&self) -> Option<&SeqExpr>

Returns Some if self is a reference of variant Seq, and None otherwise.

Source

pub fn is_ident(&self) -> bool

Returns true if self is of variant Ident.

Source

pub fn as_ident(&self) -> Option<&Ident>

Returns Some if self is a reference of variant Ident, and None otherwise.

Source

pub fn is_lit(&self) -> bool

Returns true if self is of variant Lit.

Source

pub fn as_lit(&self) -> Option<&Lit>

Returns Some if self is a reference of variant Lit, and None otherwise.

Source

pub fn is_tpl(&self) -> bool

Returns true if self is of variant Tpl.

Source

pub fn as_tpl(&self) -> Option<&Tpl>

Returns Some if self is a reference of variant Tpl, and None otherwise.

Source

pub fn is_tagged_tpl(&self) -> bool

Returns true if self is of variant TaggedTpl.

Source

pub fn as_tagged_tpl(&self) -> Option<&TaggedTpl>

Returns Some if self is a reference of variant TaggedTpl, and None otherwise.

Source

pub fn is_arrow(&self) -> bool

Returns true if self is of variant Arrow.

Source

pub fn as_arrow(&self) -> Option<&ArrowExpr>

Returns Some if self is a reference of variant Arrow, and None otherwise.

Source

pub fn is_class(&self) -> bool

Returns true if self is of variant Class.

Source

pub fn as_class(&self) -> Option<&ClassExpr>

Returns Some if self is a reference of variant Class, and None otherwise.

Source

pub fn is_yield_expr(&self) -> bool

Returns true if self is of variant Yield.

Source

pub fn as_yield_expr(&self) -> Option<&YieldExpr>

Returns Some if self is a reference of variant Yield, and None otherwise.

Source

pub fn is_meta_prop(&self) -> bool

Returns true if self is of variant MetaProp.

Source

pub fn as_meta_prop(&self) -> Option<&MetaPropExpr>

Returns Some if self is a reference of variant MetaProp, and None otherwise.

Source

pub fn is_await_expr(&self) -> bool

Returns true if self is of variant Await.

Source

pub fn as_await_expr(&self) -> Option<&AwaitExpr>

Returns Some if self is a reference of variant Await, and None otherwise.

Source

pub fn is_paren(&self) -> bool

Returns true if self is of variant Paren.

Source

pub fn as_paren(&self) -> Option<&ParenExpr>

Returns Some if self is a reference of variant Paren, and None otherwise.

Source

pub fn is_jsx_member(&self) -> bool

Returns true if self is of variant JSXMember.

Source

pub fn as_jsx_member(&self) -> Option<&JSXMemberExpr>

Returns Some if self is a reference of variant JSXMember, and None otherwise.

Source

pub fn is_jsx_namespaced_name(&self) -> bool

Returns true if self is of variant JSXNamespacedName.

Source

pub fn as_jsx_namespaced_name(&self) -> Option<&JSXNamespacedName>

Returns Some if self is a reference of variant JSXNamespacedName, and None otherwise.

Source

pub fn is_jsx_empty(&self) -> bool

Returns true if self is of variant JSXEmpty.

Source

pub fn as_jsx_empty(&self) -> Option<&JSXEmptyExpr>

Returns Some if self is a reference of variant JSXEmpty, and None otherwise.

Source

pub fn is_jsx_element(&self) -> bool

Returns true if self is of variant JSXElement.

Source

pub fn as_jsx_element(&self) -> Option<&Box<JSXElement>>

Returns Some if self is a reference of variant JSXElement, and None otherwise.

Source

pub fn is_jsx_fragment(&self) -> bool

Returns true if self is of variant JSXFragment.

Source

pub fn as_jsx_fragment(&self) -> Option<&JSXFragment>

Returns Some if self is a reference of variant JSXFragment, and None otherwise.

Source

pub fn is_ts_type_assertion(&self) -> bool

Returns true if self is of variant TsTypeAssertion.

Source

pub fn as_ts_type_assertion(&self) -> Option<&TsTypeAssertion>

Returns Some if self is a reference of variant TsTypeAssertion, and None otherwise.

Source

pub fn is_ts_const_assertion(&self) -> bool

Returns true if self is of variant TsConstAssertion.

Source

pub fn as_ts_const_assertion(&self) -> Option<&TsConstAssertion>

Returns Some if self is a reference of variant TsConstAssertion, and None otherwise.

Source

pub fn is_ts_non_null(&self) -> bool

Returns true if self is of variant TsNonNull.

Source

pub fn as_ts_non_null(&self) -> Option<&TsNonNullExpr>

Returns Some if self is a reference of variant TsNonNull, and None otherwise.

Source

pub fn is_ts_as(&self) -> bool

Returns true if self is of variant TsAs.

Source

pub fn as_ts_as(&self) -> Option<&TsAsExpr>

Returns Some if self is a reference of variant TsAs, and None otherwise.

Source

pub fn is_ts_instantiation(&self) -> bool

Returns true if self is of variant TsInstantiation.

Source

pub fn as_ts_instantiation(&self) -> Option<&TsInstantiation>

Returns Some if self is a reference of variant TsInstantiation, and None otherwise.

Source

pub fn is_ts_satisfies(&self) -> bool

Returns true if self is of variant TsSatisfies.

Source

pub fn as_ts_satisfies(&self) -> Option<&TsSatisfiesExpr>

Returns Some if self is a reference of variant TsSatisfies, and None otherwise.

Source

pub fn is_private_name(&self) -> bool

Returns true if self is of variant PrivateName.

Source

pub fn as_private_name(&self) -> Option<&PrivateName>

Returns Some if self is a reference of variant PrivateName, and None otherwise.

Source

pub fn is_opt_chain(&self) -> bool

Returns true if self is of variant OptChain.

Source

pub fn as_opt_chain(&self) -> Option<&OptChainExpr>

Returns Some if self is a reference of variant OptChain, and None otherwise.

Source

pub fn is_invalid(&self) -> bool

Returns true if self is of variant Invalid.

Source

pub fn as_invalid(&self) -> Option<&Invalid>

Returns Some if self is a reference of variant Invalid, and None otherwise.

Source

pub fn is_null(&self) -> bool

Source

pub fn leftmost(&self) -> Option<&Ident>

Source

pub fn is_ident_ref_to<S>(&self, ident: &S) -> bool
where Atom: PartialEq<S>, S: ?Sized,

Source

pub fn unwrap_with<'a, F>(&'a self, op: F) -> &'a Expr
where F: FnMut(&'a Expr) -> Option<&'a Expr>,

Unwraps an expression with a given function.

If the provided function returns Some, the function is called again with the returned value. If the provided functions returns None, the last expression is returned.

Source

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.

Source

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.

Source

pub fn directness_maters(&self) -> bool

👎Deprecated: Use directness_matters instead
Source

pub fn directness_matters(&self) -> bool

Returns true for eval and member expressions.

Trait Implementations§

Source§

impl Clone for TsExpr

Source§

fn clone(&self) -> TsExpr

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TsExpr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for TsExpr

Available on crate feature swc only.
Source§

type Target = Expr

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Display for TsExpr

Available on crate feature swc only.
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Expr> for TsExpr

Available on crate feature swc only.
Source§

fn from(expr: Expr) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> ImplicitClone for T
where T: Clone,

Source§

fn clone_quote_var(&self) -> Self

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToCompactString for T
where T: Display,

Source§

fn to_compact_string(&self) -> CompactString

Converts the given value to a CompactString. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Send for T
where T: ?Sized,

Source§

impl<T> Sync for T
where T: ?Sized,