diff --git a/src/babel/transformation/helpers/name-method.js b/src/babel/transformation/helpers/name-method.js index 331a7edd32..fd8d0e0658 100644 --- a/src/babel/transformation/helpers/name-method.js +++ b/src/babel/transformation/helpers/name-method.js @@ -45,6 +45,7 @@ var wrap = function (state, method, id, scope) { } method.id = id; + scope.getProgramParent().references[id.name] = true; }; var visit = function (node, name, scope) { diff --git a/src/babel/transformation/modules/common.js b/src/babel/transformation/modules/common.js index 2fd23d5af1..6d4288b8cb 100644 --- a/src/babel/transformation/modules/common.js +++ b/src/babel/transformation/modules/common.js @@ -70,6 +70,7 @@ export default class CommonJSFormatter extends DefaultFormatter { t.variableDeclarator(variableName, ref) ])); } else { + console.log(variableName.name); // import { foo } from "foo"; this.internalRemap[variableName.name] = t.memberExpression(ref, specifier.imported); } diff --git a/src/babel/traversal/scope/index.js b/src/babel/traversal/scope/index.js index 30490d038e..1425e524af 100644 --- a/src/babel/traversal/scope/index.js +++ b/src/babel/traversal/scope/index.js @@ -44,12 +44,6 @@ var collectorVisitor = { } }, - Scopable(node, parent, scope) { - for (var name in scope.bindings) { - scope.getProgramParent().references[name] = true; - } - }, - ExportDeclaration: { exit(node, parent, scope) { var declar = node.declaration; @@ -459,6 +453,7 @@ export default class Scope { return; } + var parent = this.getProgramParent(); var ids = path.getBindingIdentifiers(); for (var name in ids) { @@ -470,6 +465,8 @@ export default class Scope { this.checkBlockScopedCollisions(local, kind, name, id); } + parent.references[name] = true; + this.bindings[name] = new Binding({ identifier: id, scope: this, diff --git a/test/core/fixtures/transformation/es6.classes/name-method-collision/actual.js b/test/core/fixtures/transformation/es6.classes/name-method-collision/actual.js new file mode 100644 index 0000000000..cdfbf86687 --- /dev/null +++ b/test/core/fixtures/transformation/es6.classes/name-method-collision/actual.js @@ -0,0 +1,7 @@ +import { a } from "./a"; + +class Foo { + _a() { + a(); + } +} diff --git a/test/core/fixtures/transformation/es6.classes/name-method-collision/expected.js b/test/core/fixtures/transformation/es6.classes/name-method-collision/expected.js new file mode 100644 index 0000000000..3bf2306582 --- /dev/null +++ b/test/core/fixtures/transformation/es6.classes/name-method-collision/expected.js @@ -0,0 +1,17 @@ +"use strict"; + +var _a2 = require("./a"); + +var Foo = (function () { + function Foo() { + babelHelpers.classCallCheck(this, Foo); + } + + babelHelpers.createClass(Foo, [{ + key: "_a", + value: function _a() { + (0, _a2.a)(); + } + }]); + return Foo; +})();