@samitouri / QOS-React-2 / commits / 0eeedee95e

[hir] Rewrite identifiers to be consistent

If we resolve identifiers to be different from the binding, update the binding to the new name.

Sathya Gunasekaran committed Mar 31, 2023 at 12:35 UTC 0eeedee95e04563af8092f28fcb75dc65b1da583
6 files changed +8 -4
compiler/forget/src/HIR/HIRBuilder.ts
+5 -1
@@ -219,7 +219,11 @@ export default class HIRBuilder {
219 }
220 }
221
222 - return this.resolveBinding(binding.identifier);
222 + const resolvedBinding = this.resolveBinding(binding.identifier);
223 + if (resolvedBinding.name && resolvedBinding.name !== originalName) {
224 + binding.scope.rename(originalName, resolvedBinding.name);
225 + }
226 + return resolvedBinding;
227 }
228
229 resolveBinding(node: t.Identifier): Identifier {
compiler/forget/src/__tests__/fixtures/compiler/_bug.lambda-reassign-shadowed-primitive.expect.md
+1 -1
@@ -31,7 +31,7 @@ function Component() {
31 const x = t0;
32
33 const fn = function () {
34 - x = 42;
34 + x_0 = 42;
35 };
36 fn();
37 return x;
compiler/forget/src/__tests__/fixtures/compiler/capturing-function-renamed-ref renamed
compiler/forget/src/__tests__/fixtures/compiler/capturing-function-renamed-ref.expect.md renamed
+1 -1
@@ -33,7 +33,7 @@ function component(a, b) {
33
34 const z_0 = { b };
35 (function () {
36 - mutate(z);
36 + mutate(z_0);
37 })();
38 return z;
39 }
compiler/forget/src/__tests__/fixtures/compiler/lambda-mutate-shadowed-object.expect.md renamed
+1 -1
@@ -32,7 +32,7 @@ function Component() {
32
33 const x_0 = [];
34 const fn = function () {
35 - mutate(x);
35 + mutate(x_0);
36 };
37 fn();
38 return x;
compiler/forget/src/__tests__/fixtures/compiler/lambda-mutate-shadowed-object.js renamed