[hotfix T7197] Use scope.moveBindingTo

I had deleted the binding and created a new one. I naively thought that
the analysis will automatically run again. But now discovered the method
I actually want to use: `scope.moveBindingTo` which moves the binding
and all the correct analysis. The only thing that was left to do is to
update `binding.kind` which I did manually.
This commit is contained in:
Amjad Masad 2016-03-09 13:24:20 -08:00
parent 3d5969ecff
commit 8b4b02a5fb
4 changed files with 20 additions and 3 deletions

View File

@ -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,7 +352,6 @@ 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);
}
}

View File

@ -0,0 +1,5 @@
let foo = () => {
foo = () => { };
};
foo();

View File

@ -0,0 +1,5 @@
var _foo = function foo() {
_foo = function foo() {};
};
_foo();

View File

@ -0,0 +1,7 @@
{
"plugins": [
"transform-es2015-arrow-functions",
"transform-es2015-function-name",
"transform-es2015-block-scoping"
]
}