mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Rename promoteTemporary helpers
Renames the helpers for promoting temporaries to named identifiers, per feedback earlier in the stack.
This commit is contained in:
@@ -44,7 +44,7 @@ import {
|
||||
Type,
|
||||
makeInstructionId,
|
||||
makeType,
|
||||
promoteTemporaryToNamedIdentifier,
|
||||
promoteTemporary,
|
||||
} from "./HIR";
|
||||
import HIRBuilder, { Bindings } from "./HIRBuilder";
|
||||
import { BuiltInArrayId } from "./ObjectShape";
|
||||
@@ -1216,7 +1216,7 @@ function lowerStatement(
|
||||
reactive: false,
|
||||
loc: handlerBindingPath.node.loc ?? GeneratedSource,
|
||||
};
|
||||
promoteTemporaryToNamedIdentifier(place.identifier);
|
||||
promoteTemporary(place.identifier);
|
||||
lowerValueToTemporary(builder, {
|
||||
kind: "DeclareLocal",
|
||||
lvalue: {
|
||||
@@ -3422,7 +3422,7 @@ function lowerAssignment(
|
||||
builder,
|
||||
element.node.loc ?? GeneratedSource
|
||||
);
|
||||
promoteTemporaryToNamedIdentifier(temp.identifier);
|
||||
promoteTemporary(temp.identifier);
|
||||
items.push({
|
||||
kind: "Spread",
|
||||
place: { ...temp },
|
||||
@@ -3450,7 +3450,7 @@ function lowerAssignment(
|
||||
builder,
|
||||
element.node.loc ?? GeneratedSource
|
||||
);
|
||||
promoteTemporaryToNamedIdentifier(temp.identifier);
|
||||
promoteTemporary(temp.identifier);
|
||||
items.push({ ...temp });
|
||||
followups.push({ place: temp, path: element as NodePath<t.LVal> }); // TODO remove type cast
|
||||
}
|
||||
@@ -3521,7 +3521,7 @@ function lowerAssignment(
|
||||
builder,
|
||||
property.node.loc ?? GeneratedSource
|
||||
);
|
||||
promoteTemporaryToNamedIdentifier(temp.identifier);
|
||||
promoteTemporary(temp.identifier);
|
||||
properties.push({
|
||||
kind: "Spread",
|
||||
place: { ...temp },
|
||||
@@ -3602,7 +3602,7 @@ function lowerAssignment(
|
||||
builder,
|
||||
element.node.loc ?? GeneratedSource
|
||||
);
|
||||
promoteTemporaryToNamedIdentifier(temp.identifier);
|
||||
promoteTemporary(temp.identifier);
|
||||
properties.push({
|
||||
kind: "ObjectProperty",
|
||||
type: "property",
|
||||
|
||||
@@ -1004,9 +1004,7 @@ export function makeIdentifierName(name: string): ValidatedIdentifier {
|
||||
/**
|
||||
* Given an unnamed identifier, promote it to a named identifier.
|
||||
*/
|
||||
export function promoteTemporaryToNamedIdentifier(
|
||||
identifier: Identifier
|
||||
): void {
|
||||
export function promoteTemporary(identifier: Identifier): void {
|
||||
CompilerError.invariant(identifier.name === null, {
|
||||
reason: `Expected a temporary (unnamed) identifier`,
|
||||
loc: GeneratedSource,
|
||||
@@ -1027,9 +1025,7 @@ export function isPromotedTemporary(name: string): boolean {
|
||||
* Given an unnamed identifier, promote it to a named identifier, distinguishing
|
||||
* it as a value that needs to be capitalized since it appears in JSX element tag position
|
||||
*/
|
||||
export function promoteTemporaryJsxTagToNamedIdentifier(
|
||||
identifier: Identifier
|
||||
): void {
|
||||
export function promoteTemporaryJsxTag(identifier: Identifier): void {
|
||||
CompilerError.invariant(identifier.name === null, {
|
||||
reason: `Expected a temporary (unnamed) identifier`,
|
||||
loc: GeneratedSource,
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ import {
|
||||
Place,
|
||||
makeInstructionId,
|
||||
makeType,
|
||||
promoteTemporaryToNamedIdentifier,
|
||||
promoteTemporary,
|
||||
reversePostorderBlocks,
|
||||
} from "../HIR";
|
||||
import { markInstructionIds, markPredecessors } from "../HIR/HIRBuilder";
|
||||
@@ -159,7 +159,7 @@ export function inlineImmediatelyInvokedFunctionExpressions(
|
||||
declareTemporary(fn.env, block, result);
|
||||
|
||||
// Promote the temporary with a name as we require this to persist
|
||||
promoteTemporaryToNamedIdentifier(result.identifier);
|
||||
promoteTemporary(result.identifier);
|
||||
|
||||
/*
|
||||
* Rewrite blocks from the lambda to replace any `return` with a
|
||||
|
||||
+2
-4
@@ -2060,13 +2060,11 @@ function codegenPlace(cx: Context, place: Place): t.Expression | t.JSXText {
|
||||
}
|
||||
|
||||
function convertIdentifier(identifier: Identifier): t.Identifier {
|
||||
if (identifier.name !== null) {
|
||||
return t.identifier(identifier.name.value);
|
||||
}
|
||||
CompilerError.invariant(false, {
|
||||
CompilerError.invariant(identifier.name !== null, {
|
||||
reason: `Expected temporaries to be promoted to named identifiers in an earlier pass`,
|
||||
loc: GeneratedSource,
|
||||
description: `identifier ${identifier.id} is unnamed`,
|
||||
suggestions: null,
|
||||
});
|
||||
return t.identifier(identifier.name.value);
|
||||
}
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ import {
|
||||
ReactiveInstruction,
|
||||
ReactiveScopeBlock,
|
||||
ReactiveStatement,
|
||||
promoteTemporaryToNamedIdentifier,
|
||||
promoteTemporary,
|
||||
} from "../HIR";
|
||||
import { eachPatternOperand, mapPatternOperands } from "../HIR/visitors";
|
||||
import {
|
||||
@@ -159,7 +159,7 @@ function transformDestructuring(
|
||||
name: null, // overwritten below
|
||||
},
|
||||
};
|
||||
promoteTemporaryToNamedIdentifier(temporary.identifier);
|
||||
promoteTemporary(temporary.identifier);
|
||||
renamed.set(place, temporary);
|
||||
return temporary;
|
||||
});
|
||||
|
||||
+10
-10
@@ -15,8 +15,8 @@ import {
|
||||
ReactiveFunction,
|
||||
ReactiveScopeBlock,
|
||||
ReactiveValue,
|
||||
promoteTemporaryJsxTagToNamedIdentifier,
|
||||
promoteTemporaryToNamedIdentifier,
|
||||
promoteTemporary,
|
||||
promoteTemporaryJsxTag,
|
||||
} from "../HIR/HIR";
|
||||
import { ReactiveFunctionVisitor, visitReactiveFunction } from "./visitors";
|
||||
|
||||
@@ -29,7 +29,7 @@ class Visitor extends ReactiveFunctionVisitor<VisitorState> {
|
||||
for (const dep of block.scope.dependencies) {
|
||||
const { identifier } = dep;
|
||||
if (identifier.name == null) {
|
||||
promoteTemporary(identifier, state);
|
||||
promoteIdentifier(identifier, state);
|
||||
}
|
||||
}
|
||||
/*
|
||||
@@ -41,14 +41,14 @@ class Visitor extends ReactiveFunctionVisitor<VisitorState> {
|
||||
*/
|
||||
for (const [, declaration] of block.scope.declarations) {
|
||||
if (declaration.identifier.name == null) {
|
||||
promoteTemporary(declaration.identifier, state);
|
||||
promoteIdentifier(declaration.identifier, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override visitParam(place: Place, state: VisitorState): void {
|
||||
if (place.identifier.name === null) {
|
||||
promoteTemporary(place.identifier, state);
|
||||
promoteIdentifier(place.identifier, state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class Visitor extends ReactiveFunctionVisitor<VisitorState> {
|
||||
for (const operand of fn.params) {
|
||||
const place = operand.kind === "Identifier" ? operand : operand.place;
|
||||
if (place.identifier.name === null) {
|
||||
promoteTemporary(place.identifier, state);
|
||||
promoteIdentifier(place.identifier, state);
|
||||
}
|
||||
}
|
||||
visitReactiveFunction(fn, this, state);
|
||||
@@ -102,13 +102,13 @@ export function promoteUsedTemporaries(fn: ReactiveFunction): void {
|
||||
for (const operand of fn.params) {
|
||||
const place = operand.kind === "Identifier" ? operand : operand.place;
|
||||
if (place.identifier.name === null) {
|
||||
promoteTemporary(place.identifier, state);
|
||||
promoteIdentifier(place.identifier, state);
|
||||
}
|
||||
}
|
||||
visitReactiveFunction(fn, new Visitor(), state);
|
||||
}
|
||||
|
||||
function promoteTemporary(identifier: Identifier, state: VisitorState): void {
|
||||
function promoteIdentifier(identifier: Identifier, state: VisitorState): void {
|
||||
CompilerError.invariant(identifier.name === null, {
|
||||
reason:
|
||||
"promoteTemporary: Expected to be called only for temporary variables",
|
||||
@@ -117,8 +117,8 @@ function promoteTemporary(identifier: Identifier, state: VisitorState): void {
|
||||
suggestions: null,
|
||||
});
|
||||
if (state.tags.has(identifier.id)) {
|
||||
promoteTemporaryJsxTagToNamedIdentifier(identifier);
|
||||
promoteTemporaryJsxTag(identifier);
|
||||
} else {
|
||||
promoteTemporaryToNamedIdentifier(identifier);
|
||||
promoteTemporary(identifier);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ import {
|
||||
ReactiveStatement,
|
||||
ReactiveTerminalStatement,
|
||||
makeInstructionId,
|
||||
promoteTemporaryToNamedIdentifier,
|
||||
promoteTemporary,
|
||||
} from "../HIR";
|
||||
import { createTemporaryPlace } from "../HIR/HIRBuilder";
|
||||
import { EARLY_RETURN_SENTINEL } from "./CodegenReactiveFunction";
|
||||
@@ -275,7 +275,7 @@ class Transform extends ReactiveFunctionTransform<State> {
|
||||
earlyReturnValue = state.earlyReturnValue;
|
||||
} else {
|
||||
const identifier = createTemporaryPlace(this.env).identifier;
|
||||
promoteTemporaryToNamedIdentifier(identifier);
|
||||
promoteTemporary(identifier);
|
||||
earlyReturnValue = {
|
||||
label: this.env.nextBlockId,
|
||||
loc,
|
||||
|
||||
Reference in New Issue
Block a user