diff --git a/compiler/forget/src/__tests__/fixtures/hir/obj-mutated-after-if-else.expect.md b/compiler/forget/src/__tests__/fixtures/hir/obj-mutated-after-if-else.expect.md new file mode 100644 index 0000000000..a963142635 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/obj-mutated-after-if-else.expect.md @@ -0,0 +1,65 @@ + +## Input + +```javascript +function foo(a, b, c, d) { + let x = someObj(); + if (a) { + x = someObj(); + } else { + x = someObj(); + } + + x.f = 1; + return x; +} + +``` + +## Code + +```javascript +function foo(a, b, c, d) { + const $ = React.useMemoCache(); + const x = someObj(); + const c_0 = $[0] !== a; + let x$0; + if (c_0) { + x$0 = undefined; + + if (a) { + let x$1; + + if ($[2] === Symbol.for("react.memo_cache_sentinel")) { + x$1 = someObj(); + $[2] = x$1; + } else { + x$1 = $[2]; + } + + x$0 = x$1; + } else { + let x$2; + + if ($[3] === Symbol.for("react.memo_cache_sentinel")) { + x$2 = someObj(); + $[3] = x$2; + } else { + x$2 = $[3]; + } + + x$0 = x$2; + } + + x$0.f = 1; + $[0] = a; + $[1] = x$0; + } else { + x$0 = $[1]; + } + + return x$0; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/hir/obj-mutated-after-if-else.js b/compiler/forget/src/__tests__/fixtures/hir/obj-mutated-after-if-else.js new file mode 100644 index 0000000000..ed43dec122 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/obj-mutated-after-if-else.js @@ -0,0 +1,11 @@ +function foo(a, b, c, d) { + let x = someObj(); + if (a) { + x = someObj(); + } else { + x = someObj(); + } + + x.f = 1; + return x; +}