diff --git a/compiler/package.json b/compiler/package.json index 12c6de56dc0c6..b478c9f67a41c 100644 --- a/compiler/package.json +++ b/compiler/package.json @@ -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": { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-component-props-non-null.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-component-props-non-null.expect.md index da9ab95fb6b53..8079511850a84 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-component-props-non-null.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-component-props-non-null.expect.md @@ -12,7 +12,7 @@ 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 ; @@ -20,7 +20,7 @@ function Foo(props) { export const FIXTURE_ENTRYPOINT = { fn: Foo, - params: [{value: 2}], + params: [{value: 2, cond: true}], }; ``` @@ -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 = ; - $[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 \ No newline at end of file +(kind: ok)
{"arr":[2]}
\ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-component-props-non-null.tsx b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-component-props-non-null.tsx index d5aa3534d4dc3..2d88e5a790294 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-component-props-non-null.tsx +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/infer-component-props-non-null.tsx @@ -8,7 +8,7 @@ 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 ; @@ -16,5 +16,5 @@ function Foo(props) { export const FIXTURE_ENTRYPOINT = { fn: Foo, - params: [{value: 2}], + params: [{value: 2, cond: true}], }; diff --git a/compiler/packages/snap/package.json b/compiler/packages/snap/package.json index ed0b2dd6438a1..3754260dffeed 100644 --- a/compiler/packages/snap/package.json +++ b/compiler/packages/snap/package.json @@ -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'" }, diff --git a/compiler/packages/snap/scripts/link-react-compiler-runtime.sh b/compiler/packages/snap/scripts/link-react-compiler-runtime.sh new file mode 100755 index 0000000000000..83a30d41d7c8b --- /dev/null +++ b/compiler/packages/snap/scripts/link-react-compiler-runtime.sh @@ -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