From 0894e35d94fa84136e68403c7135c276a5f7898a Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Fri, 19 Jan 2024 19:12:58 -0800 Subject: [PATCH] More fixtures for reactivity and mutable aliasing (property load case) --- ...d-mutation-through-property-load.expect.md | 87 +++++++++++++++++++ ...-aliased-mutation-through-property-load.js | 28 ++++++ 2 files changed, 115 insertions(+) create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-through-property-load.expect.md create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-through-property-load.js diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-through-property-load.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-through-property-load.expect.md new file mode 100644 index 0000000000..cb63403c90 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-through-property-load.expect.md @@ -0,0 +1,87 @@ + +## Input + +```javascript +function Component(props) { + const x = {}; + const y = []; + x.y = y; + x.y.push(props.input); + + let z = 0; + if (x.y[0]) { + z = 1; + } + + return [z]; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [], + sequentialRenders: [ + { input: true }, + { input: true }, + { input: false }, + { input: false }, + { input: true }, + { input: false }, + { input: true }, + { input: false }, + ], +}; + +``` + +## Code + +```javascript +import { unstable_useMemoCache as useMemoCache } from "react"; +function Component(props) { + const $ = useMemoCache(2); + const x = {}; + const y = []; + x.y = y; + x.y.push(props.input); + + let z = 0; + if (x.y[0]) { + z = 1; + } + let t0; + if ($[0] !== z) { + t0 = [z]; + $[0] = z; + $[1] = t0; + } else { + t0 = $[1]; + } + return t0; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [], + sequentialRenders: [ + { input: true }, + { input: true }, + { input: false }, + { input: false }, + { input: true }, + { input: false }, + { input: true }, + { input: false }, + ], +}; + +``` + +### Eval output +(kind: ok) [1] +[1] +[0] +[0] +[1] +[0] +[1] +[0] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-through-property-load.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-through-property-load.js new file mode 100644 index 0000000000..a691e135fa --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reactivity-via-aliased-mutation-through-property-load.js @@ -0,0 +1,28 @@ +function Component(props) { + const x = {}; + const y = []; + x.y = y; + x.y.push(props.input); + + let z = 0; + if (x.y[0]) { + z = 1; + } + + return [z]; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [], + sequentialRenders: [ + { input: true }, + { input: true }, + { input: false }, + { input: false }, + { input: true }, + { input: false }, + { input: true }, + { input: false }, + ], +};