mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 20:32:10 +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 {
|
pub fn is_lexical(&self) -> bool {
|
||||||
matches!(self, Self::Const | Self::Let)
|
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 {
|
impl fmt::Display for VariableDeclarationKind {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let s = match self {
|
let s = self.to_string();
|
||||||
Self::Var => "var",
|
|
||||||
Self::Const => "const",
|
|
||||||
Self::Let => "let",
|
|
||||||
};
|
|
||||||
write!(f, "{s}")
|
write!(f, "{s}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,8 @@ fn check_binding_identifier<'a>(
|
||||||
)]
|
)]
|
||||||
#[diagnostic()]
|
#[diagnostic()]
|
||||||
struct InvalidLetDeclaration(String, #[label] Span);
|
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(_) => {
|
AstKind::VariableDeclaration(_) | AstKind::Function(_) | AstKind::Program(_) => {
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue