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:
Pierre-Marie Dartus
2018-07-04 04:44:33 -07:00
committed by Henry Zhu
parent afa1207224
commit 4d125c391a
4 changed files with 16 additions and 5 deletions

View File

@@ -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();
}
}
});
},

View File

@@ -2,4 +2,6 @@ class C {
public a?: number;
private b: number = 0;
readonly c!: number = 1;
@foo d: number;
@foo e: number = 3;
}

View File

@@ -0,0 +1,6 @@
{
"plugins": [
"transform-typescript",
["syntax-decorators", { "legacy": true }]
]
}

View File

@@ -1,4 +1,8 @@
class C {
b = 0;
c = 1;
@foo
d;
@foo
e = 3;
}