From 568048af0f3eccb8cd450158eb140bdb811e13c8 Mon Sep 17 00:00:00 2001 From: mofeiZ <34200447+mofeiZ@users.noreply.github.com> Date: Fri, 24 Mar 2023 15:23:42 -0400 Subject: [PATCH] [tests] failing tests for dependencies and codegen (#1414) --- ..._bug.nested-optional-member-expr.expect.md | 31 ++++++++++++++++ .../_bug.nested-optional-member-expr.js | 4 +++ .../_bug.primitive-computed-load.expect.md | 35 +++++++++++++++++++ .../compiler/_bug.primitive-computed-load.js | 9 +++++ 4 files changed, 79 insertions(+) create mode 100644 compiler/forget/src/__tests__/fixtures/compiler/_bug.nested-optional-member-expr.expect.md create mode 100644 compiler/forget/src/__tests__/fixtures/compiler/_bug.nested-optional-member-expr.js create mode 100644 compiler/forget/src/__tests__/fixtures/compiler/_bug.primitive-computed-load.expect.md create mode 100644 compiler/forget/src/__tests__/fixtures/compiler/_bug.primitive-computed-load.js diff --git a/compiler/forget/src/__tests__/fixtures/compiler/_bug.nested-optional-member-expr.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/_bug.nested-optional-member-expr.expect.md new file mode 100644 index 0000000000..9d33267161 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/compiler/_bug.nested-optional-member-expr.expect.md @@ -0,0 +1,31 @@ + +## Input + +```javascript +function Component(props) { + let x = foo(props.a?.b.c.d); + return x; +} + +``` + +## Code + +```javascript +function Component(props) { + const $ = React.unstable_useMemoCache(2); + const c_0 = $[0] !== props.a.b.c.d; + let t0; + if (c_0) { + t0 = foo(props.a?.b?.c?.d); + $[0] = props.a.b.c.d; + $[1] = t0; + } else { + t0 = $[1]; + } + const x = t0; + return x; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/compiler/_bug.nested-optional-member-expr.js b/compiler/forget/src/__tests__/fixtures/compiler/_bug.nested-optional-member-expr.js new file mode 100644 index 0000000000..63561f207c --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/compiler/_bug.nested-optional-member-expr.js @@ -0,0 +1,4 @@ +function Component(props) { + let x = foo(props.a?.b.c.d); + return x; +} diff --git a/compiler/forget/src/__tests__/fixtures/compiler/_bug.primitive-computed-load.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/_bug.primitive-computed-load.expect.md new file mode 100644 index 0000000000..7886b720d0 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/compiler/_bug.primitive-computed-load.expect.md @@ -0,0 +1,35 @@ + +## Input + +```javascript +function Component(props) { + let a = foo(); + // freeze `a` so we know the next line cannot mutate it +
{a}
; + + // b should be dependent on `props.a` + let b = bar(a[props.a] + 1); + return b; +} + +``` + +## Code + +```javascript +function Component(props) { + const $ = React.unstable_useMemoCache(1); + const a = foo(); + let t0; + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { + t0 = bar(a[props.a] + 1); + $[0] = t0; + } else { + t0 = $[0]; + } + const b = t0; + return b; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/compiler/_bug.primitive-computed-load.js b/compiler/forget/src/__tests__/fixtures/compiler/_bug.primitive-computed-load.js new file mode 100644 index 0000000000..e6d2c795c3 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/compiler/_bug.primitive-computed-load.js @@ -0,0 +1,9 @@ +function Component(props) { + let a = foo(); + // freeze `a` so we know the next line cannot mutate it +
{a}
; + + // b should be dependent on `props.a` + let b = bar(a[props.a] + 1); + return b; +}