Typescript: Avoid stripping class properties when a decorator is set (#8238)
The `babel-plugin-transform-typescript` removes class properties without value regardless if decorators are assigned to it or not.
This commit is contained in:
committed by
Henry Zhu
parent
afa1207224
commit
4d125c391a
@@ -157,10 +157,6 @@ export default declare((api, { jsxPragma = "React" }) => {
|
||||
|
||||
ClassProperty(path) {
|
||||
const { node } = path;
|
||||
if (!node.value) {
|
||||
path.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
if (node.accessibility) node.accessibility = null;
|
||||
if (node.abstract) node.abstract = null;
|
||||
@@ -196,7 +192,10 @@ export default declare((api, { jsxPragma = "React" }) => {
|
||||
path.get("body.body").forEach(child => {
|
||||
if (child.isClassProperty()) {
|
||||
child.node.typeAnnotation = null;
|
||||
if (!child.node.value) child.remove();
|
||||
|
||||
if (!child.node.value && !child.node.decorators) {
|
||||
child.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -2,4 +2,6 @@ class C {
|
||||
public a?: number;
|
||||
private b: number = 0;
|
||||
readonly c!: number = 1;
|
||||
@foo d: number;
|
||||
@foo e: number = 3;
|
||||
}
|
||||
|
||||
6
packages/babel-plugin-transform-typescript/test/fixtures/class/properties/options.json
vendored
Normal file
6
packages/babel-plugin-transform-typescript/test/fixtures/class/properties/options.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
"transform-typescript",
|
||||
["syntax-decorators", { "legacy": true }]
|
||||
]
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
class C {
|
||||
b = 0;
|
||||
c = 1;
|
||||
@foo
|
||||
d;
|
||||
@foo
|
||||
e = 3;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user