Fix 'Missing class properties transform' error when parsing class properties with Typescript syntax (#8007)

This commit is contained in:
Alexey Zaslavsky
2018-06-12 20:13:30 +03:00
committed by Henry Zhu
parent b6455c611b
commit 0b25e3327c
3 changed files with 13 additions and 4 deletions

View File

@@ -1,7 +1,6 @@
class C {
// Output should not use `_initialiseProps`
constructor(T) {
this.x = void 0;
this.y = 0;
}

View File

@@ -3,8 +3,6 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
class C {
// Output should not use `_initialiseProps`
constructor(T) {
_defineProperty(this, "x", void 0);
_defineProperty(this, "y", 0);
}

View File

@@ -183,10 +183,22 @@ export default declare((api, { jsxPragma = "React" }) => {
if (node.abstract) node.abstract = null;
},
Class({ node }) {
Class(path) {
const { node } = path;
if (node.typeParameters) node.typeParameters = null;
if (node.superTypeParameters) node.superTypeParameters = null;
if (node.implements) node.implements = null;
// Same logic is used in babel-plugin-transform-flow-strip-types:
// We do this here instead of in a `ClassProperty` visitor because the class transform
// would transform the class before we reached the class property.
path.get("body.body").forEach(child => {
if (child.isClassProperty()) {
child.node.typeAnnotation = null;
if (!child.node.value) child.remove();
}
});
},
Function({ node }) {