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:
Dunqing 2023-11-14 20:22:56 +08:00 committed by GitHub
parent 3dee2c7178
commit 446ba169de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View file

@ -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}")
}
}

View file

@ -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;