Merge pull request #3411 from babel/hotfix-7197
[hotfix T7197] Use scope.moveBindingTo
This commit is contained in:
commit
facf6bc82f
@ -90,9 +90,10 @@ function convertBlockScopedToVar(path, parent, scope, moveBindingsToParent = fal
|
||||
const parentScope = scope.getFunctionParent();
|
||||
const ids = path.getBindingIdentifiers();
|
||||
for (let name in ids) {
|
||||
scope.removeOwnBinding(name);
|
||||
let binding = scope.getOwnBinding(name);
|
||||
if (binding) binding.kind = "var";
|
||||
scope.moveBindingTo(name, parentScope);
|
||||
}
|
||||
parentScope.registerBinding("var", path);
|
||||
}
|
||||
}
|
||||
|
||||
@ -351,8 +352,8 @@ class BlockScoping {
|
||||
const binding = scope.getBinding(ref.name);
|
||||
if (!binding) continue;
|
||||
if (binding.kind === "let" || binding.kind === "const") {
|
||||
scope.removeOwnBinding(ref.name);
|
||||
parentScope.registerBinding("var", binding.path);
|
||||
binding.kind = "var";
|
||||
scope.moveBindingTo(ref.name, parentScope);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
let foo = () => {
|
||||
foo = () => { };
|
||||
};
|
||||
|
||||
foo();
|
||||
@ -0,0 +1,5 @@
|
||||
var _foo = function foo() {
|
||||
_foo = function foo() {};
|
||||
};
|
||||
|
||||
_foo();
|
||||
@ -0,0 +1,7 @@
|
||||
{
|
||||
"plugins": [
|
||||
"transform-es2015-arrow-functions",
|
||||
"transform-es2015-function-name",
|
||||
"transform-es2015-block-scoping"
|
||||
]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user