diff --git a/packages/babel-plugin-transform-class-properties/src/index.js b/packages/babel-plugin-transform-class-properties/src/index.js index eb6ab6cad8..de42c134a2 100644 --- a/packages/babel-plugin-transform-class-properties/src/index.js +++ b/packages/babel-plugin-transform-class-properties/src/index.js @@ -12,6 +12,9 @@ export default function({ types: t }) { }; const referenceVisitor = { + TypeAnnotation(path) { + path.skip(); + }, ReferencedIdentifier(path) { if (this.scope.hasOwnBinding(path.node.name)) { this.collision = true; diff --git a/packages/babel-plugin-transform-class-properties/test/fixtures/compile-to-class/constructor-collision-ignores-types/actual.js b/packages/babel-plugin-transform-class-properties/test/fixtures/compile-to-class/constructor-collision-ignores-types/actual.js new file mode 100644 index 0000000000..593242cde2 --- /dev/null +++ b/packages/babel-plugin-transform-class-properties/test/fixtures/compile-to-class/constructor-collision-ignores-types/actual.js @@ -0,0 +1,6 @@ +class C { + // Output should not use `_initialiseProps` + x: T; + y = 0; + constructor(T) {} +} diff --git a/packages/babel-plugin-transform-class-properties/test/fixtures/compile-to-class/constructor-collision-ignores-types/expected.js b/packages/babel-plugin-transform-class-properties/test/fixtures/compile-to-class/constructor-collision-ignores-types/expected.js new file mode 100644 index 0000000000..18cbcb0e7e --- /dev/null +++ b/packages/babel-plugin-transform-class-properties/test/fixtures/compile-to-class/constructor-collision-ignores-types/expected.js @@ -0,0 +1,7 @@ +class C { + // Output should not use `_initialiseProps` + constructor(T) { + this.y = 0; + } + +} diff --git a/packages/babel-plugin-transform-class-properties/test/fixtures/compile-to-class/constructor-collision-ignores-types/options.json b/packages/babel-plugin-transform-class-properties/test/fixtures/compile-to-class/constructor-collision-ignores-types/options.json new file mode 100644 index 0000000000..0bdc0309c5 --- /dev/null +++ b/packages/babel-plugin-transform-class-properties/test/fixtures/compile-to-class/constructor-collision-ignores-types/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-typescript", "transform-class-properties"] +}