[preset-typescript] Fix private members type annotations (#11315)
This commit is contained in:
parent
296d8ce179
commit
2f549886e4
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
class C {
|
||||
#m(x: number): void {}
|
||||
m(): void;
|
||||
public m(x?: number, ...y: number[]): void {}
|
||||
public constructor() {}
|
||||
|
||||
6
packages/babel-plugin-transform-typescript/test/fixtures/class/methods/options.json
vendored
Normal file
6
packages/babel-plugin-transform-typescript/test/fixtures/class/methods/options.json
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
"transform-typescript",
|
||||
"syntax-class-properties"
|
||||
]
|
||||
}
|
||||
@ -1,4 +1,6 @@
|
||||
class C {
|
||||
#m(x) {}
|
||||
|
||||
m(x, ...y) {}
|
||||
|
||||
constructor() {}
|
||||
|
||||
@ -6,4 +6,6 @@ class C {
|
||||
@foo e: number = 3;
|
||||
f!: number;
|
||||
@foo g!: number;
|
||||
#h: string;
|
||||
#i: number = 10;
|
||||
}
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
{
|
||||
"plugins": ["transform-typescript", ["syntax-decorators", { "legacy": true }]]
|
||||
"plugins": [
|
||||
"transform-typescript",
|
||||
["syntax-decorators", { "legacy": true }],
|
||||
"syntax-class-properties"
|
||||
]
|
||||
}
|
||||
|
||||
@ -7,4 +7,6 @@ class C {
|
||||
e = 3;
|
||||
@foo
|
||||
g;
|
||||
#h;
|
||||
#i = 10;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user