Avoid renaming this bindings in simple arrow function cases.
This commit is contained in:
parent
db3a43869c
commit
51ddeade8a
@ -30,6 +30,7 @@ function remap(path, key, create) {
|
|||||||
|
|
||||||
let shadowFunction = path.node._shadowedFunctionLiteral;
|
let shadowFunction = path.node._shadowedFunctionLiteral;
|
||||||
let currentFunction;
|
let currentFunction;
|
||||||
|
let passedShadowFunction = false;
|
||||||
|
|
||||||
let fnPath = path.findParent(function (path) {
|
let fnPath = path.findParent(function (path) {
|
||||||
if (path.isProgram() || path.isFunction()) {
|
if (path.isProgram() || path.isFunction()) {
|
||||||
@ -38,13 +39,18 @@ function remap(path, key, create) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (path.isProgram()) {
|
if (path.isProgram()) {
|
||||||
|
passedShadowFunction = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (path.isFunction() && !path.isArrowFunctionExpression()) {
|
} else if (path.isFunction() && !path.isArrowFunctionExpression()) {
|
||||||
if (shadowFunction) {
|
if (shadowFunction) {
|
||||||
return path === shadowFunction || path.node === shadowFunction.node;
|
if (path === shadowFunction || path.node === shadowFunction.node) return true;
|
||||||
} else {
|
} else {
|
||||||
return !path.is("shadow");
|
if (!path.is("shadow")) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
passedShadowFunction = true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -53,6 +59,10 @@ function remap(path, key, create) {
|
|||||||
// no point in realiasing if we're in this function
|
// no point in realiasing if we're in this function
|
||||||
if (fnPath === currentFunction) return;
|
if (fnPath === currentFunction) return;
|
||||||
|
|
||||||
|
// If the only functions that were encountered are arrow functions, skip remapping the
|
||||||
|
// binding since arrow function syntax already does that.
|
||||||
|
if (!passedShadowFunction) return;
|
||||||
|
|
||||||
let cached = fnPath.getData(key);
|
let cached = fnPath.getData(key);
|
||||||
if (cached) return path.replaceWith(cached);
|
if (cached) return path.replaceWith(cached);
|
||||||
|
|
||||||
|
|||||||
@ -1,37 +1,34 @@
|
|||||||
let s = function () {
|
let s = function () {
|
||||||
var ref = babelHelpers.asyncToGenerator(function* (x) {
|
var ref = babelHelpers.asyncToGenerator(function* (x) {
|
||||||
let t = (() => {
|
var _this2 = this;
|
||||||
var _this3 = this;
|
|
||||||
|
let t = (() => {
|
||||||
var ref = babelHelpers.asyncToGenerator(function* (y, a) {
|
var ref = babelHelpers.asyncToGenerator(function* (y, a) {
|
||||||
let r = (() => {
|
let r = (() => {
|
||||||
var _this2 = this;
|
var ref = babelHelpers.asyncToGenerator(function* (z, b) {
|
||||||
|
yield z;
|
||||||
var ref = babelHelpers.asyncToGenerator(function* (z, b) {
|
return _this2.x;
|
||||||
yield z;
|
}),
|
||||||
return _this2.x;
|
_this = _this2;
|
||||||
}),
|
|
||||||
_this = this;
|
return function r(_x4, _x5) {
|
||||||
|
return ref.apply(_this, arguments);
|
||||||
return function r(_x4, _x5) {
|
};
|
||||||
return ref.apply(_this, arguments);
|
})();
|
||||||
};
|
yield r();
|
||||||
})();
|
|
||||||
yield r();
|
return _this2.g(r);
|
||||||
|
}),
|
||||||
return _this3.g(r);
|
_this = this;
|
||||||
}),
|
return function t(_x2, _x3) {
|
||||||
_this = this;
|
return ref.apply(_this, arguments);
|
||||||
|
};
|
||||||
return function t(_x2, _x3) {
|
})();
|
||||||
return ref.apply(_this, arguments);
|
|
||||||
};
|
yield t();
|
||||||
})();
|
return this.h(t);
|
||||||
|
});
|
||||||
yield t();
|
return function s(_x) {
|
||||||
return this.h(t);
|
return ref.apply(this, arguments);
|
||||||
});
|
};
|
||||||
return function s(_x) {
|
}();
|
||||||
return ref.apply(this, arguments);
|
|
||||||
};
|
|
||||||
}();
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user