Skip to content

Commit

Permalink
feat(ast): add Expression::into_inner_expression (#8048)
Browse files Browse the repository at this point in the history
Add `Expression::into_inner_expression`. Does the same as `get_inner_expression` and `get_inner_expression_mut`, but operates on an owned `Expression`.
  • Loading branch information
overlookmotel committed Dec 23, 2024
1 parent cbd5169 commit c2daa20
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,24 @@ impl<'a> Expression<'a> {
}
}

#[allow(missing_docs)]
#[must_use]
pub fn into_inner_expression(self) -> Expression<'a> {
let mut expr = self;
loop {
expr = match expr {
Expression::ParenthesizedExpression(e) => e.unbox().expression,
Expression::TSAsExpression(e) => e.unbox().expression,
Expression::TSSatisfiesExpression(e) => e.unbox().expression,
Expression::TSInstantiationExpression(e) => e.unbox().expression,
Expression::TSNonNullExpression(e) => e.unbox().expression,
Expression::TSTypeAssertion(e) => e.unbox().expression,
_ => break,
};
}
expr
}

#[allow(missing_docs)]
pub fn get_inner_expression(&self) -> &Expression<'a> {
let mut expr = self;
Expand Down

0 comments on commit c2daa20

Please sign in to comment.