mirror of
https://github.com/danbulant/oxc
synced 2026-05-21 05:08:45 +00:00
feat(ast): add to_string function to VariableDelcartionKind (#1303)
feat(ast): add to_string function to VariableDelcartionKind fix: lint error
This commit is contained in:
parent
3dee2c7178
commit
446ba169de
2 changed files with 11 additions and 6 deletions
|
|
@ -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}")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue