[preset-typescript] Fix private members type annotations (#11315)

This commit is contained in:
Vlad Rindevich 2020-03-23 21:33:16 +03:00 committed by GitHub
parent 296d8ce179
commit 2f549886e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 4 deletions

View File

@ -78,7 +78,12 @@ export default declare(
if (!node.decorators) {
path.remove();
}
} else if (!allowDeclareFields && !node.value && !node.decorators) {
} else if (
!allowDeclareFields &&
!node.value &&
!node.decorators &&
!t.isClassPrivateProperty(node)
) {
path.remove();
}
@ -325,13 +330,16 @@ export default declare(
// class transform would transform the class, causing more specific
// visitors to not run.
path.get("body.body").forEach(child => {
if (child.isClassMethod()) {
if (child.isClassMethod() || child.isClassPrivateMethod()) {
if (child.node.kind === "constructor") {
classMemberVisitors.constructor(child, path);
} else {
classMemberVisitors.method(child, path);
}
} else if (child.isClassProperty()) {
} else if (
child.isClassProperty() ||
child.isClassPrivateProperty()
) {
classMemberVisitors.field(child, path);
}
});

View File

@ -1,4 +1,5 @@
class C {
#m(x: number): void {}
m(): void;
public m(x?: number, ...y: number[]): void {}
public constructor() {}

View File

@ -0,0 +1,6 @@
{
"plugins": [
"transform-typescript",
"syntax-class-properties"
]
}

View File

@ -1,4 +1,6 @@
class C {
#m(x) {}
m(x, ...y) {}
constructor() {}

View File

@ -6,4 +6,6 @@ class C {
@foo e: number = 3;
f!: number;
@foo g!: number;
#h: string;
#i: number = 10;
}

View File

@ -1,3 +1,7 @@
{
"plugins": ["transform-typescript", ["syntax-decorators", { "legacy": true }]]
"plugins": [
"transform-typescript",
["syntax-decorators", { "legacy": true }],
"syntax-class-properties"
]
}

View File

@ -7,4 +7,6 @@ class C {
e = 3;
@foo
g;
#h;
#i = 10;
}