[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) {
|
if (!node.decorators) {
|
||||||
path.remove();
|
path.remove();
|
||||||
}
|
}
|
||||||
} else if (!allowDeclareFields && !node.value && !node.decorators) {
|
} else if (
|
||||||
|
!allowDeclareFields &&
|
||||||
|
!node.value &&
|
||||||
|
!node.decorators &&
|
||||||
|
!t.isClassPrivateProperty(node)
|
||||||
|
) {
|
||||||
path.remove();
|
path.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,13 +330,16 @@ export default declare(
|
|||||||
// class transform would transform the class, causing more specific
|
// class transform would transform the class, causing more specific
|
||||||
// visitors to not run.
|
// visitors to not run.
|
||||||
path.get("body.body").forEach(child => {
|
path.get("body.body").forEach(child => {
|
||||||
if (child.isClassMethod()) {
|
if (child.isClassMethod() || child.isClassPrivateMethod()) {
|
||||||
if (child.node.kind === "constructor") {
|
if (child.node.kind === "constructor") {
|
||||||
classMemberVisitors.constructor(child, path);
|
classMemberVisitors.constructor(child, path);
|
||||||
} else {
|
} else {
|
||||||
classMemberVisitors.method(child, path);
|
classMemberVisitors.method(child, path);
|
||||||
}
|
}
|
||||||
} else if (child.isClassProperty()) {
|
} else if (
|
||||||
|
child.isClassProperty() ||
|
||||||
|
child.isClassPrivateProperty()
|
||||||
|
) {
|
||||||
classMemberVisitors.field(child, path);
|
classMemberVisitors.field(child, path);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
class C {
|
class C {
|
||||||
|
#m(x: number): void {}
|
||||||
m(): void;
|
m(): void;
|
||||||
public m(x?: number, ...y: number[]): void {}
|
public m(x?: number, ...y: number[]): void {}
|
||||||
public constructor() {}
|
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 {
|
class C {
|
||||||
|
#m(x) {}
|
||||||
|
|
||||||
m(x, ...y) {}
|
m(x, ...y) {}
|
||||||
|
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|||||||
@ -6,4 +6,6 @@ class C {
|
|||||||
@foo e: number = 3;
|
@foo e: number = 3;
|
||||||
f!: number;
|
f!: number;
|
||||||
@foo g!: 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;
|
e = 3;
|
||||||
@foo
|
@foo
|
||||||
g;
|
g;
|
||||||
|
#h;
|
||||||
|
#i = 10;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user