diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/compile-to-class/constructor-collision-ignores-types-loose/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/compile-to-class/constructor-collision-ignores-types-loose/output.js index 688eb31db9..18cbcb0e7e 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/compile-to-class/constructor-collision-ignores-types-loose/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/compile-to-class/constructor-collision-ignores-types-loose/output.js @@ -1,7 +1,6 @@ class C { // Output should not use `_initialiseProps` constructor(T) { - this.x = void 0; this.y = 0; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/compile-to-class/constructor-collision-ignores-types/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/compile-to-class/constructor-collision-ignores-types/output.js index e6d715c07a..c85b2477ed 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/compile-to-class/constructor-collision-ignores-types/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/compile-to-class/constructor-collision-ignores-types/output.js @@ -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); } diff --git a/packages/babel-plugin-transform-typescript/src/index.js b/packages/babel-plugin-transform-typescript/src/index.js index ac1e51d477..6e685b9f69 100644 --- a/packages/babel-plugin-transform-typescript/src/index.js +++ b/packages/babel-plugin-transform-typescript/src/index.js @@ -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 }) {