@samitouri / QOS-React-1 / commits / 603d2179a8

[hir] Pretty print object property keys

Sathya Gunasekaran committed Sep 7, 2023 at 13:56 UTC 603d2179a879e5b001086e0c38ef79dd3986b8ef
1 file changed +18 -2
compiler/packages/babel-plugin-react-forget/src/HIR/PrintHIR.ts
+18 -2
@@ -19,6 +19,7 @@ import {
19 InstructionValue,
20 LValue,
21 MutableRange,
22 + ObjectProperty,
23 Pattern,
24 Phi,
25 Place,
@@ -243,6 +244,15 @@ function printHole(): string {
244 return "<hole>";
245 }
246
247 +function printObjectPropertyKey(property: ObjectProperty): string {
248 + switch (property.type) {
249 + case "identifier":
250 + return property.name;
251 + case "string":
252 + return `'${property.name}'`;
253 + }
254 +}
255 +
256 export function printInstructionValue(instrValue: ReactiveValue): string {
257 let value = "";
258 switch (instrValue.kind) {
@@ -265,7 +275,11 @@ export function printInstructionValue(instrValue: ReactiveValue): string {
275 if (instrValue.properties !== null) {
276 for (const property of instrValue.properties) {
277 if (property.kind === "ObjectProperty") {
268 - properties.push(`${property.name}: ${printPlace(property.place)}`);
278 + properties.push(
279 + `${printObjectPropertyKey(property)}: ${printPlace(
280 + property.place
281 + )}`
282 + );
283 } else {
284 properties.push(`...${printPlace(property.place)}`);
285 }
@@ -591,7 +605,9 @@ export function printPattern(pattern: Pattern | Place | SpreadPattern): string {
605 .map((item) => {
606 switch (item.kind) {
607 case "ObjectProperty": {
594 - return `${item.name}: ${printPattern(item.place)}`;
608 + return `${printObjectPropertyKey(item)}: ${printPattern(
609 + item.place
610 + )}`;
611 }
612 case "Spread": {
613 return printPattern(item);