Skip to content

Commit

Permalink
Fix isStringKeySafeToUnquote (#16058)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Feb 18, 2024
1 parent 57fdd9a commit c4af355
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 83 deletions.
16 changes: 16 additions & 0 deletions changelog_unreleased/javascript/16058.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#### Fix unstable object print (#16058 by @fisker)

<!-- prettier-ignore -->
```jsx
// Input
a = {"\a": 1, "b": 2}

// Prettier stable (--quote-props consistent)
a = { "a": 1, "b": 2 };

// Prettier stable (--quote-props as-needed)
a = { "a": 1, b: 2 };

// Prettier main
a = { a: 1, b: 2 };
```
3 changes: 1 addition & 2 deletions src/language-js/print/property.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ function isStringKeySafeToUnquote(node, options) {
options.parser === "json" ||
options.parser === "jsonc" ||
!isStringLiteral(node.key) ||
// TODO[@fisker]: Use `printString` instead
rawText(node.key).slice(1, -1) !== node.key.value
printString(rawText(node.key), options).slice(1, -1) !== node.key.value
) {
return false;
}
Expand Down
Loading

0 comments on commit c4af355

Please sign in to comment.