Merge pull request #3298 from babel/hzoo-T7010

Set NOT_LOCAL_BINDING on all inferred function names
This commit is contained in:
Amjad Masad 2016-02-02 16:46:35 -08:00
commit 430607fc1d
5 changed files with 47 additions and 5 deletions

View File

@ -63,11 +63,6 @@ export function push(mutatorMap: Object, node: Object, kind: string, file, scope
// infer function name
if (scope && t.isStringLiteral(key) && (kind === "value" || kind === "initializer") && t.isFunctionExpression(value)) {
value = nameFunction({ id: key, node: value, scope });
// Class methods don't have their name bound in the funciton body.
if (t.isClassMethod(node)) {
value.id[t.NOT_LOCAL_BINDING] = true
}
}
if (value) {

View File

@ -141,6 +141,7 @@ export default function ({ node, parent, scope, id }) {
if (binding && binding.constant && scope.getBinding(id.name) === binding) {
// always going to reference this method
node.id = id;
node.id[t.NOT_LOCAL_BINDING] = true;
return;
}
}
@ -163,6 +164,11 @@ export default function ({ node, parent, scope, id }) {
name = t.toBindingIdentifierName(name);
id = t.identifier(name);
// The id shouldn't be considered a local binding to the function because
// we are simply trying to set the function name and not actually create
// a local binding.
id[t.NOT_LOCAL_BINDING] = true;
let state = visit(node, name, scope);
return wrap(state, node, id, scope) || node;
}

View File

@ -0,0 +1,8 @@
class Foo {
constructor(val){
this._val = val;
}
foo2(){
return foo2(this._val);
}
}

View File

@ -0,0 +1,27 @@
"use strict";
var Foo = function () {
function Foo(val) {
babelHelpers.classCallCheck(this, Foo);
this._val = val;
}
babelHelpers.createClass(Foo, [{
key: "foo2",
value: function (_foo) {
function foo2() {
return _foo.apply(this, arguments);
}
foo2.toString = function () {
return _foo.toString();
};
return foo2;
}(function () {
return foo2(this._val);
})
}]);
return Foo;
}();

View File

@ -0,0 +1,6 @@
{
"plugins": [
"transform-es2015-classes",
"external-helpers"
]
}