@samitouri / QOS-React-2 / commits / 1cccd6a815

[hir] Clone babel nodes rather than reusing them

There's state such as scope info sticking on to these nodes so reusing them can cause issues if a pass later on just uses scopes these directly.

Sathya Gunasekaran committed Apr 27, 2023 at 17:35 UTC 1cccd6a81574ea28cd5fac5da73955e9547e0fd6
22 files changed +22 -4
compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts
+1 -1
@@ -895,7 +895,7 @@ function codegenInstructionValue(
895 break;
896 }
897 case "FunctionExpression": {
898 - value = instrValue.expr;
898 + value = t.cloneNode(instrValue.expr, true, true);
899 break;
900 }
901 case "TaggedTemplateExpression": {
compiler/forget/src/__tests__/fixtures/compiler/_bug.capturing-reference-changes-type.expect.md
+1
@@ -23,6 +23,7 @@ function component(a) {
23 (function () {
24 y = x;
25 })();
26 +
27 mutate(1);
28 return 1;
29 }
compiler/forget/src/__tests__/fixtures/compiler/_bug.lambda-reassign-primitive.expect.md
+1
@@ -31,6 +31,7 @@ function Component() {
31 const fn = function () {
32 x = x + 1;
33 };
34 +
35 fn();
36 return 40;
37 }
compiler/forget/src/__tests__/fixtures/compiler/_bug.lambda-reassign-shadowed-primitive.expect.md
+1
@@ -34,6 +34,7 @@ function Component() {
34 const fn = function () {
35 x_0 = 42;
36 };
37 +
38 fn();
39 return x;
40 }
compiler/forget/src/__tests__/fixtures/compiler/capture-param-mutate.expect.md
+1 -3
@@ -58,9 +58,7 @@ function getNativeLogFunction(level) {
58 } else {
59 str = Array.prototype.map
60 .call(arguments, function (arg) {
61 - return inspect(arg, {
62 - depth: 10,
63 - });
61 + return inspect(arg, { depth: 10 });
62 })
63 .join(", ");
64 }
compiler/forget/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-2.expect.md
+1
@@ -33,6 +33,7 @@ function component(foo, bar) {
33 let b = x;
34 a.x = b;
35 })();
36 +
37 mutate(y);
38 $[0] = foo;
39 $[1] = bar;
compiler/forget/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-arr-2.expect.md
+1
@@ -33,6 +33,7 @@ function component(foo, bar) {
33 let b = x;
34 a.x = b;
35 })();
36 +
37 mutate(y);
38 $[0] = foo;
39 $[1] = bar;
compiler/forget/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate-arr.expect.md
+1
@@ -33,6 +33,7 @@ function component(foo, bar) {
33 let b = x;
34 a.x = b;
35 })();
36 +
37 mutate(y);
38 $[0] = foo;
39 $[1] = bar;
compiler/forget/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate.expect.md
+1
@@ -33,6 +33,7 @@ function component(foo, bar) {
33 let b = x;
34 a.x = b;
35 })();
36 +
37 mutate(y);
38 $[0] = foo;
39 $[1] = bar;
compiler/forget/src/__tests__/fixtures/compiler/capturing-func-alias-computed-mutate.expect.md
+1
@@ -28,6 +28,7 @@ function component(a) {
28 (function () {
29 y["x"] = x;
30 })();
31 +
32 mutate(y);
33 $[0] = a;
34 $[1] = y;
compiler/forget/src/__tests__/fixtures/compiler/capturing-func-alias-mutate.expect.md
+1
@@ -28,6 +28,7 @@ function component(a) {
28 (function () {
29 y.x = x;
30 })();
31 +
32 mutate(y);
33 $[0] = a;
34 $[1] = y;
compiler/forget/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-computed-mutate.expect.md
+1
@@ -30,6 +30,7 @@ function component(a) {
30 let a_0 = y;
31 a_0["x"] = x;
32 })();
33 +
34 mutate(y);
35 $[0] = a;
36 $[1] = y;
compiler/forget/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-mutate.expect.md
+1
@@ -30,6 +30,7 @@ function component(a) {
30 let a_0 = y;
31 a_0.x = x;
32 })();
33 +
34 mutate(y);
35 $[0] = a;
36 $[1] = y;
compiler/forget/src/__tests__/fixtures/compiler/capturing-func-mutate-2.expect.md
+1
@@ -40,6 +40,7 @@ function component(a, b) {
40 z.a = 2;
41 y.b;
42 };
43 +
44 x();
45 $[2] = a;
46 $[3] = y.b;
compiler/forget/src/__tests__/fixtures/compiler/capturing-func-mutate-nested.expect.md
+1
@@ -26,6 +26,7 @@ function component(a) {
26 x = function () {
27 y.b.a = 2;
28 };
29 +
30 x();
31 $[0] = a;
32 $[1] = x;
compiler/forget/src/__tests__/fixtures/compiler/capturing-func-mutate.expect.md
+1
@@ -40,6 +40,7 @@ function component(a, b) {
40 z.a = 2;
41 y.b;
42 };
43 +
44 x();
45 $[0] = a;
46 $[1] = b;
compiler/forget/src/__tests__/fixtures/compiler/capturing-func-simple-alias.expect.md
+1
@@ -28,6 +28,7 @@ function component(a) {
28 (function () {
29 y = x;
30 })();
31 +
32 mutate(y);
33 $[0] = a;
34 $[1] = y;
compiler/forget/src/__tests__/fixtures/compiler/capturing-function-capture-ref-before-rename.expect.md
+1
@@ -37,6 +37,7 @@ function component(a, b) {
37 } else {
38 z = $[1];
39 }
40 +
41 let y = z;
42 const c_2 = $[2] !== b;
43 let t0;
compiler/forget/src/__tests__/fixtures/compiler/capturing-function-decl.expect.md
+1
@@ -26,6 +26,7 @@ function component(a) {
26 const x = function x() {
27 t.foo();
28 };
29 +
30 x(t);
31 $[0] = a;
32 $[1] = t;
compiler/forget/src/__tests__/fixtures/compiler/function-declaration-simple.expect.md
+1
@@ -33,6 +33,7 @@ function component(a) {
33 t0 = $[2];
34 }
35 const x = t0;
36 +
37 x(t);
38 $[0] = a;
39 $[1] = t;
compiler/forget/src/__tests__/fixtures/compiler/lambda-capture-returned-alias.expect.md
+1
@@ -54,6 +54,7 @@ function CaptureNotMutate(props) {
54 const arr = { element };
55 return arr[idx];
56 };
57 +
58 aliasedElement = fn();
59 mutate(aliasedElement);
60 $[2] = props.el;
compiler/forget/src/__tests__/fixtures/compiler/lambda-mutate-shadowed-object.expect.md
+1
@@ -35,6 +35,7 @@ function Component() {
35 const fn = function () {
36 mutate(x_0);
37 };
38 +
39 fn();
40 return x;
41 }