Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix to add parentheses for TSTypeQuery in some case (#14042)
* add TSTypeQuery to needsParens * fix to lint prettier * add test * remove comment * add changelog * fix lint * remove template comments at top in changelog * Fix changelog * Add new line * check objectType * remove fallthrough comment * check property name * Simplify changelog Co-authored-by: fisker Cheung <lionkay@gmail.com>
- Loading branch information
1 parent
e301b1f
commit 369bf2a
Showing
5 changed files
with
50 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#### Add parentheses for TSTypeQuery to improve readability (#14042 by @onishi-kohei) | ||
|
||
<!-- prettier-ignore --> | ||
```tsx | ||
// Input | ||
a as (typeof node.children)[number] | ||
a as (typeof node.children)[] | ||
a as ((typeof node.children)[number])[] | ||
|
||
// Prettier stable | ||
a as typeof node.children[number]; | ||
a as typeof node.children[]; | ||
a as typeof node.children[number][]; | ||
|
||
// Prettier main | ||
a as (typeof node.children)[number]; | ||
a as (typeof node.children)[]; | ||
a as (typeof node.children)[number][]; | ||
``` |
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
21 changes: 21 additions & 0 deletions
21
tests/format/typescript/typeof/__snapshots__/jsfmt.spec.js.snap
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,21 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`typeof.ts format 1`] = ` | ||
====================================options===================================== | ||
parsers: ["typescript"] | ||
printWidth: 80 | ||
| printWidth | ||
=====================================input====================================== | ||
a as (typeof node.children)[number] | ||
a as (typeof node.children)[] | ||
a as ((typeof node.children)[number])[] | ||
a as number[(typeof node.children)] | ||
=====================================output===================================== | ||
a as (typeof node.children)[number]; | ||
a as (typeof node.children)[]; | ||
a as (typeof node.children)[number][]; | ||
a as number[typeof node.children]; | ||
================================================================================ | ||
`; |
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 @@ | ||
run_spec(__dirname, ["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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
a as (typeof node.children)[number] | ||
a as (typeof node.children)[] | ||
a as ((typeof node.children)[number])[] | ||
a as number[(typeof node.children)] |