Skip to content

Commit 49eea1c

Browse files
committed
Merge branch 'issue-31578-setter-arity-gcc' of github.com:/davesnx/react 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)
2 parents 926d19e + 46aa363 commit 49eea1c

File tree

79 files changed

+1371
-1306
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1371
-1306
lines changed

compiler/apps/playground/__tests__/e2e/__snapshots__/page.spec.ts/01-user-output.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
function TestComponent(t0) {
1+
import { c as _c } from "react/compiler-runtime";
2+
export default function TestComponent(t0) {
23
const $ = _c(2);
34
const { x } = t0;
45
let t1;

compiler/apps/playground/__tests__/e2e/__snapshots__/page.spec.ts/02-default-output.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
function MyApp() {
1+
import { c as _c } from "react/compiler-runtime";
2+
export default function MyApp() {
23
const $ = _c(1);
34
let t0;
45
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {

compiler/apps/playground/__tests__/e2e/__snapshots__/page.spec.ts/module-scope-use-memo-output.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
function TestComponent(t0) {
1+
"use memo";
2+
import { c as _c } from "react/compiler-runtime";
3+
export default function TestComponent(t0) {
24
const $ = _c(2);
35
const { x } = t0;
46
let t1;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
function TestComponent({ x }) {
1+
"use no memo";
2+
export default function TestComponent({ x }) {
23
return <Button>{x}</Button>;
34
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { c as _c } from "react/compiler-runtime";
2+
function useFoo(propVal) {
3+
  const $ = _c(2);
4+
  const t0 = (propVal.baz: number);
5+
  let t1;
6+
  if ($[0] !== t0) {
7+
    t1 = <div>{t0}</div>;
8+
    $[0] = t0;
9+
    $[1] = t1;
10+
  } else {
11+
    t1 = $[1];
12+
  }
13+
  return t1;
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { c as _c } from "react/compiler-runtime";
2+
function Foo() {
3+
  const $ = _c(2);
4+
  let t0;
5+
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
6+
    t0 = foo();
7+
    $[0] = t0;
8+
  } else {
9+
    t0 = $[0];
10+
  }
11+
  const x = t0 as number;
12+
  let t1;
13+
  if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
14+
    t1 = <div>{x}</div>;
15+
    $[1] = t1;
16+
  } else {
17+
    t1 = $[1];
18+
  }
19+
  return t1;
20+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use no memo";
2+
function TestComponent({ x }) {
3+
"use memo";
4+
return <Button>{x}</Button>;
5+
}

compiler/apps/playground/__tests__/e2e/__snapshots__/page.spec.ts/use-memo-output.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { c as _c } from "react/compiler-runtime";
12
function TestComponent(t0) {
23
"use memo";
34
const $ = _c(2);
@@ -12,7 +13,7 @@ function TestComponent(t0) {
1213
}
1314
return t1;
1415
}
15-
function anonymous_1(t0) {
16+
const TestComponent2 = (t0) => {
1617
"use memo";
1718
const $ = _c(2);
1819
const { x } = t0;
@@ -25,4 +26,4 @@ function anonymous_1(t0) {
2526
t1 = $[1];
2627
}
2728
return t1;
28-
}
29+
};
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
function anonymous_1() {
1+
const TestComponent = function () {
22
"use no memo";
33
return <Button>{x}</Button>;
4-
}
5-
function anonymous_3({ x }) {
4+
};
5+
const TestComponent2 = ({ x }) => {
66
"use no memo";
77
return <Button>{x}</Button>;
8-
}
8+
};

compiler/apps/playground/__tests__/e2e/page.spec.ts

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import {expect, test} from '@playwright/test';
99
import {encodeStore, type Store} from '../../lib/stores';
1010
import {format} from 'prettier';
1111

12-
function print(data: Array<string>): Promise<string> {
12+
function formatPrint(data: Array<string>): Promise<string> {
1313
return format(data.join(''), {parser: 'babel'});
1414
}
1515

16-
const DIRECTIVE_TEST_CASES = [
16+
const TEST_CASE_INPUTS = [
1717
{
1818
name: 'module-scope-use-memo',
1919
input: `
@@ -55,14 +55,34 @@ const TestComponent2 = ({ x }) => {
5555
};`,
5656
},
5757
{
58-
name: 'function-scope-beats-module-scope',
58+
name: 'todo-function-scope-does-not-beat-module-scope',
5959
input: `
6060
'use no memo';
6161
function TestComponent({ x }) {
6262
'use memo';
6363
return <Button>{x}</Button>;
6464
}`,
6565
},
66+
{
67+
name: 'parse-typescript',
68+
input: `
69+
function Foo() {
70+
const x = foo() as number;
71+
return <div>{x}</div>;
72+
}
73+
`,
74+
noFormat: true,
75+
},
76+
{
77+
name: 'parse-flow',
78+
input: `
79+
// @flow
80+
function useFoo(propVal: {+baz: number}) {
81+
return <div>{(propVal.baz as number)}</div>;
82+
}
83+
`,
84+
noFormat: true,
85+
},
6686
];
6787

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

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

120140
expect(output).not.toEqual('');
121141
expect(output).toMatchSnapshot('02-default-output.txt');
122142
});
123143

124-
DIRECTIVE_TEST_CASES.forEach((t, idx) =>
125-
test(`directives work: ${t.name}`, async ({page}) => {
144+
TEST_CASE_INPUTS.forEach((t, idx) =>
145+
test(`playground compiles: ${t.name}`, async ({page}) => {
126146
const store: Store = {
127147
source: t.input,
128148
};
@@ -135,7 +155,12 @@ DIRECTIVE_TEST_CASES.forEach((t, idx) =>
135155

136156
const text =
137157
(await page.locator('.monaco-editor').nth(1).allInnerTexts()) ?? [];
138-
const output = await print(text);
158+
let output: string;
159+
if (t.noFormat) {
160+
output = text.join('');
161+
} else {
162+
output = await formatPrint(text);
163+
}
139164

140165
expect(output).not.toEqual('');
141166
expect(output).toMatchSnapshot(`${t.name}-output.txt`);

0 commit comments

Comments
 (0)