pub trait ExprFactory: Into<Box<Expr>> {
Show 21 methods
// Provided methods
fn as_arg(self) -> ExprOrSpread { ... }
fn into_stmt(self) -> Stmt { ... }
fn into_return_stmt(self) -> ReturnStmt { ... }
fn as_callee(self) -> Callee { ... }
fn as_iife(self) -> CallExpr { ... }
fn into_lazy_arrow(self, params: Vec<Pat>) -> ArrowExpr { ... }
fn into_lazy_fn(self, params: Vec<Param>) -> Function { ... }
fn into_lazy_auto(self, params: Vec<Pat>, support_arrow: bool) -> Expr { ... }
fn into_var_decl(self, kind: VarDeclKind, name: Pat) -> VarDecl { ... }
fn into_new_expr(
self,
span: Span,
args: Option<Vec<ExprOrSpread>>,
) -> NewExpr { ... }
fn apply(self, span: Span, this: Box<Expr>, args: Vec<ExprOrSpread>) -> Expr { ... }
fn call_fn(self, span: Span, args: Vec<ExprOrSpread>) -> Expr { ... }
fn as_call(self, span: Span, args: Vec<ExprOrSpread>) -> Expr { ... }
fn as_fn_decl(self) -> Option<FnDecl> { ... }
fn as_class_decl(self) -> Option<ClassDecl> { ... }
fn wrap_with_paren(self) -> Expr { ... }
fn make_eq<T>(self, right: T) -> Expr
where T: Into<Expr> { ... }
fn make_bin<T>(self, op: BinaryOp, right: T) -> Expr
where T: Into<Expr> { ... }
fn make_assign_to(self, op: AssignOp, left: AssignTarget) -> Expr { ... }
fn make_member(self, prop: IdentName) -> MemberExpr { ... }
fn computed_member<T>(self, prop: T) -> MemberExpr
where T: Into<Box<Expr>> { ... }
}
Expand description
Extension methods for [Expr].
Note that many types implements Into<Expr>
and you can do like
use swc_ecma_utils::ExprFactory;
let _args = vec![0f64.as_arg()];
to create literals. Almost all rust core types implements Into<Expr>
.
Provided Methods§
sourcefn as_arg(self) -> ExprOrSpread
fn as_arg(self) -> ExprOrSpread
Creates an [ExprOrSpread] using the given [Expr].
This is recommended way to create [ExprOrSpread].
§Example
use swc_common::DUMMY_SP;
use swc_ecma_ast::*;
use swc_ecma_utils::ExprFactory;
let first = Lit::Num(Number {
span: DUMMY_SP,
value: 0.0,
raw: None,
});
let _args = vec![first.as_arg()];
sourcefn into_return_stmt(self) -> ReturnStmt
fn into_return_stmt(self) -> ReturnStmt
Creates a statement whcih return self
.
fn as_callee(self) -> Callee
fn as_iife(self) -> CallExpr
sourcefn into_lazy_arrow(self, params: Vec<Pat>) -> ArrowExpr
fn into_lazy_arrow(self, params: Vec<Pat>) -> ArrowExpr
create a ArrowExpr which return self
(params) => $self
sourcefn into_lazy_fn(self, params: Vec<Param>) -> Function
fn into_lazy_fn(self, params: Vec<Param>) -> Function
create a Function which return self
function(params) { return $self; }
fn into_lazy_auto(self, params: Vec<Pat>, support_arrow: bool) -> Expr
sourcefn into_var_decl(self, kind: VarDeclKind, name: Pat) -> VarDecl
fn into_var_decl(self, kind: VarDeclKind, name: Pat) -> VarDecl
create a var declartor using self as init
var name = expr
fn into_new_expr(self, span: Span, args: Option<Vec<ExprOrSpread>>) -> NewExpr
fn apply(self, span: Span, this: Box<Expr>, args: Vec<ExprOrSpread>) -> Expr
fn call_fn(self, span: Span, args: Vec<ExprOrSpread>) -> Expr
fn as_call(self, span: Span, args: Vec<ExprOrSpread>) -> Expr
fn as_fn_decl(self) -> Option<FnDecl>
fn as_class_decl(self) -> Option<ClassDecl>
fn wrap_with_paren(self) -> Expr
sourcefn make_bin<T>(self, op: BinaryOp, right: T) -> Exprwhere
T: Into<Expr>,
fn make_bin<T>(self, op: BinaryOp, right: T) -> Exprwhere
T: Into<Expr>,
Creates a binary expr $self $op $rhs
sourcefn make_assign_to(self, op: AssignOp, left: AssignTarget) -> Expr
fn make_assign_to(self, op: AssignOp, left: AssignTarget) -> Expr
Creates a assign expr $lhs $op $self
fn make_member(self, prop: IdentName) -> MemberExpr
fn computed_member<T>(self, prop: T) -> MemberExpr
Object Safety§
This trait is not object safe.