[compiler] Refactor makeTemporary outside HIRBuilder
This is a useful utility function similar to the existing `makeInstructionId` and `makeIdentifierId` functions. This PR moves it outside the HIRBuilder so we can use this in passes that don't have access to the builder instance. ghstack-source-id: 1ac0839e6cb417aedcdf8cdd159af7069af7172a Pull Request resolved: https://github.com/facebook/react/pull/30545
Sathya Gunsasekaran committed
Jul 31, 2024 at 14:35 UTC
ce6078521e0203585c4d0ff15c64d4405ae1bfb5
2 files changed
+17
-9
compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts
+15
-1
@@ -11,7 +11,7 @@ import {CompilerError, CompilerErrorDetailOptions} from '../CompilerError';
11
import {assertExhaustive} from '../Utils/utils';
12
import {Environment, ReactFunctionType} from './Environment';
13
import {HookKind} from './ObjectShape';
14
-import {Type} from './Types';
14
+import {Type, makeType} from './Types';
15
16
/*
17
* *******************************************************************************************
@@ -1205,6 +1205,20 @@ export type ValidIdentifierName = string & {
1205
[opaqueValidIdentifierName]: 'ValidIdentifierName';
1206
};
1207
1208
+export function makeTemporary(
1209
+ id: IdentifierId,
1210
+ loc: SourceLocation,
1211
+): Identifier {
1212
+ return {
1213
+ id,
1214
+ name: null,
1215
+ mutableRange: {start: makeInstructionId(0), end: makeInstructionId(0)},
1216
+ scope: null,
1217
+ type: makeType(),
1218
+ loc,
1219
+ };
1220
+}
1221
+
1222
/**
1223
* Creates a valid identifier name. This should *not* be used for synthesizing
1224
* identifier names: only call this method for identifier names that appear in the
compiler/packages/babel-plugin-react-compiler/src/HIR/HIRBuilder.ts
+2
-8
@@ -27,6 +27,7 @@ import {
27
makeBlockId,
28
makeIdentifierName,
29
makeInstructionId,
30
+ makeTemporary,
31
makeType,
32
} from './HIR';
33
import {printInstruction} from './PrintHIR';
@@ -182,14 +183,7 @@ export default class HIRBuilder {
183
184
makeTemporary(loc: SourceLocation): Identifier {
185
const id = this.nextIdentifierId;
185
- return {
186
- id,
187
- name: null,
188
- mutableRange: {start: makeInstructionId(0), end: makeInstructionId(0)},
189
- scope: null,
190
- type: makeType(),
191
- loc,
192
- };
186
+ return makeTemporary(id, loc);
187
}
188
189
#resolveBabelBinding(