diff --git a/src/babel/transformation/helpers/name-method.js b/src/babel/transformation/helpers/name-method.js index 508f135c5a..97af78f66b 100644 --- a/src/babel/transformation/helpers/name-method.js +++ b/src/babel/transformation/helpers/name-method.js @@ -20,7 +20,7 @@ var visitor = { var wrap = function (state, method, id, scope) { if (state.selfReference) { - if (scope.hasBinding(id.name)) { + if (scope.hasBinding(id.name) && !scope.hasGlobal(id.name)) { // we can just munge the local binding scope.rename(id.name); } else { diff --git a/test/core/fixtures/transformation/spec.function-name/global/actual.js b/test/core/fixtures/transformation/spec.function-name/global/actual.js new file mode 100644 index 0000000000..abd0e6f67b --- /dev/null +++ b/test/core/fixtures/transformation/spec.function-name/global/actual.js @@ -0,0 +1,5 @@ +var test = { + setInterval: function(fn, ms) { + setInterval(fn, ms); + } +}; diff --git a/test/core/fixtures/transformation/spec.function-name/global/expected.js b/test/core/fixtures/transformation/spec.function-name/global/expected.js new file mode 100644 index 0000000000..fc059a98e6 --- /dev/null +++ b/test/core/fixtures/transformation/spec.function-name/global/expected.js @@ -0,0 +1,17 @@ +"use strict"; + +var test = { + setInterval: (function (_setInterval) { + function setInterval(_x, _x2) { + return _setInterval.apply(this, arguments); + } + + setInterval.toString = function () { + return _setInterval.toString(); + }; + + return setInterval; + })(function (fn, ms) { + setInterval(fn, ms); + }) +};