Skip to content

Commit

Permalink
refactor(ast): use exhaustive match for Argument to `ArrayExpressio…
Browse files Browse the repository at this point in the history
…nElement` conversion (#7848)

Follow-on after #7830. Refactor.

Use an exhaustive match in implementation of `From<Argument<'a>> 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`.
  • Loading branch information
overlookmotel committed Dec 13, 2024
1 parent e55ab24 commit beb982a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,9 @@ impl ArrayExpressionElement<'_> {

impl<'a> From<Argument<'a>> 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()),
}
}
}
Expand Down

0 comments on commit beb982a

Please sign in to comment.