Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[snap] Add react-compiler-runtime as a dependency #31142

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"test": "yarn workspaces run test",
"snap": "yarn workspace babel-plugin-react-compiler run snap",
"snap:build": "yarn workspace snap run build",
"postinstall": "perl -p -i -e 's/react\\.element/react.transitional.element/' node_modules/fbt/lib/FbtReactUtil.js && perl -p -i -e 's/didWarnAboutUsingAct = false;/didWarnAboutUsingAct = true;/' node_modules/react-dom/cjs/react-dom-test-utils.development.js",
"npm:publish": "node scripts/release/publish"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ function Foo(props) {
* as it is arg[0] of a component function
*/
const arr = [];
if (cond) {
if (props.cond) {
arr.push(identity(props.value));
}
return <Stringify arr={arr} />;
}

export const FIXTURE_ENTRYPOINT = {
fn: Foo,
params: [{value: 2}],
params: [{value: 2, cond: true}],
};

```
Expand All @@ -32,29 +32,38 @@ import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
import { identity, Stringify } from "shared-runtime";

function Foo(props) {
const $ = _c(2);
const $ = _c(5);
let t0;
if ($[0] !== props.value) {
if ($[0] !== props.cond || $[1] !== props.value) {
const arr = [];
if (cond) {
arr.push(identity(props.value));
if (props.cond) {
let t1;
if ($[3] !== props.value) {
t1 = identity(props.value);
$[3] = props.value;
$[4] = t1;
} else {
t1 = $[4];
}
arr.push(t1);
}

t0 = <Stringify arr={arr} />;
$[0] = props.value;
$[1] = t0;
$[0] = props.cond;
$[1] = props.value;
$[2] = t0;
} else {
t0 = $[1];
t0 = $[2];
}
return t0;
}

export const FIXTURE_ENTRYPOINT = {
fn: Foo,
params: [{ value: 2 }],
params: [{ value: 2, cond: true }],
};

```

### Eval output
(kind: exception) cond is not defined
(kind: ok) <div>{"arr":[2]}</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ function Foo(props) {
* as it is arg[0] of a component function
*/
const arr = [];
if (cond) {
if (props.cond) {
arr.push(identity(props.value));
}
return <Stringify arr={arr} />;
}

export const FIXTURE_ENTRYPOINT = {
fn: Foo,
params: [{value: 2}],
params: [{value: 2, cond: true}],
};
3 changes: 2 additions & 1 deletion compiler/packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"src"
],
"scripts": {
"build": "rimraf dist && tsc --build",
"postinstall": "./scripts/link-react-compiler-runtime.sh && perl -p -i -e 's/react\\.element/react.transitional.element/' ../../node_modules/fbt/lib/FbtReactUtil.js && perl -p -i -e 's/didWarnAboutUsingAct = false;/didWarnAboutUsingAct = true;/' ../../node_modules/react-dom/cjs/react-dom-test-utils.development.js",
"build": "rimraf dist && concurrently -n snap,runtime \"tsc --build\" \"yarn --silent workspace react-compiler-runtime build --silent\"",
"test": "echo 'no tests'",
"prettier": "prettier --write 'src/**/*.ts'"
},
Expand Down
10 changes: 10 additions & 0 deletions compiler/packages/snap/scripts/link-react-compiler-runtime.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

set -eo pipefail

yarn --silent workspace react-compiler-runtime link
yarn --silent workspace snap link react-compiler-runtime