Indent type assertions in heads of call and member expressions (#10341)
This commit is contained in:
1 parent
31b3351800
commit
42f8271a1e
4 files changed
+80
-4
No files matched your search
@@ -0,0 +1,31 @@
|
||||
#### Indent type assertions in heads of member and call expressions (#10341 by @thorn0)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```ts
|
||||
// Input
|
||||
const getAccountCount = async () =>
|
||||
(await
|
||||
((await (
|
||||
await focusOnSection(BOOKMARKED_PROJECTS_SECTION_NAME)
|
||||
).findItem("My bookmarks")) as TreeItem
|
||||
).getChildren()
|
||||
).length
|
||||
|
||||
// Prettier stable
|
||||
const getAccountCount = async () =>
|
||||
(
|
||||
await ((await (
|
||||
await focusOnSection(BOOKMARKED_PROJECTS_SECTION_NAME)
|
||||
).findItem("My bookmarks")) as TreeItem).getChildren()
|
||||
).length;
|
||||
|
||||
// Prettier main
|
||||
const getAccountCount = async () =>
|
||||
(
|
||||
await (
|
||||
(await (
|
||||
await focusOnSection(BOOKMARKED_PROJECTS_SECTION_NAME)
|
||||
).findItem("My bookmarks")) as TreeItem
|
||||
).getChildren()
|
||||
).length;
|
||||
```
|
||||
@@ -18,6 +18,8 @@ const {
|
||||
isLiteral,
|
||||
getTypeScriptMappedTypeModifier,
|
||||
shouldPrintComma,
|
||||
isCallExpression,
|
||||
isMemberExpression,
|
||||
} = require("../utils");
|
||||
const { locStart, locEnd } = require("../loc");
|
||||
|
||||
@@ -160,12 +162,21 @@ function printTypescript(path, options, print) {
|
||||
return "undefined";
|
||||
case "TSUnknownKeyword":
|
||||
return "unknown";
|
||||
case "TSAsExpression":
|
||||
return [
|
||||
case "TSAsExpression": {
|
||||
parts.push(
|
||||
path.call(print, "expression"),
|
||||
" as ",
|
||||
path.call(print, "typeAnnotation"),
|
||||
];
|
||||
path.call(print, "typeAnnotation")
|
||||
);
|
||||
const parent = path.getParentNode();
|
||||
if (
|
||||
(isCallExpression(parent) && parent.callee === n) ||
|
||||
(isMemberExpression(parent) && parent.object === n)
|
||||
) {
|
||||
return group([indent([softline, ...parts]), softline]);
|
||||
}
|
||||
return parts;
|
||||
}
|
||||
case "TSArrayType":
|
||||
return [path.call(print, "elementType"), "[]"];
|
||||
case "TSPropertySignature": {
|
||||
|
||||
@@ -320,6 +320,33 @@ averredBathersBoxroomBuggyNurl(
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`nested-await-and-as.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
const getAccountCount = async () =>
|
||||
(await
|
||||
((await (
|
||||
await focusOnSection(BOOKMARKED_PROJECTS_SECTION_NAME)
|
||||
).findItem("My bookmarks")) as TreeItem
|
||||
).getChildren()
|
||||
).length
|
||||
|
||||
=====================================output=====================================
|
||||
const getAccountCount = async () =>
|
||||
(
|
||||
await (
|
||||
(await (
|
||||
await focusOnSection(BOOKMARKED_PROJECTS_SECTION_NAME)
|
||||
).findItem("My bookmarks")) as TreeItem
|
||||
).getChildren()
|
||||
).length;
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`return.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
const getAccountCount = async () =>
|
||||
(await
|
||||
((await (
|
||||
await focusOnSection(BOOKMARKED_PROJECTS_SECTION_NAME)
|
||||
).findItem("My bookmarks")) as TreeItem
|
||||
).getChildren()
|
||||
).length
|
||||
Reference in new issue
Block a user