mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[hir][be] Use a Map to store ObjectExpression.properties
Semantically this seems like a better fit as we're using Map like methods to iterate and update values anyway.
This commit is contained in:
@@ -682,7 +682,7 @@ function lowerExpression(
|
||||
case "ObjectExpression": {
|
||||
const expr = exprPath as NodePath<t.ObjectExpression>;
|
||||
const propertyPaths = expr.get("properties");
|
||||
const properties: { [name: string]: Place } = {};
|
||||
const properties: Map<string, Place> = new Map();
|
||||
for (const propertyPath of propertyPaths) {
|
||||
todoInvariant(
|
||||
propertyPath.isObjectProperty(),
|
||||
@@ -696,7 +696,7 @@ function lowerExpression(
|
||||
"Handle non-expression object values"
|
||||
);
|
||||
const value = lowerExpressionToPlace(builder, valuePath);
|
||||
properties[key.name] = value;
|
||||
properties.set(key.name, value);
|
||||
}
|
||||
return {
|
||||
kind: "ObjectExpression",
|
||||
|
||||
@@ -200,7 +200,7 @@ function writeInstr(cx: Context, instr: Instruction, body: Array<t.Statement>) {
|
||||
case "ObjectExpression": {
|
||||
const properties = [];
|
||||
if (instrValue.properties !== null) {
|
||||
for (const [property, value] of Object.entries(instrValue.properties)) {
|
||||
for (const [property, value] of instrValue.properties) {
|
||||
properties.push(
|
||||
t.objectProperty(t.stringLiteral(property), codegenPlace(cx, value))
|
||||
);
|
||||
|
||||
@@ -190,7 +190,7 @@ export type InstructionData =
|
||||
}
|
||||
| {
|
||||
kind: "ObjectExpression";
|
||||
properties: { [property: string]: Place } | null; // null === empty object
|
||||
properties: Map<string, Place> | null; // null === empty object
|
||||
}
|
||||
| { kind: "ArrayExpression"; elements: Array<Place> }
|
||||
|
||||
|
||||
@@ -526,7 +526,7 @@ function inferBlock(env: Environment, block: BasicBlock) {
|
||||
valueKind = ValueKind.Mutable;
|
||||
// Object construction captures but does not modify the key/property values
|
||||
if (instrValue.properties !== null) {
|
||||
for (const [_key, value] of Object.entries(instrValue.properties)) {
|
||||
for (const [_key, value] of instrValue.properties) {
|
||||
env.reference(value, Effect.Read);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ function printInstructionValue(instrValue: InstructionValue): string {
|
||||
case "ObjectExpression": {
|
||||
const properties = [];
|
||||
if (instrValue.properties !== null) {
|
||||
for (const [key, value] of Object.entries(instrValue.properties)) {
|
||||
for (const [key, value] of instrValue.properties) {
|
||||
properties.push(`${key}: ${printPlace(value)}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user