fix: avoid line breaks between class members head and key (#12653)

This commit is contained in:
Huáng Jùnliàng 2021-01-23 20:06:01 -05:00 committed by GitHub
parent 8fcba6eb55
commit 446c70c6c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 86 additions and 0 deletions

View File

@ -71,6 +71,11 @@ export function ClassBody(node: Object) {
export function ClassProperty(node: Object) {
this.printJoin(node.decorators, node);
// catch up to property key, avoid line break
// between member modifiers and the property key.
this.source("end", node.key.loc);
this.tsPrintClassMemberModifiers(node, /* isField */ true);
if (node.computed) {
@ -131,6 +136,9 @@ export function ClassPrivateMethod(node: Object) {
export function _classMethodHead(node) {
this.printJoin(node.decorators, node);
// catch up to method key, avoid line break
// between member modifiers/method heads and the method key.
this.source("end", node.key.loc);
this.tsPrintClassMemberModifiers(node, /* isField */ false);
this._methodHead(node);
}

View File

@ -0,0 +1,23 @@
class A {
@decorate
public p = "p"
@decorate
public m() {}
@decorate
private set s
(v) {}
@decorate
public [
cp
]
= "cp"
@decorate
private [
cm
]
() {}
}

View File

@ -0,0 +1 @@
{ "plugins": ["classProperties", "decorators-legacy", "typescript"], "decoratorsBeforeExport": true, "retainLines": true }

View File

@ -0,0 +1,22 @@
class A {
@decorate
public p = "p";
@decorate
public m() {}
@decorate
private set s(
v) {}
@decorate
public [cp] =
"cp";
@decorate
private [cm]()
{}}

View File

@ -0,0 +1,7 @@
class C {
@dec
get a() {}
@dec
set a(v) {}
}

View File

@ -0,0 +1,8 @@
class C {
@dec
get a() {}
@dec
set a(v) {}
}

View File

@ -0,0 +1,9 @@
class C {
@dec
async a() {}
@dec
async *
a(v) {}
}

View File

@ -0,0 +1,8 @@
class C {
@dec
async a() {}
@dec
async *a(v) {}
}