Fix line comments jumping past member lookups in as expressions (#18522)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
64484a41be
commit
f2f97751a1
5 files changed
+79
-2
No files matched your search
@@ -0,0 +1,35 @@
|
||||
#### Fix line comments jumping past member expression lookups (#18522 by @ulrichstark)
|
||||
|
||||
Line comments between a member expression object and property were incorrectly moved past subsequent content like `as` expressions.
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```tsx
|
||||
// Input
|
||||
function getClassNameFromPrototypeMethod(container) {
|
||||
return ((container // a
|
||||
.left as PropertyAccessExpression) // b
|
||||
.expression as PropertyAccessExpression) // c
|
||||
.expression; // d
|
||||
}
|
||||
|
||||
// Prettier stable
|
||||
function getClassNameFromPrototypeMethod(container) {
|
||||
return (
|
||||
(
|
||||
container.left as PropertyAccessExpression // a
|
||||
).expression as PropertyAccessExpression // b
|
||||
).expression; // c // d
|
||||
}
|
||||
|
||||
// Prettier main
|
||||
function getClassNameFromPrototypeMethod(container) {
|
||||
return (
|
||||
(
|
||||
container // a
|
||||
.left as PropertyAccessExpression
|
||||
) // b
|
||||
.expression as PropertyAccessExpression
|
||||
) // c
|
||||
.expression; // d
|
||||
}
|
||||
```
|
||||
@@ -1,4 +1,10 @@
|
||||
import { group, indent, label, softline } from "../../document/index.js";
|
||||
import {
|
||||
group,
|
||||
indent,
|
||||
label,
|
||||
lineSuffixBoundary,
|
||||
softline,
|
||||
} from "../../document/index.js";
|
||||
import {
|
||||
getCallArguments,
|
||||
isCallExpression,
|
||||
@@ -62,6 +68,7 @@ function printMemberExpression(path, options, print) {
|
||||
|
||||
return label(objectDoc.label, [
|
||||
objectDoc,
|
||||
lineSuffixBoundary,
|
||||
shouldInline ? lookupDoc : group(indent([softline, lookupDoc])),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -220,7 +220,8 @@ a = \`\${[[1, 2, 3], [4, 5, 6]]}\`
|
||||
|
||||
=====================================output=====================================
|
||||
const long1 = \`long \${
|
||||
a.b //comment
|
||||
a //comment
|
||||
.b
|
||||
} long longlong \${a.b.c.d.e} long longlong \${a.b.c.d.e} long longlong \${a.b.c.d.e} long long\`;
|
||||
const long2 = \`long \${a.b.c.d.e} long longlong \${loooooooooooooooooong} long longlong \${loooooooooooooooooong} long longlong \${loooooooooooooooooong} long long\`;
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
function getClassNameFromPrototypeMethod(container) {
|
||||
return ((container // a
|
||||
.left as PropertyAccessExpression) // b
|
||||
.expression as PropertyAccessExpression) // c
|
||||
.expression; // d
|
||||
}
|
||||
@@ -1,5 +1,33 @@
|
||||
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
||||
|
||||
exports[`17407.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript", "flow"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
function getClassNameFromPrototypeMethod(container) {
|
||||
return ((container // a
|
||||
.left as PropertyAccessExpression) // b
|
||||
.expression as PropertyAccessExpression) // c
|
||||
.expression; // d
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
function getClassNameFromPrototypeMethod(container) {
|
||||
return (
|
||||
(
|
||||
container // a
|
||||
.left as PropertyAccessExpression
|
||||
) // b
|
||||
.expression as PropertyAccessExpression
|
||||
) // c
|
||||
.expression; // d
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`18160.ts [hermes] format 1`] = `
|
||||
"';' expected (7:2)
|
||||
5 | comment
|
||||
|
||||
Reference in new issue
Block a user