Skip to content

Commit

Permalink
derive Is
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Nov 23, 2023
1 parent 45d9a22 commit fcf4db7
Showing 1 changed file with 1 addition and 58 deletions.
59 changes: 1 addition & 58 deletions crates/swc_ecma_ast/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ impl Take for BlockStmtOrExpr {
}

#[ast_node]
#[derive(Eq, Hash, EqIgnoreSpan)]
#[derive(Is, Eq, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub enum AssignTarget {
#[tag("TsNonNullExpression")]
Expand Down Expand Up @@ -1159,63 +1159,6 @@ bridge_from!(AssignTarget, SimpleAssignTarget, TsNonNullExpr);
bridge_from!(AssignTarget, SimpleAssignTarget, TsTypeAssertion);

impl AssignTarget {
/// Returns the [Pat] if this is a pattern, otherwise returns [None].
pub fn pat(self) -> Option<Box<Pat>> {
match self {
AssignTarget::Simple(_) => None,
AssignTarget::Pat(p) => Some(p),
}
}

/// Returns the [Expr] if this is an expression, otherwise returns
/// `None`.
pub fn expr(self) -> Option<Box<Expr>> {
match self {
AssignTarget::Simple(e) => Some(e),
AssignTarget::Pat(p) => match *p {
Pat::Expr(e) => Some(e),
_ => None,
},
}
}

#[track_caller]
pub fn expect_pat(self) -> Box<Pat> {
self.pat()
.expect("expect_pat is called but it was not a pattern")
}

#[track_caller]
pub fn expect_expr(self) -> Box<Expr> {
self.expr()
.expect("expect_expr is called but it was not a pattern")
}

pub fn as_pat(&self) -> Option<&Pat> {
match self {
AssignTarget::Simple(_) => None,
AssignTarget::Pat(p) => Some(p),
}
}

pub fn as_expr(&self) -> Option<&Expr> {
match self {
AssignTarget::Simple(e) => Some(e),
AssignTarget::Pat(p) => match &**p {
Pat::Expr(e) => Some(e),
_ => None,
},
}
}

pub fn is_pat(&self) -> bool {
self.as_pat().is_some()
}

pub fn is_expr(&self) -> bool {
self.as_expr().is_some()
}

pub fn as_ident(&self) -> Option<&Ident> {
match self {
AssignTarget::Simple(v) => match &**v {
Expand Down

0 comments on commit fcf4db7

Please sign in to comment.