From c19f052b2d1b167f4a0541d2215148b2f35f7685 Mon Sep 17 00:00:00 2001 From: Mofei Zhang Date: Thu, 13 Mar 2025 11:52:25 -0400 Subject: [PATCH] [compiler][ez] Move compiler gating tests Move all gating tests to `gating/` --- .../src/HIR/Environment.ts | 2 +- .../arrow-function-expr-gating-test.expect.md | 35 ---------- .../arrow-function-expr-gating-test.js | 4 -- ...codegen-emit-imports-same-source.expect.md | 2 +- .../codegen-instrument-forget-test.expect.md | 4 +- ...gating-test-export-function-and-default.js | 14 ---- .../arrow-function-expr-gating-test.expect.md | 50 ++++++++++++++ .../gating/arrow-function-expr-gating-test.js | 10 +++ ...en-instrument-forget-gating-test.expect.md | 68 +++++++++++++++---- .../codegen-instrument-forget-gating-test.js | 15 +++- ...component-syntax-ref-gating.flow.expect.md | 0 .../error.component-syntax-ref-gating.flow.js | 0 .../error.gating-hoisting.expect.md | 0 .../{ => gating}/error.gating-hoisting.js | 0 .../error.gating-use-before-decl.expect.md | 0 .../error.gating-use-before-decl.js | 0 ...ccess-function-name-in-component.expect.md | 0 ...ating-access-function-name-in-component.js | 0 ...ng-preserves-function-properties.expect.md | 0 .../gating-preserves-function-properties.tsx | 0 ...ing-test-export-default-function.expect.md | 14 +++- .../gating-test-export-default-function.js | 5 ++ ...test-export-function-and-default.expect.md | 67 ++++++++++++++---- ...gating-test-export-function-and-default.js | 26 +++++++ .../gating-test-export-function.expect.md | 14 +++- .../gating-test-export-function.js | 5 ++ .../{ => gating}/gating-test.expect.md | 14 +++- .../compiler/{ => gating}/gating-test.js | 5 ++ ...with-hoisted-type-reference.flow.expect.md | 14 +++- ...gating-with-hoisted-type-reference.flow.js | 5 ++ ...ion-expression-React-memo-gating.expect.md | 5 +- ...r-function-expression-React-memo-gating.js | 0 ...expr-export-default-gating-test.expect.md} | 21 +++--- ...i-arrow-expr-export-default-gating-test.js | 11 +++ ...ti-arrow-expr-export-gating-test.expect.md | 41 +++++++---- .../multi-arrow-expr-export-gating-test.js | 16 +++++ .../multi-arrow-expr-gating-test.expect.md} | 49 +++++++++---- .../gating/multi-arrow-expr-gating-test.js | 18 +++++ ...mport-without-compiled-functions.expect.md | 0 ...ating-import-without-compiled-functions.js | 0 ...i-arrow-expr-export-default-gating-test.js | 9 --- .../multi-arrow-expr-export-gating-test.js | 9 --- .../compiler/multi-arrow-expr-gating-test.js | 11 --- .../packages/snap/src/SproutTodoFilter.ts | 13 +--- 44 files changed, 406 insertions(+), 170 deletions(-) delete mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/arrow-function-expr-gating-test.expect.md delete mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/arrow-function-expr-gating-test.js delete mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-function-and-default.js create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/arrow-function-expr-gating-test.expect.md create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/arrow-function-expr-gating-test.js rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/codegen-instrument-forget-gating-test.expect.md (57%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/codegen-instrument-forget-gating-test.js (52%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/error.component-syntax-ref-gating.flow.expect.md (100%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/error.component-syntax-ref-gating.flow.js (100%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/error.gating-hoisting.expect.md (100%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/error.gating-hoisting.js (100%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/error.gating-use-before-decl.expect.md (100%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/error.gating-use-before-decl.js (100%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/gating-access-function-name-in-component.expect.md (100%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/gating-access-function-name-in-component.js (100%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/gating-preserves-function-properties.expect.md (100%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/gating-preserves-function-properties.tsx (100%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/gating-test-export-default-function.expect.md (86%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/gating-test-export-default-function.js (76%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/gating-test-export-function-and-default.expect.md (51%) create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-function-and-default.js rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/gating-test-export-function.expect.md (86%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/gating-test-export-function.js (77%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/gating-test.expect.md (86%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/gating-test.js (75%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/gating-with-hoisted-type-reference.flow.expect.md (79%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/gating-with-hoisted-type-reference.flow.js (69%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/infer-function-expression-React-memo-gating.expect.md (80%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/infer-function-expression-React-memo-gating.js (100%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{multi-arrow-expr-gating-test.expect.md => gating/multi-arrow-expr-export-default-gating-test.expect.md} (69%) create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-export-default-gating-test.js rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/multi-arrow-expr-export-gating-test.expect.md (57%) create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-export-gating-test.js rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{multi-arrow-expr-export-default-gating-test.expect.md => gating/multi-arrow-expr-gating-test.expect.md} (50%) create mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-gating-test.js rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/repro-no-gating-import-without-compiled-functions.expect.md (100%) rename compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/{ => gating}/repro-no-gating-import-without-compiled-functions.js (100%) delete mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-export-default-gating-test.js delete mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-export-gating-test.js delete mode 100644 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-gating-test.js diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts index 7dc9e044bf..785240653e 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts @@ -663,7 +663,7 @@ const testComplexConfigDefaults: PartialEnvironmentConfig = { source: 'react-compiler-runtime', importSpecifierName: 'shouldInstrument', }, - globalGating: '__DEV__', + globalGating: 'DEV', }, enableEmitHookGuards: { source: 'react-compiler-runtime', diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/arrow-function-expr-gating-test.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/arrow-function-expr-gating-test.expect.md deleted file mode 100644 index 25feb6fd64..0000000000 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/arrow-function-expr-gating-test.expect.md +++ /dev/null @@ -1,35 +0,0 @@ - -## Input - -```javascript -// @gating -const ErrorView = (error, _retry) => ; - -export default ErrorView; - -``` - -## Code - -```javascript -import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag"; -import { c as _c } from "react/compiler-runtime"; // @gating -const ErrorView = isForgetEnabled_Fixtures() - ? (error, _retry) => { - const $ = _c(2); - let t0; - if ($[0] !== error) { - t0 = ; - $[0] = error; - $[1] = t0; - } else { - t0 = $[1]; - } - return t0; - } - : (error, _retry) => ; - -export default ErrorView; - -``` - \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/arrow-function-expr-gating-test.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/arrow-function-expr-gating-test.js deleted file mode 100644 index 3debc725be..0000000000 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/arrow-function-expr-gating-test.js +++ /dev/null @@ -1,4 +0,0 @@ -// @gating -const ErrorView = (error, _retry) => ; - -export default ErrorView; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-emit-imports-same-source.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-emit-imports-same-source.expect.md index 9a59b36cc0..161b42dc6d 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-emit-imports-same-source.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-emit-imports-same-source.expect.md @@ -21,7 +21,7 @@ import { import { c as _c } from "react/compiler-runtime"; // @enableEmitFreeze @enableEmitInstrumentForget function useFoo(props) { - if (__DEV__ && shouldInstrument) + if (DEV && shouldInstrument) useRenderCounter("useFoo", "/codegen-emit-imports-same-source.ts"); const $ = _c(2); let t0; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-instrument-forget-test.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-instrument-forget-test.expect.md index b5da853b6e..319de18794 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-instrument-forget-test.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-instrument-forget-test.expect.md @@ -28,7 +28,7 @@ import { c as _c } from "react/compiler-runtime"; // @enableEmitInstrumentForget function Bar(props) { "use forget"; - if (__DEV__ && shouldInstrument) + if (DEV && shouldInstrument) useRenderCounter("Bar", "/codegen-instrument-forget-test.ts"); const $ = _c(2); let t0; @@ -48,7 +48,7 @@ function NoForget(props) { function Foo(props) { "use forget"; - if (__DEV__ && shouldInstrument) + if (DEV && shouldInstrument) useRenderCounter("Foo", "/codegen-instrument-forget-test.ts"); const $ = _c(2); let t0; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-function-and-default.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-function-and-default.js deleted file mode 100644 index abd227e247..0000000000 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-function-and-default.js +++ /dev/null @@ -1,14 +0,0 @@ -// @gating @compilationMode(annotation) -export default function Bar(props) { - 'use forget'; - return
{props.bar}
; -} - -function NoForget(props) { - return {props.noForget}; -} - -export function Foo(props) { - 'use forget'; - return {props.bar}; -} diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/arrow-function-expr-gating-test.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/arrow-function-expr-gating-test.expect.md new file mode 100644 index 0000000000..659e2c9ff9 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/arrow-function-expr-gating-test.expect.md @@ -0,0 +1,50 @@ + +## Input + +```javascript +// @gating +import {Stringify} from 'shared-runtime'; +const ErrorView = ({error, _retry}) => ; + +export default ErrorView; + +export const FIXTURE_ENTRYPOINT = { + fn: eval('ErrorView'), + params: [{}], +}; + +``` + +## Code + +```javascript +import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag"; +import { c as _c } from "react/compiler-runtime"; // @gating +import { Stringify } from "shared-runtime"; +const ErrorView = isForgetEnabled_Fixtures() + ? (t0) => { + const $ = _c(2); + const { error } = t0; + let t1; + if ($[0] !== error) { + t1 = ; + $[0] = error; + $[1] = t1; + } else { + t1 = $[1]; + } + return t1; + } + : ({ error, _retry }) => ; + +export default ErrorView; + +export const FIXTURE_ENTRYPOINT = { + fn: eval("ErrorView"), + params: [{}], +}; + +``` + +### Eval output +(kind: ok)
{}
\ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/arrow-function-expr-gating-test.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/arrow-function-expr-gating-test.js new file mode 100644 index 0000000000..4c6ab77596 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/arrow-function-expr-gating-test.js @@ -0,0 +1,10 @@ +// @gating +import {Stringify} from 'shared-runtime'; +const ErrorView = ({error, _retry}) => ; + +export default ErrorView; + +export const FIXTURE_ENTRYPOINT = { + fn: eval('ErrorView'), + params: [{}], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-instrument-forget-gating-test.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/codegen-instrument-forget-gating-test.expect.md similarity index 57% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-instrument-forget-gating-test.expect.md rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/codegen-instrument-forget-gating-test.expect.md index fc9247344d..fe85e38e10 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-instrument-forget-gating-test.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/codegen-instrument-forget-gating-test.expect.md @@ -15,9 +15,22 @@ function NoForget(props) { function Foo(props) { 'use forget'; - return {props.bar}; + if (props.bar < 0) { + return props.children; + } + return ( + + + + ); } +global.DEV = true; +export const FIXTURE_ENTRYPOINT = { + fn: eval('Foo'), + params: [{bar: 2}], +}; + ``` ## Code @@ -29,7 +42,7 @@ import { c as _c } from "react/compiler-runtime"; // @enableEmitInstrumentForget const Bar = isForgetEnabled_Fixtures() ? function Bar(props) { "use forget"; - if (__DEV__ && shouldInstrument) + if (DEV && shouldInstrument) useRenderCounter("Bar", "/codegen-instrument-forget-gating-test.ts"); const $ = _c(2); let t0; @@ -53,23 +66,50 @@ function NoForget(props) { const Foo = isForgetEnabled_Fixtures() ? function Foo(props) { "use forget"; - if (__DEV__ && shouldInstrument) + if (DEV && shouldInstrument) useRenderCounter("Foo", "/codegen-instrument-forget-gating-test.ts"); - const $ = _c(2); - let t0; - if ($[0] !== props.bar) { - t0 = {props.bar}; - $[0] = props.bar; - $[1] = t0; - } else { - t0 = $[1]; + const $ = _c(3); + if (props.bar < 0) { + return props.children; } - return t0; + + const t0 = props.bar - 1; + let t1; + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { + t1 = ; + $[0] = t1; + } else { + t1 = $[0]; + } + let t2; + if ($[1] !== t0) { + t2 = {t1}; + $[1] = t0; + $[2] = t2; + } else { + t2 = $[2]; + } + return t2; } : function Foo(props) { "use forget"; - return {props.bar}; + if (props.bar < 0) { + return props.children; + } + return ( + + + + ); }; +global.DEV = true; +export const FIXTURE_ENTRYPOINT = { + fn: eval("Foo"), + params: [{ bar: 2 }], +}; + ``` - \ No newline at end of file + +### Eval output +(kind: ok)
\ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-instrument-forget-gating-test.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/codegen-instrument-forget-gating-test.js similarity index 52% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-instrument-forget-gating-test.js rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/codegen-instrument-forget-gating-test.js index dffb8ce795..6730630ac3 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-instrument-forget-gating-test.js +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/codegen-instrument-forget-gating-test.js @@ -11,5 +11,18 @@ function NoForget(props) { function Foo(props) { 'use forget'; - return {props.bar}; + if (props.bar < 0) { + return props.children; + } + return ( + + + + ); } + +global.DEV = true; +export const FIXTURE_ENTRYPOINT = { + fn: eval('Foo'), + params: [{bar: 2}], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.component-syntax-ref-gating.flow.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/error.component-syntax-ref-gating.flow.expect.md similarity index 100% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.component-syntax-ref-gating.flow.expect.md rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/error.component-syntax-ref-gating.flow.expect.md diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.component-syntax-ref-gating.flow.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/error.component-syntax-ref-gating.flow.js similarity index 100% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.component-syntax-ref-gating.flow.js rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/error.component-syntax-ref-gating.flow.js diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.gating-hoisting.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/error.gating-hoisting.expect.md similarity index 100% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.gating-hoisting.expect.md rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/error.gating-hoisting.expect.md diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.gating-hoisting.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/error.gating-hoisting.js similarity index 100% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.gating-hoisting.js rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/error.gating-hoisting.js diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.gating-use-before-decl.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/error.gating-use-before-decl.expect.md similarity index 100% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.gating-use-before-decl.expect.md rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/error.gating-use-before-decl.expect.md diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.gating-use-before-decl.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/error.gating-use-before-decl.js similarity index 100% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.gating-use-before-decl.js rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/error.gating-use-before-decl.js diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-access-function-name-in-component.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-access-function-name-in-component.expect.md similarity index 100% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-access-function-name-in-component.expect.md rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-access-function-name-in-component.expect.md diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-access-function-name-in-component.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-access-function-name-in-component.js similarity index 100% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-access-function-name-in-component.js rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-access-function-name-in-component.js diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-preserves-function-properties.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-preserves-function-properties.expect.md similarity index 100% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-preserves-function-properties.expect.md rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-preserves-function-properties.expect.md diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-preserves-function-properties.tsx b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-preserves-function-properties.tsx similarity index 100% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-preserves-function-properties.tsx rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-preserves-function-properties.tsx diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-default-function.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-default-function.expect.md similarity index 86% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-default-function.expect.md rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-default-function.expect.md index 92830938b5..4e4a35c375 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-default-function.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-default-function.expect.md @@ -17,6 +17,11 @@ function Foo(props) { return {props.bar}; } +export const FIXTURE_ENTRYPOINT = { + fn: eval('Bar'), + params: [{bar: 2}], +}; + ``` ## Code @@ -66,5 +71,12 @@ const Foo = isForgetEnabled_Fixtures() return {props.bar}; }; +export const FIXTURE_ENTRYPOINT = { + fn: eval("Bar"), + params: [{ bar: 2 }], +}; + ``` - \ No newline at end of file + +### Eval output +(kind: ok)
2
\ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-default-function.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-default-function.js similarity index 76% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-default-function.js rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-default-function.js index 5ac847953d..1ec9a902b2 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-default-function.js +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-default-function.js @@ -12,3 +12,8 @@ function Foo(props) { 'use forget'; return {props.bar}; } + +export const FIXTURE_ENTRYPOINT = { + fn: eval('Bar'), + params: [{bar: 2}], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-function-and-default.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-function-and-default.expect.md similarity index 51% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-function-and-default.expect.md rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-function-and-default.expect.md index ea3d320a3e..95c629aa11 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-function-and-default.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-function-and-default.expect.md @@ -12,11 +12,23 @@ function NoForget(props) { return {props.noForget}; } -export function Foo(props) { +function Foo(props) { 'use forget'; - return {props.bar}; + if (props.bar < 0) { + return props.children; + } + return ( + + + + ); } +export const FIXTURE_ENTRYPOINT = { + fn: eval('Bar'), + params: [{bar: 2}], +}; + ``` ## Code @@ -47,25 +59,50 @@ export default Bar; function NoForget(props) { return {props.noForget}; } - -export const Foo = isForgetEnabled_Fixtures() +const Foo = isForgetEnabled_Fixtures() ? function Foo(props) { "use forget"; - const $ = _c(2); - let t0; - if ($[0] !== props.bar) { - t0 = {props.bar}; - $[0] = props.bar; - $[1] = t0; - } else { - t0 = $[1]; + const $ = _c(3); + if (props.bar < 0) { + return props.children; } - return t0; + + const t0 = props.bar - 1; + let t1; + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { + t1 = ; + $[0] = t1; + } else { + t1 = $[0]; + } + let t2; + if ($[1] !== t0) { + t2 = {t1}; + $[1] = t0; + $[2] = t2; + } else { + t2 = $[2]; + } + return t2; } : function Foo(props) { "use forget"; - return {props.bar}; + if (props.bar < 0) { + return props.children; + } + return ( + + + + ); }; +export const FIXTURE_ENTRYPOINT = { + fn: eval("Bar"), + params: [{ bar: 2 }], +}; + ``` - \ No newline at end of file + +### Eval output +(kind: ok)
2
\ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-function-and-default.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-function-and-default.js new file mode 100644 index 0000000000..5b7f7c81b7 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-function-and-default.js @@ -0,0 +1,26 @@ +// @gating @compilationMode(annotation) +export default function Bar(props) { + 'use forget'; + return
{props.bar}
; +} + +function NoForget(props) { + return {props.noForget}; +} + +function Foo(props) { + 'use forget'; + if (props.bar < 0) { + return props.children; + } + return ( + + + + ); +} + +export const FIXTURE_ENTRYPOINT = { + fn: eval('Bar'), + params: [{bar: 2}], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-function.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-function.expect.md similarity index 86% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-function.expect.md rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-function.expect.md index caaf1b4472..ab31d2939d 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-function.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-function.expect.md @@ -17,6 +17,11 @@ export function Foo(props) { return {props.bar}; } +export const FIXTURE_ENTRYPOINT = { + fn: eval('Bar'), + params: [{bar: 2}], +}; + ``` ## Code @@ -66,5 +71,12 @@ export const Foo = isForgetEnabled_Fixtures() return {props.bar}; }; +export const FIXTURE_ENTRYPOINT = { + fn: eval("Bar"), + params: [{ bar: 2 }], +}; + ``` - \ No newline at end of file + +### Eval output +(kind: ok)
2
\ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-function.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-function.js similarity index 77% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-function.js rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-function.js index 45ce5cbdb5..5bcf9ac67d 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-function.js +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test-export-function.js @@ -12,3 +12,8 @@ export function Foo(props) { 'use forget'; return {props.bar}; } + +export const FIXTURE_ENTRYPOINT = { + fn: eval('Bar'), + params: [{bar: 2}], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test.expect.md similarity index 86% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test.expect.md rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test.expect.md index 5166dab418..e68e4840cf 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test.expect.md @@ -17,6 +17,11 @@ function Foo(props) { return {props.bar}; } +export const FIXTURE_ENTRYPOINT = { + fn: eval('Bar'), + params: [{bar: 2}], +}; + ``` ## Code @@ -65,5 +70,12 @@ const Foo = isForgetEnabled_Fixtures() return {props.bar}; }; +export const FIXTURE_ENTRYPOINT = { + fn: eval("Bar"), + params: [{ bar: 2 }], +}; + ``` - \ No newline at end of file + +### Eval output +(kind: ok)
2
\ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test.js similarity index 75% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test.js rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test.js index bf031d8b15..3bb92654d9 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test.js +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-test.js @@ -12,3 +12,8 @@ function Foo(props) { 'use forget'; return {props.bar}; } + +export const FIXTURE_ENTRYPOINT = { + fn: eval('Bar'), + params: [{bar: 2}], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-with-hoisted-type-reference.flow.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-with-hoisted-type-reference.flow.expect.md similarity index 79% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-with-hoisted-type-reference.flow.expect.md rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-with-hoisted-type-reference.flow.expect.md index e87606372d..26c6e510d1 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-with-hoisted-type-reference.flow.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-with-hoisted-type-reference.flow.expect.md @@ -13,6 +13,11 @@ component Component(value: string) { export default memo(Component); +export const FIXTURE_ENTRYPOINT = { + fn: eval('Component'), + params: [{value: 'foo'}], +}; + ``` ## Code @@ -43,5 +48,12 @@ const Component = isForgetEnabled_Fixtures() export default memo(Component); +export const FIXTURE_ENTRYPOINT = { + fn: eval("Component"), + params: [{ value: "foo" }], +}; + ``` - \ No newline at end of file + +### Eval output +(kind: ok)
foo
\ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-with-hoisted-type-reference.flow.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-with-hoisted-type-reference.flow.js similarity index 69% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-with-hoisted-type-reference.flow.js rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-with-hoisted-type-reference.flow.js index 86433ec50d..1fe640b693 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-with-hoisted-type-reference.flow.js +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/gating-with-hoisted-type-reference.flow.js @@ -8,3 +8,8 @@ component Component(value: string) { } export default memo(Component); + +export const FIXTURE_ENTRYPOINT = { + fn: eval('Component'), + params: [{value: 'foo'}], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-function-expression-React-memo-gating.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/infer-function-expression-React-memo-gating.expect.md similarity index 80% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-function-expression-React-memo-gating.expect.md rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/infer-function-expression-React-memo-gating.expect.md index 6524c9d202..4931b87b01 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-function-expression-React-memo-gating.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/infer-function-expression-React-memo-gating.expect.md @@ -35,4 +35,7 @@ export default React.forwardRef( ); ``` - \ No newline at end of file + +### Eval output +(kind: exception) Fixture not implemented +logs: ['forwardRef render functions accept exactly two parameters: props and ref. %s','Did you forget to use the ref parameter?'] \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-function-expression-React-memo-gating.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/infer-function-expression-React-memo-gating.js similarity index 100% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/infer-function-expression-React-memo-gating.js rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/infer-function-expression-React-memo-gating.js diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-gating-test.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-export-default-gating-test.expect.md similarity index 69% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-gating-test.expect.md rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-export-default-gating-test.expect.md index 92d3aa7209..b3dc5011f9 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-gating-test.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-export-default-gating-test.expect.md @@ -3,17 +3,17 @@ ```javascript // @gating -const ErrorView = (error, _retry) => ; +import {Stringify} from 'shared-runtime'; -const Renderer = props => ( +const ErrorView = (error, _retry) => ; + +export default props => ( ); -export default Renderer; - ``` ## Code @@ -21,12 +21,14 @@ export default Renderer; ```javascript import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag"; import { c as _c } from "react/compiler-runtime"; // @gating +import { Stringify } from "shared-runtime"; + const ErrorView = isForgetEnabled_Fixtures() ? (error, _retry) => { const $ = _c(2); let t0; if ($[0] !== error) { - t0 = ; + t0 = ; $[0] = error; $[1] = t0; } else { @@ -34,9 +36,9 @@ const ErrorView = isForgetEnabled_Fixtures() } return t0; } - : (error, _retry) => ; + : (error, _retry) => ; -const Renderer = isForgetEnabled_Fixtures() +export default isForgetEnabled_Fixtures() ? (props) => { const $ = _c(1); let t0; @@ -59,7 +61,8 @@ const Renderer = isForgetEnabled_Fixtures() ); -export default Renderer; ``` - \ No newline at end of file + +### Eval output +(kind: exception) Fixture not implemented \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-export-default-gating-test.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-export-default-gating-test.js new file mode 100644 index 0000000000..e856a290f7 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-export-default-gating-test.js @@ -0,0 +1,11 @@ +// @gating +import {Stringify} from 'shared-runtime'; + +const ErrorView = (error, _retry) => ; + +export default props => ( + + + + +); diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-export-gating-test.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-export-gating-test.expect.md similarity index 57% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-export-gating-test.expect.md rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-export-gating-test.expect.md index 61d87a11cd..ea2a1c1541 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-export-gating-test.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-export-gating-test.expect.md @@ -3,15 +3,22 @@ ```javascript // @gating -const ErrorView = (error, _retry) => ; +import {Stringify} from 'shared-runtime'; + +const ErrorView = (error, _retry) => ; export const Renderer = props => ( - - +
+ - +
); +export const FIXTURE_ENTRYPOINT = { + fn: eval('Renderer'), + params: [{}], +}; + ``` ## Code @@ -19,12 +26,14 @@ export const Renderer = props => ( ```javascript import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag"; import { c as _c } from "react/compiler-runtime"; // @gating +import { Stringify } from "shared-runtime"; + const ErrorView = isForgetEnabled_Fixtures() ? (error, _retry) => { const $ = _c(2); let t0; if ($[0] !== error) { - t0 = ; + t0 = ; $[0] = error; $[1] = t0; } else { @@ -32,7 +41,7 @@ const ErrorView = isForgetEnabled_Fixtures() } return t0; } - : (error, _retry) => ; + : (error, _retry) => ; export const Renderer = isForgetEnabled_Fixtures() ? (props) => { @@ -40,10 +49,10 @@ export const Renderer = isForgetEnabled_Fixtures() let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { t0 = ( - - +
+ - +
); $[0] = t0; } else { @@ -52,11 +61,17 @@ export const Renderer = isForgetEnabled_Fixtures() return t0; } : (props) => ( - - +
+ - +
); +export const FIXTURE_ENTRYPOINT = { + fn: eval("Renderer"), + params: [{}], +}; ``` - \ No newline at end of file + +### Eval output +(kind: ok)
{"error":{}}
\ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-export-gating-test.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-export-gating-test.js new file mode 100644 index 0000000000..19152d6839 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-export-gating-test.js @@ -0,0 +1,16 @@ +// @gating +import {Stringify} from 'shared-runtime'; + +const ErrorView = (error, _retry) => ; + +export const Renderer = props => ( +
+ + +
+); + +export const FIXTURE_ENTRYPOINT = { + fn: eval('Renderer'), + params: [{}], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-export-default-gating-test.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-gating-test.expect.md similarity index 50% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-export-default-gating-test.expect.md rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-gating-test.expect.md index a9a90eaa21..cc5195edb2 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-export-default-gating-test.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-gating-test.expect.md @@ -3,15 +3,24 @@ ```javascript // @gating -const ErrorView = (error, _retry) => ; +import {Stringify} from 'shared-runtime'; -export default Renderer = props => ( - - +const ErrorView = (error, _retry) => ; + +const Renderer = props => ( +
+ - +
); +export default Renderer; + +export const FIXTURE_ENTRYPOINT = { + fn: eval('Renderer'), + params: [{}], +}; + ``` ## Code @@ -19,12 +28,14 @@ export default Renderer = props => ( ```javascript import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag"; import { c as _c } from "react/compiler-runtime"; // @gating +import { Stringify } from "shared-runtime"; + const ErrorView = isForgetEnabled_Fixtures() ? (error, _retry) => { const $ = _c(2); let t0; if ($[0] !== error) { - t0 = ; + t0 = ; $[0] = error; $[1] = t0; } else { @@ -32,18 +43,18 @@ const ErrorView = isForgetEnabled_Fixtures() } return t0; } - : (error, _retry) => ; + : (error, _retry) => ; -export default Renderer = isForgetEnabled_Fixtures() +const Renderer = isForgetEnabled_Fixtures() ? (props) => { const $ = _c(1); let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { t0 = ( - - +
+ - +
); $[0] = t0; } else { @@ -52,11 +63,19 @@ export default Renderer = isForgetEnabled_Fixtures() return t0; } : (props) => ( - - +
+ - +
); +export default Renderer; + +export const FIXTURE_ENTRYPOINT = { + fn: eval("Renderer"), + params: [{}], +}; ``` - \ No newline at end of file + +### Eval output +(kind: ok)
{"error":{}}
\ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-gating-test.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-gating-test.js new file mode 100644 index 0000000000..ae4fd8dc94 --- /dev/null +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/multi-arrow-expr-gating-test.js @@ -0,0 +1,18 @@ +// @gating +import {Stringify} from 'shared-runtime'; + +const ErrorView = (error, _retry) => ; + +const Renderer = props => ( +
+ + +
+); + +export default Renderer; + +export const FIXTURE_ENTRYPOINT = { + fn: eval('Renderer'), + params: [{}], +}; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-no-gating-import-without-compiled-functions.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/repro-no-gating-import-without-compiled-functions.expect.md similarity index 100% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-no-gating-import-without-compiled-functions.expect.md rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/repro-no-gating-import-without-compiled-functions.expect.md diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-no-gating-import-without-compiled-functions.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/repro-no-gating-import-without-compiled-functions.js similarity index 100% rename from compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-no-gating-import-without-compiled-functions.js rename to compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating/repro-no-gating-import-without-compiled-functions.js diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-export-default-gating-test.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-export-default-gating-test.js deleted file mode 100644 index 0c07f55b10..0000000000 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-export-default-gating-test.js +++ /dev/null @@ -1,9 +0,0 @@ -// @gating -const ErrorView = (error, _retry) => ; - -export default Renderer = props => ( - - - - -); diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-export-gating-test.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-export-gating-test.js deleted file mode 100644 index ac71868f33..0000000000 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-export-gating-test.js +++ /dev/null @@ -1,9 +0,0 @@ -// @gating -const ErrorView = (error, _retry) => ; - -export const Renderer = props => ( - - - - -); diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-gating-test.js b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-gating-test.js deleted file mode 100644 index 72109d6f81..0000000000 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/multi-arrow-expr-gating-test.js +++ /dev/null @@ -1,11 +0,0 @@ -// @gating -const ErrorView = (error, _retry) => ; - -const Renderer = props => ( - - - - -); - -export default Renderer; diff --git a/compiler/packages/snap/src/SproutTodoFilter.ts b/compiler/packages/snap/src/SproutTodoFilter.ts index 0817bbf89c..7c487869d3 100644 --- a/compiler/packages/snap/src/SproutTodoFilter.ts +++ b/compiler/packages/snap/src/SproutTodoFilter.ts @@ -222,7 +222,6 @@ const skipFilter = new Set([ 'array-at-mutate-after-capture', 'array-join', 'array-push-effect', - 'arrow-function-expr-gating-test', 'assignment-in-nested-if', 'await-side-effecting-promise', 'await', @@ -335,16 +334,10 @@ const skipFilter = new Set([ 'babel-existing-react-import', 'babel-existing-react-kitchensink-import', 'call', - 'codegen-instrument-forget-gating-test', 'codegen-instrument-forget-test', 'conditional-on-mutable', 'constructor', 'frozen-after-alias', - 'gating-test-export-default-function', - 'gating-test-export-function-and-default', - 'gating-test-export-function', - 'gating-test', - 'gating-with-hoisted-type-reference.flow', 'hook-call', 'hooks-freeze-arguments', 'hooks-freeze-possibly-mutable-arguments', @@ -352,8 +345,6 @@ const skipFilter = new Set([ 'independent', 'interdependent-across-if', 'interdependent', - 'multi-arrow-expr-export-gating-test', - 'multi-arrow-expr-gating-test', 'mutable-liverange-loop', 'sequence-expression', 'ssa-call-jsx-2', @@ -361,7 +352,6 @@ const skipFilter = new Set([ 'ssa-newexpression', 'ssa-shadowing', 'template-literal', - 'multi-arrow-expr-export-default-gating-test', // works, but appears differently when printing // due to optional function argument @@ -407,7 +397,6 @@ const skipFilter = new Set([ 'infer-functions-hook-with-hook-call', 'infer-functions-hook-with-jsx', 'infer-function-expression-component', - 'infer-function-expression-React-memo-gating', 'infer-skip-components-without-hooks-or-jsx', 'class-component-with-render-helper', 'fbt/fbtparam-with-jsx-element-content', @@ -422,7 +411,7 @@ const skipFilter = new Set([ 'transitive-freeze-function-expressions', // nothing to compile/run - 'repro-no-gating-import-without-compiled-functions', + 'gating/repro-no-gating-import-without-compiled-functions', // TODOs 'rules-of-hooks/todo.bail.rules-of-hooks-279ac76f53af',