From 603d2179a879e5b001086e0c38ef79dd3986b8ef Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Thu, 7 Sep 2023 13:56:59 +0100 Subject: [PATCH] [hir] Pretty print object property keys --- .../src/HIR/PrintHIR.ts | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/compiler/packages/babel-plugin-react-forget/src/HIR/PrintHIR.ts b/compiler/packages/babel-plugin-react-forget/src/HIR/PrintHIR.ts index c6ff2c7055..f7de1aa59c 100644 --- a/compiler/packages/babel-plugin-react-forget/src/HIR/PrintHIR.ts +++ b/compiler/packages/babel-plugin-react-forget/src/HIR/PrintHIR.ts @@ -19,6 +19,7 @@ import { InstructionValue, LValue, MutableRange, + ObjectProperty, Pattern, Phi, Place, @@ -243,6 +244,15 @@ function printHole(): string { return ""; } +function printObjectPropertyKey(property: ObjectProperty): string { + switch (property.type) { + case "identifier": + return property.name; + case "string": + return `'${property.name}'`; + } +} + export function printInstructionValue(instrValue: ReactiveValue): string { let value = ""; switch (instrValue.kind) { @@ -265,7 +275,11 @@ export function printInstructionValue(instrValue: ReactiveValue): string { if (instrValue.properties !== null) { for (const property of instrValue.properties) { if (property.kind === "ObjectProperty") { - properties.push(`${property.name}: ${printPlace(property.place)}`); + properties.push( + `${printObjectPropertyKey(property)}: ${printPlace( + property.place + )}` + ); } else { properties.push(`...${printPlace(property.place)}`); } @@ -591,7 +605,9 @@ export function printPattern(pattern: Pattern | Place | SpreadPattern): string { .map((item) => { switch (item.kind) { case "ObjectProperty": { - return `${item.name}: ${printPattern(item.place)}`; + return `${printObjectPropertyKey(item)}: ${printPattern( + item.place + )}`; } case "Spread": { return printPattern(item);