Skip to content

Commit 2daa703

Browse files
committed
[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-poisoned]
1 parent 9f89dbf commit 2daa703

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {CompilerError, CompilerErrorDetailOptions} from '../CompilerError';
1111
import {assertExhaustive} from '../Utils/utils';
1212
import {Environment, ReactFunctionType} from './Environment';
1313
import {HookKind} from './ObjectShape';
14-
import {Type} from './Types';
14+
import {Type, makeType} from './Types';
1515

1616
/*
1717
* *******************************************************************************************
@@ -1205,6 +1205,20 @@ export type ValidIdentifierName = string & {
12051205
[opaqueValidIdentifierName]: 'ValidIdentifierName';
12061206
};
12071207

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+
12081222
/**
12091223
* Creates a valid identifier name. This should *not* be used for synthesizing
12101224
* identifier names: only call this method for identifier names that appear in the

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
makeBlockId,
2828
makeIdentifierName,
2929
makeInstructionId,
30+
makeTemporary,
3031
makeType,
3132
} from './HIR';
3233
import {printInstruction} from './PrintHIR';
@@ -182,14 +183,7 @@ export default class HIRBuilder {
182183

183184
makeTemporary(loc: SourceLocation): Identifier {
184185
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);
193187
}
194188

195189
#resolveBabelBinding(

0 commit comments

Comments
 (0)