Skip to content

Commit 217a0ef

Browse files
committed
[compiler] Add returnIdentifier to function expressions
This gives us a place to store type information, used in follow-up PRs. ghstack-source-id: ee0bfa2 Pull Request resolved: #30784
1 parent 8a20fc3 commit 217a0ef

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,14 @@ export function lower(
211211
null,
212212
);
213213

214+
const returnIdentifier = builder.makeTemporary(func.node.loc ?? GeneratedSource);
215+
214216
return Ok({
215217
id,
216218
params,
217219
fnType: parent == null ? env.fnType : 'Other',
218220
returnType: null, // TODO: extract the actual return type node if present
221+
returnIdentifier,
219222
body: builder.build(),
220223
context,
221224
generator: func.node.generator === true,

compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ export type HIRFunction = {
286286
env: Environment;
287287
params: Array<Place | SpreadPattern>;
288288
returnType: t.FlowType | t.TSType | null;
289+
returnIdentifier: Identifier;
289290
context: Array<Place>;
290291
effects: Array<FunctionEffect> | null;
291292
body: HIR;

compiler/packages/babel-plugin-react-compiler/src/Optimization/LowerContextAccess.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,15 @@ function emitSelectorFn(env: Environment, keys: Array<string>): Instruction {
238238
phis: new Set(),
239239
};
240240

241+
const returnIdentifier = createTemporaryPlace(env, GeneratedSource).identifier;
241242
const fn: HIRFunction = {
242243
loc: GeneratedSource,
243244
id: null,
244245
fnType: 'Other',
245246
env,
246247
params: [obj],
247248
returnType: null,
249+
returnIdentifier,
248250
context: [],
249251
effects: null,
250252
body: {

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-repro-named-function-with-shadowed-local-same-name.expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function Component(props) {
2222
7 | return hasErrors;
2323
8 | }
2424
> 9 | return hasErrors();
25-
| ^^^^^^^^^ Invariant: [hoisting] Expected value for identifier to be initialized. hasErrors_0$16 (9:9)
25+
| ^^^^^^^^^ Invariant: [hoisting] Expected value for identifier to be initialized. hasErrors_0$17 (9:9)
2626
10 | }
2727
11 |
2828
```

0 commit comments

Comments
 (0)