Fix comments on class methods with decorators (#16891)
This commit is contained in:
1 parent
359c4f02d0
commit
572bebe2d4
4 files changed
+253
-1
No files matched your search
@@ -0,0 +1,40 @@
|
|||||||
|
#### Fix comments print on class methods with decorators (#16891 by @fisker)
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
```jsx
|
||||||
|
// Input
|
||||||
|
class A {
|
||||||
|
@decorator
|
||||||
|
/**
|
||||||
|
* The method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
async method(foo: Foo, bar: Bar) {
|
||||||
|
console.log(foo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prettier stable
|
||||||
|
class A {
|
||||||
|
@decorator
|
||||||
|
async /**
|
||||||
|
* The method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
method(foo: Foo, bar: Bar) {
|
||||||
|
console.log(foo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prettier main
|
||||||
|
class A {
|
||||||
|
@decorator
|
||||||
|
/**
|
||||||
|
* The method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
async method(foo: Foo, bar: Bar) {
|
||||||
|
console.log(foo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -543,7 +543,7 @@ function handleMethodNameComments({
|
|||||||
if (
|
if (
|
||||||
precedingNode?.type === "Decorator" &&
|
precedingNode?.type === "Decorator" &&
|
||||||
propertyLikeNodeTypes.has(enclosingNode?.type) &&
|
propertyLikeNodeTypes.has(enclosingNode?.type) &&
|
||||||
isLineComment(comment)
|
(isLineComment(comment) || comment.placement === "ownLine")
|
||||||
) {
|
) {
|
||||||
addTrailingComment(precedingNode, comment);
|
addTrailingComment(precedingNode, comment);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
class A {
|
||||||
|
@decorator
|
||||||
|
/**
|
||||||
|
* The method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator/**
|
||||||
|
* The method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator/**
|
||||||
|
* The method description
|
||||||
|
*
|
||||||
|
*/ async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
async /* comment */ method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator /* comment */ async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
// line comment
|
||||||
|
async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator // line comment
|
||||||
|
async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
/* comment */
|
||||||
|
public async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
/* comment */
|
||||||
|
static async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
/* comment */
|
||||||
|
protected async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
/* comment */
|
||||||
|
protected async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
/* comment */
|
||||||
|
* method() {}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
* /* comment */ method() {}
|
||||||
|
|
||||||
|
/* comment */
|
||||||
|
abstract method():void;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -248,6 +248,147 @@ class Foo {
|
|||||||
================================================================================
|
================================================================================
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`16889.ts format 1`] = `
|
||||||
|
====================================options=====================================
|
||||||
|
parsers: ["typescript"]
|
||||||
|
printWidth: 80
|
||||||
|
| printWidth
|
||||||
|
=====================================input======================================
|
||||||
|
class A {
|
||||||
|
@decorator
|
||||||
|
/**
|
||||||
|
* The method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator/**
|
||||||
|
* The method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator/**
|
||||||
|
* The method description
|
||||||
|
*
|
||||||
|
*/ async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
async /* comment */ method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator /* comment */ async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
// line comment
|
||||||
|
async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator // line comment
|
||||||
|
async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
/* comment */
|
||||||
|
public async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
/* comment */
|
||||||
|
static async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
/* comment */
|
||||||
|
protected async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
/* comment */
|
||||||
|
protected async method() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
/* comment */
|
||||||
|
* method() {}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
* /* comment */ method() {}
|
||||||
|
|
||||||
|
/* comment */
|
||||||
|
abstract method():void;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
=====================================output=====================================
|
||||||
|
class A {
|
||||||
|
@decorator
|
||||||
|
/**
|
||||||
|
* The method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
async method() {}
|
||||||
|
|
||||||
|
@decorator /**
|
||||||
|
* The method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
async method() {}
|
||||||
|
|
||||||
|
@decorator /**
|
||||||
|
* The method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
async method() {}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
async /* comment */ method() {}
|
||||||
|
|
||||||
|
@decorator /* comment */ async method() {}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
// line comment
|
||||||
|
async method() {}
|
||||||
|
|
||||||
|
@decorator // line comment
|
||||||
|
async method() {}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
/* comment */
|
||||||
|
public async method() {}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
/* comment */
|
||||||
|
static async method() {}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
/* comment */
|
||||||
|
protected async method() {}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
/* comment */
|
||||||
|
protected async method() {}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
/* comment */
|
||||||
|
*method() {}
|
||||||
|
|
||||||
|
@decorator
|
||||||
|
*/* comment */ method() {}
|
||||||
|
|
||||||
|
/* comment */
|
||||||
|
abstract method(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`abstract_class.ts format 1`] = `
|
exports[`abstract_class.ts format 1`] = `
|
||||||
====================================options=====================================
|
====================================options=====================================
|
||||||
parsers: ["typescript"]
|
parsers: ["typescript"]
|
||||||
|
|||||||
Reference in new issue
Block a user