Skip to content

Commit

Permalink
Merge branch 'issue-31578-setter-arity-gcc' of github.com:/davesnx/re…
Browse files Browse the repository at this point in the history
…act into issue-31578-setter-arity-gcc

* 'issue-31578-setter-arity-gcc' of github.com:/davesnx/react:
  [flags] Clean up scheduler flags (facebook#31814)
  Enable debugRenderPhaseSideEffectsForStrictMode in test renderers (facebook#31761)
  Enable disableDefaultPropsExceptForClasses (facebook#31804)
  Turn on useModernStrictMode in test renderers (facebook#31769)
  [compiler][ez] Add shape for global Object.keys (facebook#31583)
  [compiler] Context variables as dependencies (facebook#31582)
  [compiler] Add fire to known React APIs (facebook#31795)
  [compiler] Add option for firing effect functions (facebook#31794)
  [compiler][be] Logger based debug printing in test runner (facebook#31809)
  [compiler][ez] Clean up duplicate code in propagateScopeDeps (facebook#31581)
  [compiler] Repro for aliased captures within inner function expressions (facebook#31770)
  [compiler][be] Playground now compiles entire program (facebook#31774)
  [Flight] Color and badge non-primary environments (facebook#31738)
  [Flight] Emit Deduped Server Components Marker (facebook#31737)
  [Flight] Sort Server Components Track Group ahead of Client Scheduler/Components Tracks (facebook#31736)
  Clean up context access profiling experiment (facebook#31806)
  [Flight] Stack Parallel Components in Separate Tracks (facebook#31735)
  Flag for requestPaint (facebook#31805)
  • Loading branch information
davesnx committed Dec 18, 2024
2 parents 926d19e + 46aa363 commit 49eea1c
Show file tree
Hide file tree
Showing 79 changed files with 1,371 additions and 1,306 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function TestComponent(t0) {
import { c as _c } from "react/compiler-runtime";
export default function TestComponent(t0) {
const $ = _c(2);
const { x } = t0;
let t1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function MyApp() {
import { c as _c } from "react/compiler-runtime";
export default function MyApp() {
const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
function TestComponent(t0) {
"use memo";
import { c as _c } from "react/compiler-runtime";
export default function TestComponent(t0) {
const $ = _c(2);
const { x } = t0;
let t1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
function TestComponent({ x }) {
"use no memo";
export default function TestComponent({ x }) {
return <Button>{x}</Button>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { c as _c } from "react/compiler-runtime";
function useFoo(propVal) {
  const $ = _c(2);
  const t0 = (propVal.baz: number);
  let t1;
  if ($[0] !== t0) {
    t1 = <div>{t0}</div>;
    $[0] = t0;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  return t1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { c as _c } from "react/compiler-runtime";
function Foo() {
  const $ = _c(2);
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = foo();
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  const x = t0 as number;
  let t1;
  if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = <div>{x}</div>;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  return t1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use no memo";
function TestComponent({ x }) {
"use memo";
return <Button>{x}</Button>;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { c as _c } from "react/compiler-runtime";
function TestComponent(t0) {
"use memo";
const $ = _c(2);
Expand All @@ -12,7 +13,7 @@ function TestComponent(t0) {
}
return t1;
}
function anonymous_1(t0) {
const TestComponent2 = (t0) => {
"use memo";
const $ = _c(2);
const { x } = t0;
Expand All @@ -25,4 +26,4 @@ function anonymous_1(t0) {
t1 = $[1];
}
return t1;
}
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function anonymous_1() {
const TestComponent = function () {
"use no memo";
return <Button>{x}</Button>;
}
function anonymous_3({ x }) {
};
const TestComponent2 = ({ x }) => {
"use no memo";
return <Button>{x}</Button>;
}
};
41 changes: 33 additions & 8 deletions compiler/apps/playground/__tests__/e2e/page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {expect, test} from '@playwright/test';
import {encodeStore, type Store} from '../../lib/stores';
import {format} from 'prettier';

function print(data: Array<string>): Promise<string> {
function formatPrint(data: Array<string>): Promise<string> {
return format(data.join(''), {parser: 'babel'});
}

const DIRECTIVE_TEST_CASES = [
const TEST_CASE_INPUTS = [
{
name: 'module-scope-use-memo',
input: `
Expand Down Expand Up @@ -55,14 +55,34 @@ const TestComponent2 = ({ x }) => {
};`,
},
{
name: 'function-scope-beats-module-scope',
name: 'todo-function-scope-does-not-beat-module-scope',
input: `
'use no memo';
function TestComponent({ x }) {
'use memo';
return <Button>{x}</Button>;
}`,
},
{
name: 'parse-typescript',
input: `
function Foo() {
const x = foo() as number;
return <div>{x}</div>;
}
`,
noFormat: true,
},
{
name: 'parse-flow',
input: `
// @flow
function useFoo(propVal: {+baz: number}) {
return <div>{(propVal.baz as number)}</div>;
}
`,
noFormat: true,
},
];

test('editor should open successfully', async ({page}) => {
Expand Down Expand Up @@ -90,7 +110,7 @@ test('editor should compile from hash successfully', async ({page}) => {
});
const text =
(await page.locator('.monaco-editor').nth(1).allInnerTexts()) ?? [];
const output = await print(text);
const output = await formatPrint(text);

expect(output).not.toEqual('');
expect(output).toMatchSnapshot('01-user-output.txt');
Expand All @@ -115,14 +135,14 @@ test('reset button works', async ({page}) => {
});
const text =
(await page.locator('.monaco-editor').nth(1).allInnerTexts()) ?? [];
const output = await print(text);
const output = await formatPrint(text);

expect(output).not.toEqual('');
expect(output).toMatchSnapshot('02-default-output.txt');
});

DIRECTIVE_TEST_CASES.forEach((t, idx) =>
test(`directives work: ${t.name}`, async ({page}) => {
TEST_CASE_INPUTS.forEach((t, idx) =>
test(`playground compiles: ${t.name}`, async ({page}) => {
const store: Store = {
source: t.input,
};
Expand All @@ -135,7 +155,12 @@ DIRECTIVE_TEST_CASES.forEach((t, idx) =>

const text =
(await page.locator('.monaco-editor').nth(1).allInnerTexts()) ?? [];
const output = await print(text);
let output: string;
if (t.noFormat) {
output = text.join('');
} else {
output = await formatPrint(text);
}

expect(output).not.toEqual('');
expect(output).toMatchSnapshot(`${t.name}-output.txt`);
Expand Down
Loading

0 comments on commit 49eea1c

Please sign in to comment.