From beb982a69eaf1405aae5f35c6a7b956625c89cfa Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 13 Dec 2024 14:52:11 +0000 Subject: [PATCH] refactor(ast): use exhaustive match for `Argument` to `ArrayExpressionElement` conversion (#7848) Follow-on after #7830. Refactor. Use an exhaustive match in implementation of `From> for ArrayExpressionElement<'a>`. At present this change makes no difference. But the reason I feel an exhaustive match is preferable here is that if we add a variant to `Argument` enum later, then this match will be missing an arm to handle that variant, and compiler will refuse to compile until we deal with it. Whereas before this PR, compiler would not complain, but instead it'd be a runtime panic when `into_expression` discovers that the new `Argument` variant is not an `Expression`. --- crates/oxc_ast/src/ast_impl/js.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/oxc_ast/src/ast_impl/js.rs b/crates/oxc_ast/src/ast_impl/js.rs index b05519ec3eb39..1ff48973fa5f1 100644 --- a/crates/oxc_ast/src/ast_impl/js.rs +++ b/crates/oxc_ast/src/ast_impl/js.rs @@ -321,10 +321,9 @@ impl ArrayExpressionElement<'_> { impl<'a> From> for ArrayExpressionElement<'a> { fn from(argument: Argument<'a>) -> Self { - if let Argument::SpreadElement(spread) = argument { - ArrayExpressionElement::SpreadElement(spread) - } else { - ArrayExpressionElement::from(argument.into_expression()) + match argument { + Argument::SpreadElement(spread) => Self::SpreadElement(spread), + match_expression!(Argument) => Self::from(argument.into_expression()), } } }