Fix missing parentheses around TSInstantiationExpression (#19442)
This commit is contained in:
1 parent
dae99edbe5
commit
d1c3f659ee
6 files changed
+80
No files matched your search
@@ -0,0 +1,25 @@
|
||||
#### Fix missing parentheses around instantiation expression (#19442 by @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```tsx
|
||||
// Input
|
||||
async function* f() {
|
||||
makeRecord = (yield* makeRecordFactory)<ManualValue>;
|
||||
makeRecord = (yield makeRecordFactory)<ManualValue>;
|
||||
makeRecord = (await makeRecordFactory)<ManualValue>;
|
||||
}
|
||||
|
||||
// Prettier stable
|
||||
async function* f() {
|
||||
makeRecord = yield* makeRecordFactory<ManualValue>;
|
||||
makeRecord = yield makeRecordFactory<ManualValue>;
|
||||
makeRecord = await makeRecordFactory<ManualValue>;
|
||||
}
|
||||
|
||||
// Prettier main
|
||||
async function* f() {
|
||||
makeRecord = (yield* makeRecordFactory)<ManualValue>;
|
||||
makeRecord = (yield makeRecordFactory)<ManualValue>;
|
||||
makeRecord = (await makeRecordFactory)<ManualValue>;
|
||||
}
|
||||
```
|
||||
@@ -115,6 +115,16 @@ function parentNeedsParentheses(path, options, needsParentheses) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case "TSInstantiationExpression":
|
||||
if (
|
||||
key === "expression" &&
|
||||
(node.type === "AwaitExpression" || node.type === "YieldExpression")
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
||||
|
||||
exports[`await.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
async function* f() {
|
||||
makeRecord = ( await makeRecordFactory)<ManualValue>
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
async function* f() {
|
||||
makeRecord = (await makeRecordFactory)<ManualValue>;
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`yield.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
async function* f() {
|
||||
makeRecord = ( yield* makeRecordFactory)<ManualValue>
|
||||
makeRecord = ( yield makeRecordFactory)<ManualValue>
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
async function* f() {
|
||||
makeRecord = (yield* makeRecordFactory)<ManualValue>;
|
||||
makeRecord = (yield makeRecordFactory)<ManualValue>;
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -0,0 +1,3 @@
|
||||
async function* f() {
|
||||
makeRecord = ( await makeRecordFactory)<ManualValue>
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
runFormatTest(import.meta, ["typescript"]);
|
||||
@@ -0,0 +1,4 @@
|
||||
async function* f() {
|
||||
makeRecord = ( yield* makeRecordFactory)<ManualValue>
|
||||
makeRecord = ( yield makeRecordFactory)<ManualValue>
|
||||
}
|
||||
Reference in new issue
Block a user