[compiler] Add returnIdentifier to function expressions

This gives us a place to store type information, used in follow-up PRs.

ghstack-source-id: ee0bfa253f
Pull Request resolved: https://github.com/facebook/react/pull/30784
This commit is contained in:
Joe Savona
2024-08-22 09:33:09 -07:00
parent 8a20fc3b19
commit 217a0efcd9
4 changed files with 7 additions and 1 deletions
@@ -211,11 +211,14 @@ export function lower(
null,
);
const returnIdentifier = builder.makeTemporary(func.node.loc ?? GeneratedSource);
return Ok({
id,
params,
fnType: parent == null ? env.fnType : 'Other',
returnType: null, // TODO: extract the actual return type node if present
returnIdentifier,
body: builder.build(),
context,
generator: func.node.generator === true,
@@ -286,6 +286,7 @@ export type HIRFunction = {
env: Environment;
params: Array<Place | SpreadPattern>;
returnType: t.FlowType | t.TSType | null;
returnIdentifier: Identifier;
context: Array<Place>;
effects: Array<FunctionEffect> | null;
body: HIR;
@@ -238,6 +238,7 @@ function emitSelectorFn(env: Environment, keys: Array<string>): Instruction {
phis: new Set(),
};
const returnIdentifier = createTemporaryPlace(env, GeneratedSource).identifier;
const fn: HIRFunction = {
loc: GeneratedSource,
id: null,
@@ -245,6 +246,7 @@ function emitSelectorFn(env: Environment, keys: Array<string>): Instruction {
env,
params: [obj],
returnType: null,
returnIdentifier,
context: [],
effects: null,
body: {
@@ -22,7 +22,7 @@ function Component(props) {
7 | return hasErrors;
8 | }
> 9 | return hasErrors();
| ^^^^^^^^^ Invariant: [hoisting] Expected value for identifier to be initialized. hasErrors_0$16 (9:9)
| ^^^^^^^^^ Invariant: [hoisting] Expected value for identifier to be initialized. hasErrors_0$17 (9:9)
10 | }
11 |
```