Forward bound shadowed function when hoisting identifiers (#4635)
This change ensures that when hoisting an identifier we do not hoist it up to the first no shadowed function, but rather up to the bound shadowed function
This commit is contained in:
committed by
Henry Zhu
parent
f9ccee9d83
commit
5a8070a397
@@ -17,7 +17,7 @@ const superVisitor = {
|
||||
|
||||
export default new Plugin({
|
||||
name: "internal.shadowFunctions",
|
||||
|
||||
|
||||
visitor: {
|
||||
ThisExpression(path) {
|
||||
remap(path, "this");
|
||||
@@ -104,6 +104,10 @@ function remap(path, key) {
|
||||
} else {
|
||||
const init = key === "this" ? t.thisExpression() : t.identifier(key);
|
||||
|
||||
// Forward the shadowed function, so that the identifiers do not get hoisted
|
||||
// up to the first non shadow function but rather up to the bound shadow function
|
||||
if (shadowFunction) init._shadowedFunctionLiteral = shadowFunction;
|
||||
|
||||
fnPath.scope.push({ id, init });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user