TypeScript: Prefer leading comment when there is a comment on after "?" in conditional types (#8557)
* Fix #8555 * Add changelog
This commit is contained in:
1 parent
ad855e4e03
commit
29959103a9
4 files changed
+48
-1
No files matched your search
@@ -0,0 +1,22 @@
|
||||
#### Prefer leading comment when there is a comment on after "?" in conditional types ([#8557](https://github.com/prettier/prettier/pull/8557) by [@sosukesuzuki](https://github.com/sosukesuzuki))
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```ts
|
||||
// Input
|
||||
type A = B extends T
|
||||
? // comment
|
||||
foo
|
||||
: bar;
|
||||
|
||||
// Prettier stable
|
||||
type A = B extends T // comment
|
||||
? foo
|
||||
: bar;
|
||||
|
||||
// Prettier master
|
||||
type A = B extends T
|
||||
? // comment
|
||||
foo
|
||||
: bar;
|
||||
|
||||
```
|
||||
@@ -407,7 +407,8 @@ function handleConditionalExpressionComments(
|
||||
if (
|
||||
(!precedingNode || !isSameLineAsPrecedingNode) &&
|
||||
enclosingNode &&
|
||||
enclosingNode.type === "ConditionalExpression" &&
|
||||
(enclosingNode.type === "ConditionalExpression" ||
|
||||
enclosingNode.type === "TSConditionalType") &&
|
||||
followingNode
|
||||
) {
|
||||
addLeadingComment(followingNode, comment);
|
||||
|
||||
@@ -1,5 +1,25 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`comments.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
type A = B extends T
|
||||
? // comment
|
||||
foo
|
||||
: bar;
|
||||
|
||||
=====================================output=====================================
|
||||
type A = B extends T
|
||||
? // comment
|
||||
foo
|
||||
: bar;
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`conditonal-types.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
type A = B extends T
|
||||
? // comment
|
||||
foo
|
||||
: bar;
|
||||
Reference in new issue
Block a user