Skip to content

Commit 6f046e6

Browse files
committed
right way to fix
1 parent 238699f commit 6f046e6

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

crates/oxc_formatter/src/write/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,22 @@ impl<'a> Format<'a> for AstNode<'a, Vec<'a, TSEnumMember<'a>>> {
11661166

11671167
impl<'a> FormatWrite<'a> for AstNode<'a, TSEnumMember<'a>> {
11681168
fn write(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
1169-
write!(f, [self.id()])?;
1169+
let id = self.id();
1170+
let is_computed = match id.as_ref() {
1171+
TSEnumMemberName::ComputedTemplateString(_) => true,
1172+
_ => false,
1173+
};
1174+
1175+
if is_computed {
1176+
write!(f, "[")?;
1177+
}
1178+
1179+
write!(f, [id])?;
1180+
1181+
if is_computed {
1182+
write!(f, "]")?;
1183+
}
1184+
11701185
if let Some(init) = self.initializer() {
11711186
write!(f, [space(), "=", space(), init])?;
11721187
}

crates/oxc_formatter/src/write/template.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
printer::Printer,
1717
trivia::{FormatLeadingComments, FormatTrailingComments},
1818
},
19-
generated::ast_nodes::{AstNode, AstNodeIterator, AstNodes},
19+
generated::ast_nodes::{AstNode, AstNodeIterator},
2020
utils::{
2121
call_expression::is_test_each_pattern, expression::FormatExpressionWithoutTrailingComments,
2222
},
@@ -27,20 +27,8 @@ use super::FormatWrite;
2727

2828
impl<'a> FormatWrite<'a> for AstNode<'a, TemplateLiteral<'a>> {
2929
fn write(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
30-
let is_computed_literal = matches!(self.parent, AstNodes::TSEnumMember(_));
31-
32-
if is_computed_literal {
33-
write!(f, "[")?;
34-
}
35-
3630
let template = TemplateLike::TemplateLiteral(self);
37-
write!(f, template)?;
38-
39-
if is_computed_literal {
40-
write!(f, "]")?;
41-
}
42-
43-
Ok(())
31+
write!(f, template)
4432
}
4533
}
4634

0 commit comments

Comments
 (0)