diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index 9af9a9a09..bfc187b8c 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -1112,15 +1112,19 @@ impl VariableDeclarationKind { pub fn is_lexical(&self) -> bool { matches!(self, Self::Const | Self::Let) } + + pub fn to_string(&self) -> &str { + match self { + Self::Var => "var", + Self::Const => "const", + Self::Let => "let", + } + } } impl fmt::Display for VariableDeclarationKind { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let s = match self { - Self::Var => "var", - Self::Const => "const", - Self::Let => "let", - }; + let s = self.to_string(); write!(f, "{s}") } } diff --git a/crates/oxc_semantic/src/checker/javascript.rs b/crates/oxc_semantic/src/checker/javascript.rs index 4ebf51721..c9ce4305b 100644 --- a/crates/oxc_semantic/src/checker/javascript.rs +++ b/crates/oxc_semantic/src/checker/javascript.rs @@ -216,7 +216,8 @@ fn check_binding_identifier<'a>( )] #[diagnostic()] struct InvalidLetDeclaration(String, #[label] Span); - return ctx.error(InvalidLetDeclaration(decl.kind.to_string(), ident.span)); + return ctx + .error(InvalidLetDeclaration(decl.kind.to_string().into(), ident.span)); } AstKind::VariableDeclaration(_) | AstKind::Function(_) | AstKind::Program(_) => { break;