Skip to content

Commit

Permalink
Typescript: Avoid stripping class properties when a decorator is set (#…
Browse files Browse the repository at this point in the history
…8238)

The `babel-plugin-transform-typescript` removes class properties without value regardless if decorators are assigned to it or not.
  • Loading branch information
pmdartus authored and hzoo committed Jul 4, 2018
1 parent afa1207 commit 4d125c3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/babel-plugin-transform-typescript/src/index.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
});
},
Expand Down
Expand Up @@ -2,4 +2,6 @@ class C {
public a?: number;
private b: number = 0;
readonly c!: number = 1;
@foo d: number;
@foo e: number = 3;
}
@@ -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;
}

0 comments on commit 4d125c3

Please sign in to comment.