Skip to content

Commit

Permalink
fix: avoid line breaks between class members head and key (#12653)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jan 24, 2021
1 parent 8fcba6e commit 446c70c
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/babel-generator/src/generators/classes.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
@@ -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
]
() {}
}
@@ -0,0 +1 @@
{ "plugins": ["classProperties", "decorators-legacy", "typescript"], "decoratorsBeforeExport": true, "retainLines": true }
@@ -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]()

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

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

@dec
set a(v) {}

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

@dec
async *
a(v) {}

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

@dec
async *a(v) {}

}

0 comments on commit 446c70c

Please sign in to comment.