fix(prettier) print computed object property key correctly (#1599)

This commit is contained in:
Cameron 2023-12-01 10:36:38 +00:00 committed by GitHub
parent 0134211b6f
commit 66452c95f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View file

@ -1475,7 +1475,11 @@ impl<'a> Format<'a> for ObjectProperty<'a> {
return self.value.format(p);
}
let left_doc = format!(p, self.key);
let left_doc = if self.computed {
array!(p, ss!("["), format!(p, self.key), ss!("]"))
} else {
format!(p, self.key)
};
assignment::print_assignment(
p,

View file

@ -1,4 +1,4 @@
Compatibility: 210/561 (37.43%)
Compatibility: 212/561 (37.79%)
# Failed
@ -366,7 +366,6 @@ Compatibility: 210/561 (37.43%)
* objects/right-break.js
### objects/assignment-expression
* objects/assignment-expression/object-property.js
* objects/assignment-expression/object-value.js
### optional-chaining
@ -402,7 +401,6 @@ Compatibility: 210/561 (37.43%)
### quote-props
* quote-props/numeric-separator.js
* quote-props/objects.js
* quote-props/with_member_expressions.js
### quotes
* quotes/objects.js