Fix comment around TSParameterProperty (#15324)

This commit is contained in:
fisker Cheung authored and GitHub committed 2023-09-02 09:16:36 +08:00
1 parent 7c7ab7f7a2
commit 958b355ccb
4 files changed
+68 -2

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
#### Fix unstable comment after the last parameter property (#15324 by @fisker)
<!-- prettier-ignore -->
```tsx
// Input
class Class {
constructor(
private readonly paramProp: Type,
// comment
) {
}
}
// Prettier stable
class Class {
constructor(private readonly paramProp: Type) // comment
{}
}
// Prettier stable (Second format)
class Class {
constructor(
private readonly paramProp: Type, // comment
) {}
}
// Prettier main
class Class {
constructor(
private readonly paramProp: Type,
// comment
) {}
}
```
+2 -2
View File
@@ -576,8 +576,8 @@ function handleLastFunctionArgComments({
precedingNode?.type === "AssignmentPattern" ||
precedingNode?.type === "ObjectPattern" ||
precedingNode?.type === "ArrayPattern" ||
precedingNode?.type === "RestElement") &&
enclosingNode &&
precedingNode?.type === "RestElement" ||
precedingNode?.type === "TSParameterProperty") &&
isRealFunctionLikeNode(enclosingNode) &&
getNextNonSpaceNonCommentCharacter(text, locEnd(comment)) === ")"
) {
@@ -694,6 +694,31 @@ export class Point {
================================================================================
`;
exports[`ts-parameter-proerty.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
class A {
constructor(
private readonly paramProp: Type,
// comment
) {
}
}
=====================================output=====================================
class A {
constructor(
private readonly paramProp: Type,
// comment
) {}
}
================================================================================
`;
exports[`type_literals.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
@@ -0,0 +1,7 @@
class A {
constructor(
private readonly paramProp: Type,
// comment
) {
}
}