Skip to content

Commit a9a480e

Browse files
authored
Merge branch 'main' into arrow-function-with-implicit-return
2 parents 20c4d74 + c01b805 commit a9a480e

File tree

230 files changed

+7037
-3804
lines changed

Some content is hidden

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

230 files changed

+7037
-3804
lines changed

.github/workflows/compiler_playground.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
- .github/workflows/compiler_playground.yml
1010

1111
concurrency:
12-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
12+
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.run_id }}
1313
cancel-in-progress: true
1414

1515
env:

.github/workflows/compiler_rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on:
1616
- compiler/*.toml
1717

1818
concurrency:
19-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
19+
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.run_id }}
2020
cancel-in-progress: true
2121

2222
env:

.github/workflows/compiler_typescript.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
- .github/workflows/compiler_typescript.yml
1010

1111
concurrency:
12-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
12+
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.run_id }}
1313
cancel-in-progress: true
1414

1515
env:

.github/workflows/runtime_build_and_test.yml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- compiler/**
99

1010
concurrency:
11-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
11+
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.run_id }}
1212
cancel-in-progress: true
1313

1414
env:
@@ -25,6 +25,8 @@ jobs:
2525
matrix: ${{ steps.set-matrix.outputs.result }}
2626
steps:
2727
- uses: actions/checkout@v4
28+
with:
29+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
2830
- uses: actions/github-script@v7
2931
id: set-matrix
3032
with:
@@ -42,6 +44,8 @@ jobs:
4244
flow_inline_config_shortname: ${{ fromJSON(needs.discover_flow_inline_configs.outputs.matrix) }}
4345
steps:
4446
- uses: actions/checkout@v4
47+
with:
48+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
4549
- uses: actions/setup-node@v4
4650
with:
4751
node-version-file: '.nvmrc'
@@ -64,6 +68,8 @@ jobs:
6468
runs-on: ubuntu-latest
6569
steps:
6670
- uses: actions/checkout@v4
71+
with:
72+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
6773
- uses: actions/setup-node@v4
6874
with:
6975
node-version-file: '.nvmrc'
@@ -88,6 +94,8 @@ jobs:
8894
runs-on: ubuntu-latest
8995
steps:
9096
- uses: actions/checkout@v4
97+
with:
98+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
9199
- uses: actions/setup-node@v4
92100
with:
93101
node-version-file: '.nvmrc'
@@ -139,6 +147,8 @@ jobs:
139147
continue-on-error: true
140148
steps:
141149
- uses: actions/checkout@v4
150+
with:
151+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
142152
- uses: actions/setup-node@v4
143153
with:
144154
node-version-file: '.nvmrc'
@@ -166,6 +176,8 @@ jobs:
166176
release_channel: [stable, experimental]
167177
steps:
168178
- uses: actions/checkout@v4
179+
with:
180+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
169181
- uses: actions/setup-node@v4
170182
with:
171183
node-version-file: '.nvmrc'
@@ -242,6 +254,8 @@ jobs:
242254
runs-on: ubuntu-latest
243255
steps:
244256
- uses: actions/checkout@v4
257+
with:
258+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
245259
- uses: actions/setup-node@v4
246260
with:
247261
node-version-file: '.nvmrc'
@@ -272,6 +286,8 @@ jobs:
272286
runs-on: ubuntu-latest
273287
steps:
274288
- uses: actions/checkout@v4
289+
with:
290+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
275291
- uses: actions/setup-node@v4
276292
with:
277293
node-version-file: '.nvmrc'
@@ -317,6 +333,8 @@ jobs:
317333
runs-on: ubuntu-latest
318334
steps:
319335
- uses: actions/checkout@v4
336+
with:
337+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
320338
- uses: actions/setup-node@v4
321339
with:
322340
node-version-file: '.nvmrc'
@@ -350,6 +368,8 @@ jobs:
350368
runs-on: ubuntu-latest
351369
steps:
352370
- uses: actions/checkout@v4
371+
with:
372+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
353373
- uses: actions/setup-node@v4
354374
with:
355375
node-version-file: '.nvmrc'
@@ -380,6 +400,8 @@ jobs:
380400
runs-on: ubuntu-latest
381401
steps:
382402
- uses: actions/checkout@v4
403+
with:
404+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
383405
- uses: actions/setup-node@v4
384406
with:
385407
node-version-file: '.nvmrc'
@@ -419,6 +441,8 @@ jobs:
419441
runs-on: ubuntu-latest
420442
steps:
421443
- uses: actions/checkout@v4
444+
with:
445+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
422446
- uses: actions/setup-node@v4
423447
with:
424448
node-version-file: '.nvmrc'
@@ -480,6 +504,8 @@ jobs:
480504
runs-on: ubuntu-latest
481505
steps:
482506
- uses: actions/checkout@v4
507+
with:
508+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
483509
- uses: actions/setup-node@v4
484510
with:
485511
node-version-file: '.nvmrc'
@@ -528,6 +554,8 @@ jobs:
528554
runs-on: ubuntu-latest
529555
steps:
530556
- uses: actions/checkout@v4
557+
with:
558+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
531559
- uses: actions/setup-node@v4
532560
with:
533561
node-version-file: '.nvmrc'
@@ -562,6 +590,8 @@ jobs:
562590
runs-on: ubuntu-latest
563591
steps:
564592
- uses: actions/checkout@v4
593+
with:
594+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
565595
- uses: actions/setup-node@v4
566596
with:
567597
node-version-file: '.nvmrc'
@@ -603,6 +633,8 @@ jobs:
603633
runs-on: ubuntu-latest
604634
steps:
605635
- uses: actions/checkout@v4
636+
with:
637+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
606638
- uses: actions/setup-node@v4
607639
with:
608640
node-version-file: '.nvmrc'

.github/workflows/shared_lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
pull_request:
77

88
concurrency:
9-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
9+
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.run_id }}
1010
cancel-in-progress: true
1111

1212
env:

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+
}
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)