TypeScript: Don’t breakup call expressions when the last argument is an arrow function with a simple return type (#6106)
parent
4fda7af783
commit
48d542ec1e
|
@ -87,6 +87,29 @@ type G<T> = any;
|
|||
const myFunc = <T,>(arg1: G<T>) => false;
|
||||
```
|
||||
|
||||
### TypeScript: Don’t breakup call expressions when the last argument is an arrow function with a simple return type ([#6106] by [@brainkim])
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```js
|
||||
Fixes [an edge-case](#6099) where we were splitting up call expressions containing arrow functions with simple return types.
|
||||
app.get("/", (req, res): void => {
|
||||
res.send("Hello World!");
|
||||
});
|
||||
|
||||
// Output (Prettier stable)
|
||||
app.get(
|
||||
"/",
|
||||
(req, res): void => {
|
||||
res.send("Hello World!");
|
||||
},
|
||||
);
|
||||
|
||||
// Output (Prettier master)
|
||||
app.get("/", (req, res): void => {
|
||||
res.send("Hello World!");
|
||||
});
|
||||
```
|
||||
|
||||
### JavaScript: Fix closure typecasts without spaces ([#6116] by [@jridgewell])
|
||||
|
||||
Previously, a space was required between the `@type` and opening `{` of a closure typecast, or else the enclosing parenthesis would be removed. Closure itself does not require a space.
|
||||
|
@ -105,7 +128,9 @@ const v = /** @type{string} */ (value);
|
|||
|
||||
[#5979]: https://github.com/prettier/prettier/pull/5979
|
||||
[#6115]: https://github.com/prettier/prettier/pull/6115
|
||||
[#6106]: https://github.com/prettier/prettier/pull/6106
|
||||
[#6116]: https://github.com/prettier/prettier/pull/6116
|
||||
[@jridgewell]: https://github.com/jridgewell
|
||||
[@jwbay]: https://github.com/jwbay
|
||||
[@brainkim]: https://github.com/brainkim
|
||||
[@sosukesuzuki]: https://github.com/sosukesuzuki
|
||||
|
|
|
@ -3716,7 +3716,20 @@ function couldGroupArg(arg) {
|
|||
arg.type === "TSAsExpression" ||
|
||||
arg.type === "FunctionExpression" ||
|
||||
(arg.type === "ArrowFunctionExpression" &&
|
||||
!arg.returnType &&
|
||||
// we want to avoid breaking inside composite return types but not simple keywords
|
||||
// https://github.com/prettier/prettier/issues/4070
|
||||
// export class Thing implements OtherThing {
|
||||
// do: (type: Type) => Provider<Prop> = memoize(
|
||||
// (type: ObjectType): Provider<Opts> => {}
|
||||
// );
|
||||
// }
|
||||
// https://github.com/prettier/prettier/issues/6099
|
||||
// app.get("/", (req, res): void => {
|
||||
// res.send("Hello World!");
|
||||
// });
|
||||
(!arg.returnType ||
|
||||
!arg.returnType.typeAnnotation ||
|
||||
arg.returnType.typeAnnotation.type !== "TSTypeReference") &&
|
||||
(arg.body.type === "BlockStatement" ||
|
||||
arg.body.type === "ArrowFunctionExpression" ||
|
||||
arg.body.type === "ObjectExpression" ||
|
||||
|
|
|
@ -18,6 +18,10 @@ const foo = (x:string):void => (
|
|||
)
|
||||
);
|
||||
|
||||
app.get("/", (req, res): void => {
|
||||
res.send("Hello world");
|
||||
});
|
||||
|
||||
=====================================output=====================================
|
||||
const bar = (...varargs: any[]) => {
|
||||
console.log(varargs);
|
||||
|
@ -25,5 +29,9 @@ const bar = (...varargs: any[]) => {
|
|||
|
||||
const foo = (x: string): void => bar(x, () => {}, () => {});
|
||||
|
||||
app.get("/", (req, res): void => {
|
||||
res.send("Hello world");
|
||||
});
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
|
|
@ -9,3 +9,7 @@ const foo = (x:string):void => (
|
|||
() => {}
|
||||
)
|
||||
);
|
||||
|
||||
app.get("/", (req, res): void => {
|
||||
res.send("Hello world");
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue