mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
refactor(ast): VariableDeclarationKind::to_string -> as_str (#1321)
This commit is contained in:
parent
d2b73122c5
commit
be043c37e9
3 changed files with 5 additions and 6 deletions
|
|
@ -1113,7 +1113,7 @@ impl VariableDeclarationKind {
|
||||||
matches!(self, Self::Const | Self::Let)
|
matches!(self, Self::Const | Self::Let)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_string(&self) -> &str {
|
pub fn as_str(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::Var => "var",
|
Self::Var => "var",
|
||||||
Self::Const => "const",
|
Self::Const => "const",
|
||||||
|
|
@ -1124,7 +1124,7 @@ impl VariableDeclarationKind {
|
||||||
|
|
||||||
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 = self.to_string();
|
let s = self.as_str();
|
||||||
write!(f, "{s}")
|
write!(f, "{s}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -353,12 +353,12 @@ impl<'a> Format<'a> for Declaration<'a> {
|
||||||
|
|
||||||
impl<'a> Format<'a> for VariableDeclaration<'a> {
|
impl<'a> Format<'a> for VariableDeclaration<'a> {
|
||||||
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
|
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
|
||||||
let kind = self.kind.to_string();
|
let kind = self.kind.as_str();
|
||||||
let mut decls = p.vec();
|
let mut decls = p.vec();
|
||||||
decls.extend(self.declarations.iter().map(|decl| decl.format(p)));
|
decls.extend(self.declarations.iter().map(|decl| decl.format(p)));
|
||||||
|
|
||||||
let mut parts = p.vec();
|
let mut parts = p.vec();
|
||||||
parts.push(p.str(kind));
|
parts.push(ss!(kind));
|
||||||
parts.push(ss!(" "));
|
parts.push(ss!(" "));
|
||||||
parts.push(Doc::Array(decls));
|
parts.push(Doc::Array(decls));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -216,8 +216,7 @@ fn check_binding_identifier<'a>(
|
||||||
)]
|
)]
|
||||||
#[diagnostic()]
|
#[diagnostic()]
|
||||||
struct InvalidLetDeclaration(String, #[label] Span);
|
struct InvalidLetDeclaration(String, #[label] Span);
|
||||||
return ctx
|
return ctx.error(InvalidLetDeclaration(decl.kind.as_str().into(), ident.span));
|
||||||
.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