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

fix(react-compiler): optimize components declared with arrow function and implicit return and compilationMode: 'infer' #31792

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,10 @@ function returnsNonNode(
t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression
>,
): boolean {
if (node.type === 'ArrowFunctionExpression' && node.node.body.type === 'JSXElement') {
return false
}

let hasReturn = false;
let returnsNonNode = false;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

## Input

```javascript
// @compilationMode(infer)
const Test = () => <div />;

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime"; // @compilationMode(infer)
const Test = () => {
const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = <div />;
$[0] = t0;
} else {
t0 = $[0];
}
return t0;
};

```

### Eval output
(kind: exception) Fixture not implemented
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @compilationMode(infer)
const Test = () => <div />;