From 1eb4b52cead79e8fae8af3936fc6c63fcb747fa0 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Fri, 20 Dec 2024 14:59:21 +0000 Subject: [PATCH] feat(ast): add `Expression::into_inner_expression` --- crates/oxc_ast/src/ast_impl/js.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/oxc_ast/src/ast_impl/js.rs b/crates/oxc_ast/src/ast_impl/js.rs index 98ac44e7c6c7e..e4b6e85877d9e 100644 --- a/crates/oxc_ast/src/ast_impl/js.rs +++ b/crates/oxc_ast/src/ast_impl/js.rs @@ -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;