@samitouri / QOS-React-2 / commits / 306fe03e78

[printer] Print function name if available

Sathya Gunasekaran committed Nov 15, 2023 at 09:36 UTC 306fe03e7897199175780f80974b05bf376ad4f9
1 file changed +18 -4
compiler/packages/babel-plugin-react-forget/src/HIR/PrintHIR.ts
+18 -4
@@ -9,16 +9,16 @@ import generate from "@babel/generator";
9 import { CompilerError } from "../CompilerError";
10 import DisjointSet from "../Utils/DisjointSet";
11 import { assertExhaustive } from "../Utils/utils";
12 -import {
13 - GotoVariant,
12 +import type {
13 + FunctionExpression,
14 HIR,
15 HIRFunction,
16 Identifier,
17 Instruction,
18 - InstructionKind,
18 InstructionValue,
19 LValue,
20 MutableRange,
21 + ObjectMethod,
22 ObjectPropertyKey,
23 Pattern,
24 Phi,
@@ -31,6 +31,7 @@ import {
31 Terminal,
32 Type,
33 } from "./HIR";
34 +import { GotoVariant, InstructionKind } from "./HIR";
35
36 export type Options = {
37 indent: number;
@@ -470,6 +471,7 @@ export function printInstructionValue(instrValue: ReactiveValue): string {
471 }
472 case "ObjectMethod":
473 case "FunctionExpression": {
474 + const name = getFunctionName(instrValue, "");
475 const fn = printFunction(instrValue.loweredFunc.func)
476 .split("\n")
477 .map((line) => ` ${line}`)
@@ -480,7 +482,7 @@ export function printInstructionValue(instrValue: ReactiveValue): string {
482 const context = instrValue.loweredFunc.func.context
483 .map((dep) => printPlace(dep))
484 .join(",");
483 - value = `Function @deps[${deps}] @context[${context}]:\n${fn}`;
485 + value = `Function ${name} @deps[${deps}] @context[${context}]:\n${fn}`;
486 break;
487 }
488 case "TaggedTemplateExpression": {
@@ -726,3 +728,15 @@ export function printAliases(aliases: DisjointSet<Identifier>): string {
728
729 return items.join("\n");
730 }
731 +
732 +function getFunctionName(
733 + instrValue: ObjectMethod | FunctionExpression,
734 + defaultValue: string
735 +): string {
736 + switch (instrValue.kind) {
737 + case "FunctionExpression":
738 + return instrValue.name ?? defaultValue;
739 + case "ObjectMethod":
740 + return defaultValue;
741 + }
742 +}