diff --git a/compiler/packages/babel-plugin-react-forget/src/Inference/InferReferenceEffects.ts b/compiler/packages/babel-plugin-react-forget/src/Inference/InferReferenceEffects.ts index 23f66247a7..6b76c4aae7 100644 --- a/compiler/packages/babel-plugin-react-forget/src/Inference/InferReferenceEffects.ts +++ b/compiler/packages/babel-plugin-react-forget/src/Inference/InferReferenceEffects.ts @@ -1640,17 +1640,6 @@ function inferBlock( const lvalue = instr.lvalue; lvalue.effect = Effect.ConditionallyMutate; const valueKind = state.kind(instrValue.place); - CompilerError.invariant( - valueKind.kind === ValueKind.Mutable || - valueKind.kind === ValueKind.Context, - { - reason: - "[InferReferenceEffects] Context variables are always mutable.", - description: null, - loc: instrValue.loc, - suggestions: null, - } - ); state.initialize(instrValue, valueKind); state.define(lvalue, instrValue); continue; diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-multiple-calls-to-hoisted-callback-from-other-callback.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-multiple-calls-to-hoisted-callback-from-other-callback.expect.md deleted file mode 100644 index 76d1c69c04..0000000000 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-multiple-calls-to-hoisted-callback-from-other-callback.expect.md +++ /dev/null @@ -1,46 +0,0 @@ - -## Input - -```javascript -// @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions -function Component(props) { - const [_state, setState] = useState(); - const a = () => { - return b(); - }; - const b = () => { - return ( - <> -
onClick(true)} /> -
onClick(false)} /> - - ); - }; - const onClick = (value) => { - setState(value); - }; - - return
{a()}
; -} - -export const FIXTURE_ENTRYPONT = { - fn: Component, - props: [{}], -}; - -``` - - -## Error - -``` - 9 | <> - 10 |
onClick(true)} /> -> 11 |
onClick(false)} /> - | ^^^^^^^ Invariant: [InferReferenceEffects] Context variables are always mutable. (11:11) - 12 | - 13 | ); - 14 | }; -``` - - \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/multiple-calls-to-hoisted-callback-from-other-callback.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/multiple-calls-to-hoisted-callback-from-other-callback.expect.md new file mode 100644 index 0000000000..8315f0b47d --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/multiple-calls-to-hoisted-callback-from-other-callback.expect.md @@ -0,0 +1,73 @@ + +## Input + +```javascript +import { useState } from "react"; + +function Component(props) { + const [_state, setState] = useState(); + const a = () => { + return b(); + }; + const b = () => { + return ( + <> +
onClick(true)}>a
+
onClick(false)}>b
+ + ); + }; + const onClick = (value) => { + setState(value); + }; + + return
{a()}
; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{}], +}; + +``` + +## Code + +```javascript +import { useState, unstable_useMemoCache as useMemoCache } from "react"; + +function Component(props) { + const $ = useMemoCache(1); + const [_state, setState] = useState(); + let t0; + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { + const a = () => b(); + + const b = () => ( + <> +
onClick(true)}>a
+
onClick(false)}>b
+ + ); + + const onClick = (value) => { + setState(value); + }; + + t0 =
{a()}
; + $[0] = t0; + } else { + t0 = $[0]; + } + return t0; +} + +export const FIXTURE_ENTRYPOINT = { + fn: Component, + params: [{}], +}; + +``` + +### Eval output +(kind: ok)
a
b
\ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-multiple-calls-to-hoisted-callback-from-other-callback.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/multiple-calls-to-hoisted-callback-from-other-callback.js similarity index 55% rename from compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-multiple-calls-to-hoisted-callback-from-other-callback.js rename to compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/multiple-calls-to-hoisted-callback-from-other-callback.js index fa91f3b0f4..9467a91031 100644 --- a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-multiple-calls-to-hoisted-callback-from-other-callback.js +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/multiple-calls-to-hoisted-callback-from-other-callback.js @@ -1,4 +1,5 @@ -// @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions +import { useState } from "react"; + function Component(props) { const [_state, setState] = useState(); const a = () => { @@ -7,8 +8,8 @@ function Component(props) { const b = () => { return ( <> -
onClick(true)} /> -
onClick(false)} /> +
onClick(true)}>a
+
onClick(false)}>b
); }; @@ -19,7 +20,7 @@ function Component(props) { return
{a()}
; } -export const FIXTURE_ENTRYPONT = { +export const FIXTURE_ENTRYPOINT = { fn: Component, - props: [{}], + params: [{}], };