fix: avoid line breaks between class members head and key (#12653)
This commit is contained in:
parent
8fcba6eb55
commit
446c70c6c3
@ -71,6 +71,11 @@ export function ClassBody(node: Object) {
|
|||||||
|
|
||||||
export function ClassProperty(node: Object) {
|
export function ClassProperty(node: Object) {
|
||||||
this.printJoin(node.decorators, node);
|
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);
|
this.tsPrintClassMemberModifiers(node, /* isField */ true);
|
||||||
|
|
||||||
if (node.computed) {
|
if (node.computed) {
|
||||||
@ -131,6 +136,9 @@ export function ClassPrivateMethod(node: Object) {
|
|||||||
|
|
||||||
export function _classMethodHead(node) {
|
export function _classMethodHead(node) {
|
||||||
this.printJoin(node.decorators, 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.tsPrintClassMemberModifiers(node, /* isField */ false);
|
||||||
this._methodHead(node);
|
this._methodHead(node);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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]()
|
||||||
|
|
||||||
|
{}}
|
||||||
7
packages/babel-generator/test/fixtures/decorators/accessor-with-retainlines/input.js
vendored
Normal file
7
packages/babel-generator/test/fixtures/decorators/accessor-with-retainlines/input.js
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class C {
|
||||||
|
@dec
|
||||||
|
get a() {}
|
||||||
|
|
||||||
|
@dec
|
||||||
|
set a(v) {}
|
||||||
|
}
|
||||||
8
packages/babel-generator/test/fixtures/decorators/accessor-with-retainlines/output.js
vendored
Normal file
8
packages/babel-generator/test/fixtures/decorators/accessor-with-retainlines/output.js
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
class C {
|
||||||
|
@dec
|
||||||
|
get a() {}
|
||||||
|
|
||||||
|
@dec
|
||||||
|
set a(v) {}
|
||||||
|
|
||||||
|
}
|
||||||
9
packages/babel-generator/test/fixtures/decorators/async-method-with-retainlines/input.js
vendored
Normal file
9
packages/babel-generator/test/fixtures/decorators/async-method-with-retainlines/input.js
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
class C {
|
||||||
|
@dec
|
||||||
|
async a() {}
|
||||||
|
|
||||||
|
@dec
|
||||||
|
async *
|
||||||
|
a(v) {}
|
||||||
|
|
||||||
|
}
|
||||||
8
packages/babel-generator/test/fixtures/decorators/async-method-with-retainlines/output.js
vendored
Normal file
8
packages/babel-generator/test/fixtures/decorators/async-method-with-retainlines/output.js
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
class C {
|
||||||
|
@dec
|
||||||
|
async a() {}
|
||||||
|
|
||||||
|
@dec
|
||||||
|
async *a(v) {}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user