[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:
parent
3d5969ecff
commit
8b4b02a5fb
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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