Yield expression parens (#16194)

Co-authored-by: fisker Cheung <lionkay@gmail.com>
This commit is contained in:
Kirk Waiblingerandfisker Cheung authored and GitHub committed 2024-04-04 16:39:31 +09:00
1 parent 7982771bd6
commit 48c9bc4aea
4 files changed
+37 -1

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
#### Add necessary parentheses to yield expressions (#16194 by @kirkwaiblinger)
Add parentheses around yield expressions if parent is an angle-bracket type assertion.
<!-- prettier-ignore -->
```ts
// Input
function* g() {
const y = <T>(yield x);
}
// Prettier stable
function* g() {
const y = <T>yield x;
}
// Prettier main
function* g() {
const y = <T>(yield x);
}
```
+4 -1
View File
@@ -472,7 +472,10 @@ function needsParens(path, options) {
} }
case "YieldExpression": case "YieldExpression":
if (parent.type === "AwaitExpression") { if (
parent.type === "AwaitExpression" ||
parent.type === "TSTypeAssertion"
) {
return true; return true;
} }
// else fallthrough // else fallthrough
@@ -355,6 +355,10 @@ true || <x>a;
<x>a + <x>b; <x>a + <x>b;
(<x>a) = 1; (<x>a) = 1;
function * g() {
const a = <T>(yield b);
}
=====================================output===================================== =====================================output=====================================
<DocumentHighlightKind>(a ? b : c); <DocumentHighlightKind>(a ? b : c);
<any>(() => {}); <any>(() => {});
@@ -365,6 +369,10 @@ true || <x>a;
<x>a + <x>b; <x>a + <x>b;
(<x>a) = 1; (<x>a) = 1;
function* g() {
const a = <T>(yield b);
}
================================================================================ ================================================================================
`; `;
@@ -6,3 +6,7 @@
true || <x>a; true || <x>a;
<x>a + <x>b; <x>a + <x>b;
(<x>a) = 1; (<x>a) = 1;
function * g() {
const a = <T>(yield b);
}