diff --git a/src/babel/transformation/transformers/es6/classes.js b/src/babel/transformation/transformers/es6/classes.js index 323534bc63..352dba887d 100644 --- a/src/babel/transformation/transformers/es6/classes.js +++ b/src/babel/transformation/transformers/es6/classes.js @@ -255,9 +255,11 @@ class ClassTransformer { for (var i = 0; i < classBody.length; i++) { var node = classBody[i]; + var path = classBodyPaths[i]; + if (t.isMethodDefinition(node)) { var isConstructor = node.kind === "constructor"; - if (isConstructor) this.verifyConstructor(classBodyPaths[i]); + if (isConstructor) this.verifyConstructor(path); var replaceSupers = new ReplaceSupers({ methodNode: node, @@ -272,7 +274,7 @@ class ClassTransformer { replaceSupers.replace(); if (isConstructor) { - this.pushConstructor(node); + this.pushConstructor(node, path); } else { this.pushMethod(node); } @@ -466,7 +468,13 @@ class ClassTransformer { * Replace the constructor body of our class. */ - pushConstructor(method: { type: "MethodDefinition" }) { + pushConstructor(method: { type: "MethodDefinition" }, path: TraversalPath) { + // https://github.com/babel/babel/issues/1077 + var fnPath = path.get("value"); + if (fnPath.scope.hasOwnBinding(this.classRef.name)) { + fnPath.scope.rename(this.classRef.name); + } + var construct = this.constructor; var fn = method.value; diff --git a/test/core/fixtures/transformation/es6.classes/constructor-binding-collision/actual.js b/test/core/fixtures/transformation/es6.classes/constructor-binding-collision/actual.js new file mode 100644 index 0000000000..522f46589d --- /dev/null +++ b/test/core/fixtures/transformation/es6.classes/constructor-binding-collision/actual.js @@ -0,0 +1,7 @@ +class Example { + constructor() { + var Example; + } +} + +let t = new Example(); diff --git a/test/core/fixtures/transformation/es6.classes/constructor-binding-collision/expected.js b/test/core/fixtures/transformation/es6.classes/constructor-binding-collision/expected.js new file mode 100644 index 0000000000..615341f634 --- /dev/null +++ b/test/core/fixtures/transformation/es6.classes/constructor-binding-collision/expected.js @@ -0,0 +1,9 @@ +"use strict"; + +var Example = function Example() { + babelHelpers.classCallCheck(this, Example); + + var _Example; +}; + +var t = new Example();