Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Quote and unquote number keys (#8508)
* Quote and unquote number keys * Add changelog entry * Add tests for escapes * Fix idempotency * Only run flow-repo/ tests with flow 271 jsfmt.spec.js in flow-repo use only the flow parser. 18 use flow and babel. Now, all of them use only flow. * Don’t unquote negative numbers * Don’t quote/unquote numbers in TypeScript * Quote BigInt * Fix AST check * Fix condition * Fix BigInt to string * Fix ESLint not recognizing BigInt * Only quote/unquote “simple” numbers * No need to clean BigIntLiteral anymore * Add tests for 1. and .1 * Fix 1. and .1 * Remove unnecessary babel-ts from tests * Only unquote numbers for babel * Update changelog
- Loading branch information
Showing
50 changed files
with
2,566 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#### Quote and unquote number keys ([#8508](https://github.com/prettier/prettier/pull/8508) by [@lydell](https://github.com/lydell)) | ||
|
||
Prettier removes quotes from object keys if they are identifiers. Now, Prettier also removes quotes from object keys that are numbers. | ||
|
||
If you use `quoteProps: "consistent"`, Prettier can also _add_ quotes to number keys so that _all_ properties end up with quotes. | ||
|
||
<!-- prettier-ignore --> | ||
```jsx | ||
// Input | ||
x = { | ||
"a": null, | ||
"1": null, | ||
}; | ||
|
||
// Prettier stable | ||
x = { | ||
a: null, | ||
"1": null, | ||
}; | ||
|
||
// Prettier master | ||
x = { | ||
a: null, | ||
1: null, | ||
}; | ||
``` | ||
|
||
Prettier only touches “simple” numbers such as `1` and `123.5`. It _won’t_ make the following transformations, as they feel unexpected: | ||
|
||
``` | ||
1e2 -> "100" | ||
0b10 -> "10" | ||
1_000 -> "1000" | ||
1.0 -> "1" | ||
0.99999999999999999 -> "1" | ||
999999999999999999999 -> "1e+21" | ||
2n -> "2" | ||
"1e+100" -> 1e100 | ||
``` | ||
|
||
(Please don’t use confusing numbers as object keys!) | ||
|
||
Note that Prettier only unquotes numbers using the `"babel"` parser. It’s not completely safe to do so in TypeScript. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
run_spec(__dirname, ["flow", "babel"]); | ||
run_spec(__dirname, ["flow"]); |
Oops, something went wrong.