[hir][be] Use a Map to store JsxExpression.props

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:
Sathya Gunasekaran
2022-10-24 16:04:18 +01:00
parent c347e8b6d2
commit f54d121d71
5 changed files with 6 additions and 6 deletions
+2 -2
View File
@@ -860,7 +860,7 @@ function lowerExpression(
const children = expr
.get("children")
.map((child) => lowerJsxElement(builder, child));
const props: { [prop: string]: Place } = {};
const props: Map<string, Place> = new Map();
opening.get("attributes").forEach((attribute) => {
todoInvariant(attribute.isJSXAttribute(), "handle spread attributes");
const name = attribute.get("name");
@@ -882,7 +882,7 @@ function lowerExpression(
value = lowerExpressionToPlace(builder, expression);
}
const prop: string = name.node.name;
props[prop] = value;
props.set(prop, value);
});
return {
kind: "JsxExpression",
+1 -1
View File
@@ -215,7 +215,7 @@ function writeInstr(cx: Context, instr: Instruction, body: Array<t.Statement>) {
}
case "JsxExpression": {
const attributes: Array<t.JSXAttribute> = [];
for (const [prop, value] of Object.entries(instrValue.props)) {
for (const [prop, value] of instrValue.props) {
attributes.push(
t.jsxAttribute(
t.jsxIdentifier(prop),
+1 -1
View File
@@ -185,7 +185,7 @@ export type InstructionData =
| {
kind: "JsxExpression";
tag: Place;
props: { [prop: string]: Place };
props: Map<string, Place>;
children: Array<Place> | null; // null === no children
}
| {
@@ -546,7 +546,7 @@ function inferBlock(env: Environment, block: BasicBlock) {
case "JsxExpression": {
valueKind = ValueKind.Frozen;
env.reference(instrValue.tag, Effect.Freeze);
for (const [_prop, value] of Object.entries(instrValue.props)) {
for (const [_prop, value] of instrValue.props) {
env.reference(value, Effect.Freeze);
}
if (instrValue.children !== null) {
+1 -1
View File
@@ -191,7 +191,7 @@ function printInstructionValue(instrValue: InstructionValue): string {
}
case "JsxExpression": {
const propItems = [];
for (const [prop, value] of Object.entries(instrValue.props)) {
for (const [prop, value] of instrValue.props) {
propItems.push(`${prop}={${printPlace(value)}}`);
}
const props = propItems.length !== 0 ? " " + propItems.join(" ") : "";