mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[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:
@@ -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: {
|
||||
|
||||
+1
-1
@@ -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 |
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user