Skip to content

Commit ad7b4b0

Browse files
committed
[compiler][be] Playground now compiles entire program
Compiler playground now runs the entire program through `babel-plugin-react-compiler` instead of a custom pipeline, which previously duplicated function inference logic from `Program.ts`. In addition, the playground output reflects the tranformed file (instead of a "virtual file" of manually concatenated functions). This helps with the following: - Reduce potential discrepencies between playground and babel plugin behavior. See attached fixture output for an example where we previously diverged. - Let playground users see compiler-inserted imports (e.g. `_c` or `useFire`) This also helps us repurpose playground into a more generic tool for compiler-users instead of just compiler engineers. - imports and other functions are preserved. This is important as we now differentiate between imports and globals in many cases, - playground now shows other program-changing behavior like position of outlined functions and hoisted declarations - emitted compiled functions do not need synthetic names
1 parent 1520802 commit ad7b4b0

21 files changed

+248
-324
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
}
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ 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 }) {

0 commit comments

Comments
 (0)