Merge pull request #3298 from babel/hzoo-T7010
Set NOT_LOCAL_BINDING on all inferred function names
This commit is contained in:
commit
430607fc1d
@ -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) {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
8
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T7010/actual.js
vendored
Normal file
8
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T7010/actual.js
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
class Foo {
|
||||
constructor(val){
|
||||
this._val = val;
|
||||
}
|
||||
foo2(){
|
||||
return foo2(this._val);
|
||||
}
|
||||
}
|
||||
27
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T7010/expected.js
vendored
Normal file
27
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T7010/expected.js
vendored
Normal 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;
|
||||
}();
|
||||
6
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T7010/options.json
vendored
Normal file
6
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T7010/options.json
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
"transform-es2015-classes",
|
||||
"external-helpers"
|
||||
]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user