[hir] Rewrite identifiers to be consistent

If we resolve identifiers to be different from the binding, update the binding 
to the new name.
This commit is contained in:
Sathya Gunasekaran
2023-03-31 12:35:17 +01:00
parent 3b3d15eaeb
commit 0eeedee95e
6 changed files with 8 additions and 4 deletions
+5 -1
View File
@@ -219,7 +219,11 @@ export default class HIRBuilder {
}
}
return this.resolveBinding(binding.identifier);
const resolvedBinding = this.resolveBinding(binding.identifier);
if (resolvedBinding.name && resolvedBinding.name !== originalName) {
binding.scope.rename(originalName, resolvedBinding.name);
}
return resolvedBinding;
}
resolveBinding(node: t.Identifier): Identifier {
@@ -31,7 +31,7 @@ function Component() {
const x = t0;
const fn = function () {
x = 42;
x_0 = 42;
};
fn();
return x;
@@ -33,7 +33,7 @@ function component(a, b) {
const z_0 = { b };
(function () {
mutate(z);
mutate(z_0);
})();
return z;
}
@@ -32,7 +32,7 @@ function Component() {
const x_0 = [];
const fn = function () {
mutate(x);
mutate(x_0);
};
fn();
return x;