Skip to content

Commit 57108c0

Browse files
authored
fix(formatter): keep computed name in enum (#13848)
1 parent 5d4e4f0 commit 57108c0

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

crates/oxc_formatter/src/write/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,19 @@ 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 = matches!(id.as_ref(), TSEnumMemberName::ComputedTemplateString(_));
1171+
1172+
if is_computed {
1173+
write!(f, "[")?;
1174+
}
1175+
1176+
write!(f, [id])?;
1177+
1178+
if is_computed {
1179+
write!(f, "]")?;
1180+
}
1181+
11701182
if let Some(init) = self.initializer() {
11711183
write!(f, [space(), "=", space(), init])?;
11721184
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
formatter_misc Summary:
22
AST Parsed : 49/49 (100.00%)
3-
Positive Passed: 46/49 (93.88%)
3+
Positive Passed: 47/49 (95.92%)
44
Expect to Parse: tasks/coverage/misc/pass/oxc-11487.cjs
55
Cannot use `await` as an identifier in an async context
66
Mismatch: tasks/coverage/misc/pass/oxc-2592.ts
77

8-
Expect to Parse: tasks/coverage/misc/pass/oxc-4449.ts
9-
Computed property names are not allowed in enums.

0 commit comments

Comments
 (0)