Skip to content

[compiler] Refactor makeTemporary outside HIRBuilder #30545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {CompilerError, CompilerErrorDetailOptions} from '../CompilerError';
import {assertExhaustive} from '../Utils/utils';
import {Environment, ReactFunctionType} from './Environment';
import {HookKind} from './ObjectShape';
import {Type} from './Types';
import {Type, makeType} from './Types';

/*
* *******************************************************************************************
Expand Down Expand Up @@ -1205,6 +1205,20 @@ export type ValidIdentifierName = string & {
[opaqueValidIdentifierName]: 'ValidIdentifierName';
};

export function makeTemporary(
id: IdentifierId,
loc: SourceLocation,
): Identifier {
return {
id,
name: null,
mutableRange: {start: makeInstructionId(0), end: makeInstructionId(0)},
scope: null,
type: makeType(),
loc,
};
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a heads up that we also have createTemporaryPlace() which we could maybe unify

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do this in a follow up!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done here #30585

/**
* Creates a valid identifier name. This should *not* be used for synthesizing
* identifier names: only call this method for identifier names that appear in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
makeBlockId,
makeIdentifierName,
makeInstructionId,
makeTemporary,
makeType,
} from './HIR';
import {printInstruction} from './PrintHIR';
Expand Down Expand Up @@ -182,14 +183,7 @@ export default class HIRBuilder {

makeTemporary(loc: SourceLocation): Identifier {
const id = this.nextIdentifierId;
return {
id,
name: null,
mutableRange: {start: makeInstructionId(0), end: makeInstructionId(0)},
scope: null,
type: makeType(),
loc,
};
return makeTemporary(id, loc);
}

#resolveBabelBinding(
Expand Down