diff --git a/compiler/packages/babel-plugin-react-compiler/src/Optimization/ConstantPropagation.ts b/compiler/packages/babel-plugin-react-compiler/src/Optimization/ConstantPropagation.ts
index b9b16a93ffa6c..9369a4eef23d0 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/Optimization/ConstantPropagation.ts
+++ b/compiler/packages/babel-plugin-react-compiler/src/Optimization/ConstantPropagation.ts
@@ -311,6 +311,25 @@ function evaluateInstruction(
}
return null;
}
+ case "UnaryExpression": {
+ switch (value.operator) {
+ case "!": {
+ const operand = read(constants, value.value);
+ if (operand !== null && operand.kind === "Primitive") {
+ const result: Primitive = {
+ kind: "Primitive",
+ value: !operand.value,
+ loc: value.loc,
+ };
+ instr.value = result;
+ return result;
+ }
+ return null;
+ }
+ default:
+ return null;
+ }
+ }
case "BinaryExpression": {
const lhsValue = read(constants, value.left);
const rhsValue = read(constants, value.right);
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/constant-propagation-unary.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/constant-propagation-unary.expect.md
new file mode 100644
index 0000000000000..50b1a10a24d3e
--- /dev/null
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/constant-propagation-unary.expect.md
@@ -0,0 +1,86 @@
+
+## Input
+
+```javascript
+import { Stringify } from "shared-runtime";
+
+function foo() {
+ let _b;
+ const b = true;
+ if (!b) {
+ _b = "bar";
+ } else {
+ _b = "baz";
+ }
+
+ return (
+