Skip to content

Commit e02ea82

Browse files
authored
Merge branch 'main' into arrow-function-with-implicit-return
2 parents a9a480e + 0bf1f39 commit e02ea82

File tree

239 files changed

+22800
-8308
lines changed

Some content is hidden

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

239 files changed

+22800
-8308
lines changed

.eslintrc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ module.exports = {
303303
ERROR,
304304
{isProductionUserAppCode: true},
305305
],
306-
'react-internal/no-to-warn-dev-within-to-throw': ERROR,
307306
'react-internal/warning-args': ERROR,
308307
'react-internal/no-production-logging': ERROR,
309308
},
@@ -590,6 +589,11 @@ module.exports = {
590589
WheelEventHandler: 'readonly',
591590
FinalizationRegistry: 'readonly',
592591
Omit: 'readonly',
592+
Keyframe: 'readonly',
593+
PropertyIndexedKeyframes: 'readonly',
594+
KeyframeAnimationOptions: 'readonly',
595+
GetAnimationsOptions: 'readonly',
596+
Animatable: 'readonly',
593597

594598
spyOnDev: 'readonly',
595599
spyOnDevAndProd: 'readonly',

.github/workflows/compiler_playground.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ jobs:
3838
with:
3939
path: "**/node_modules"
4040
key: compiler-node_modules-${{ runner.arch }}-${{ runner.os }}-${{ hashFiles('compiler/**/yarn.lock') }}
41-
- name: yarn install compiler
42-
run: yarn install --frozen-lockfile
43-
working-directory: compiler
44-
- name: yarn install playground
45-
run: yarn install --frozen-lockfile
41+
- run: yarn install --frozen-lockfile
4642
- run: npx playwright install --with-deps chromium
4743
- run: CI=true yarn test
4844
- run: ls -R test-results
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: (Shared) Discord Notify
2+
3+
on:
4+
pull_request_target:
5+
types: [labeled]
6+
7+
jobs:
8+
notify:
9+
if: ${{ github.event.label.name == 'React Core Team' }}
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Discord Webhook Action
13+
uses: tsickert/discord-webhook@v6.0.0
14+
with:
15+
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
16+
embed-author-name: ${{ github.event.pull_request.user.login }}
17+
embed-author-url: ${{ github.event.pull_request.user.html_url }}
18+
embed-author-icon-url: ${{ github.event.pull_request.user.avatar_url }}
19+
embed-title: '#${{ github.event.number }} (+${{github.event.pull_request.additions}} -${{github.event.pull_request.deletions}}): ${{ github.event.pull_request.title }}'
20+
embed-description: ${{ github.event.pull_request.body }}
21+
embed-url: ${{ github.event.pull_request.html_url }}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { c as _c } from "react/compiler-runtime"; // 
2+
        @compilationMode(all)
3+
function nonReactFn() {
4+
  const $ = _c(1);
5+
  let t0;
6+
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
7+
    t0 = {};
8+
    $[0] = t0;
9+
  } else {
10+
    t0 = $[0];
11+
  }
12+
  return t0;
13+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @compilationMode(infer)
2+
function nonReactFn() {
3+
  return {};
4+
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@ function Foo() {
7979
// @flow
8080
function useFoo(propVal: {+baz: number}) {
8181
return <div>{(propVal.baz as number)}</div>;
82+
}
83+
`,
84+
noFormat: true,
85+
},
86+
{
87+
name: 'compilationMode-infer',
88+
input: `// @compilationMode(infer)
89+
function nonReactFn() {
90+
return {};
91+
}
92+
`,
93+
noFormat: true,
94+
},
95+
{
96+
name: 'compilationMode-all',
97+
input: `// @compilationMode(all)
98+
function nonReactFn() {
99+
return {};
82100
}
83101
`,
84102
noFormat: true,

compiler/apps/playground/components/Editor/EditorImpl.tsx

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import BabelPluginReactCompiler, {
2020
CompilerPipelineValue,
2121
parsePluginOptions,
2222
} from 'babel-plugin-react-compiler/src';
23-
import {type EnvironmentConfig} from 'babel-plugin-react-compiler/src/HIR/Environment';
2423
import clsx from 'clsx';
2524
import invariant from 'invariant';
2625
import {useSnackbar} from 'notistack';
@@ -69,24 +68,14 @@ function parseInput(
6968
function invokeCompiler(
7069
source: string,
7170
language: 'flow' | 'typescript',
72-
environment: EnvironmentConfig,
73-
logIR: (pipelineValue: CompilerPipelineValue) => void,
71+
options: PluginOptions,
7472
): CompilerTransformOutput {
75-
const opts: PluginOptions = parsePluginOptions({
76-
logger: {
77-
debugLogIRs: logIR,
78-
logEvent: () => {},
79-
},
80-
environment,
81-
compilationMode: 'all',
82-
panicThreshold: 'all_errors',
83-
});
8473
const ast = parseInput(source, language);
8574
let result = transformFromAstSync(ast, source, {
8675
filename: '_playgroundFile.js',
8776
highlightCode: false,
8877
retainLines: true,
89-
plugins: [[BabelPluginReactCompiler, opts]],
78+
plugins: [[BabelPluginReactCompiler, options]],
9079
ast: true,
9180
sourceType: 'module',
9281
configFile: false,
@@ -172,51 +161,59 @@ function compile(source: string): [CompilerOutput, 'flow' | 'typescript'] {
172161
try {
173162
// Extract the first line to quickly check for custom test directives
174163
const pragma = source.substring(0, source.indexOf('\n'));
175-
const config = parseConfigPragmaForTests(pragma);
176-
177-
transformOutput = invokeCompiler(
178-
source,
179-
language,
180-
{...config, customHooks: new Map([...COMMON_HOOKS])},
181-
result => {
182-
switch (result.kind) {
183-
case 'ast': {
184-
break;
185-
}
186-
case 'hir': {
187-
upsert({
188-
kind: 'hir',
189-
fnName: result.value.id,
190-
name: result.name,
191-
value: printFunctionWithOutlined(result.value),
192-
});
193-
break;
194-
}
195-
case 'reactive': {
196-
upsert({
197-
kind: 'reactive',
198-
fnName: result.value.id,
199-
name: result.name,
200-
value: printReactiveFunctionWithOutlined(result.value),
201-
});
202-
break;
203-
}
204-
case 'debug': {
205-
upsert({
206-
kind: 'debug',
207-
fnName: null,
208-
name: result.name,
209-
value: result.value,
210-
});
211-
break;
212-
}
213-
default: {
214-
const _: never = result;
215-
throw new Error(`Unhandled result ${result}`);
216-
}
164+
const logIR = (result: CompilerPipelineValue): void => {
165+
switch (result.kind) {
166+
case 'ast': {
167+
break;
168+
}
169+
case 'hir': {
170+
upsert({
171+
kind: 'hir',
172+
fnName: result.value.id,
173+
name: result.name,
174+
value: printFunctionWithOutlined(result.value),
175+
});
176+
break;
177+
}
178+
case 'reactive': {
179+
upsert({
180+
kind: 'reactive',
181+
fnName: result.value.id,
182+
name: result.name,
183+
value: printReactiveFunctionWithOutlined(result.value),
184+
});
185+
break;
217186
}
187+
case 'debug': {
188+
upsert({
189+
kind: 'debug',
190+
fnName: null,
191+
name: result.name,
192+
value: result.value,
193+
});
194+
break;
195+
}
196+
default: {
197+
const _: never = result;
198+
throw new Error(`Unhandled result ${result}`);
199+
}
200+
}
201+
};
202+
const parsedOptions = parseConfigPragmaForTests(pragma, {
203+
compilationMode: 'infer',
204+
});
205+
const opts: PluginOptions = parsePluginOptions({
206+
...parsedOptions,
207+
environment: {
208+
...parsedOptions.environment,
209+
customHooks: new Map([...COMMON_HOOKS]),
218210
},
219-
);
211+
logger: {
212+
debugLogIRs: logIR,
213+
logEvent: () => {},
214+
},
215+
});
216+
transformOutput = invokeCompiler(source, language, opts);
220217
} catch (err) {
221218
/**
222219
* error might be an invariant violation or other runtime error

compiler/apps/playground/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"dev": "cd ../.. && concurrently --kill-others -n compiler,runtime,playground \"yarn workspace babel-plugin-react-compiler run build --watch\" \"yarn workspace react-compiler-runtime run build --watch\" \"wait-on packages/babel-plugin-react-compiler/dist/index.js && cd apps/playground && NODE_ENV=development next dev\"",
6+
"dev": "cd ../.. && concurrently --kill-others -n compiler,runtime,playground \"yarn workspace babel-plugin-react-compiler run watch\" \"yarn workspace react-compiler-runtime run watch\" \"wait-on packages/babel-plugin-react-compiler/dist/index.js && cd apps/playground && NODE_ENV=development next dev\"",
77
"build:compiler": "cd ../.. && concurrently -n compiler,runtime \"yarn workspace babel-plugin-react-compiler run build\" \"yarn workspace react-compiler-runtime run build\"",
88
"build": "yarn build:compiler && next build",
99
"postbuild": "node ./scripts/downloadFonts.js",
10+
"preinstall": "cd ../.. && yarn install --frozen-lockfile",
1011
"postinstall": "./scripts/link-compiler.sh",
1112
"vercel-build": "yarn build",
1213
"start": "next start",

compiler/package.json

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"start": "yarn workspace playground run start",
1616
"next": "yarn workspace playground run dev",
1717
"build": "yarn workspaces run build",
18-
"dev": "echo 'DEPRECATED: use `cd apps/playground && yarn dev` instead!' && sleep 5 && cd apps/playground && yarn dev",
18+
"dev": "cd apps/playground && yarn dev",
1919
"test": "yarn workspaces run test",
2020
"snap": "yarn workspace babel-plugin-react-compiler run snap",
2121
"snap:build": "yarn workspace snap run build",
@@ -26,25 +26,23 @@
2626
"react-is": "0.0.0-experimental-4beb1fd8-20241118"
2727
},
2828
"devDependencies": {
29-
"@rollup/plugin-commonjs": "^25.0.7",
30-
"@rollup/plugin-json": "^6.1.0",
31-
"@rollup/plugin-node-resolve": "^15.2.3",
32-
"@rollup/plugin-terser": "^0.4.4",
33-
"@rollup/plugin-typescript": "^11.1.6",
3429
"@tsconfig/strictest": "^2.0.5",
3530
"concurrently": "^7.4.0",
31+
"esbuild": "^0.24.2",
3632
"folder-hash": "^4.0.4",
33+
"npm-dts": "^1.3.13",
3734
"object-assign": "^4.1.1",
3835
"ora": "5.4.1",
3936
"prettier": "^3.3.3",
40-
"prettier-plugin-hermes-parser": "^0.25.1",
37+
"prettier-plugin-hermes-parser": "^0.26.0",
4138
"prompt-promise": "^1.0.3",
42-
"rollup": "^4.22.4",
43-
"rollup-plugin-banner2": "^1.2.3",
44-
"rollup-plugin-prettier": "^4.1.1",
39+
"rimraf": "^5.0.10",
4540
"typescript": "^5.4.3",
4641
"wait-on": "^7.2.0",
4742
"yargs": "^17.7.2"
4843
},
44+
"resolutions": {
45+
"rimraf": "5.0.10"
46+
},
4947
"packageManager": "yarn@1.22.22"
5048
}

compiler/packages/babel-plugin-react-compiler/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
"!*.tsbuildinfo"
1010
],
1111
"scripts": {
12-
"build": "rimraf dist && rollup --config --bundleConfigAsCjs",
12+
"build": "rimraf dist && scripts/build.js",
1313
"test": "./scripts/link-react-compiler-runtime.sh && yarn snap:ci",
1414
"jest": "yarn build && ts-node node_modules/.bin/jest",
1515
"snap": "node ../snap/dist/main.js",
1616
"snap:build": "yarn workspace snap run build",
1717
"snap:ci": "yarn snap:build && yarn snap",
1818
"ts:analyze-trace": "scripts/ts-analyze-trace.sh",
19-
"lint": "yarn eslint src"
19+
"lint": "yarn eslint src",
20+
"watch": "scripts/build.js --watch"
2021
},
2122
"dependencies": {
2223
"@babel/types": "^7.19.0"
@@ -49,7 +50,6 @@
4950
"pretty-format": "^24",
5051
"react": "0.0.0-experimental-4beb1fd8-20241118",
5152
"react-dom": "0.0.0-experimental-4beb1fd8-20241118",
52-
"rimraf": "^3.0.2",
5353
"ts-jest": "^29.1.1",
5454
"ts-node": "^10.9.2",
5555
"zod": "^3.22.4",

compiler/packages/babel-plugin-react-compiler/rollup.config.js

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)