Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Jan 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {}

}