@samitouri / QOS-React / commits / 9e8224cc59

Pass `init` to E0007 diagnostic

I'm not sure why exactly but previously this diagnostic message was unusually slow to typecheck. Lifting the getter for init outside of the diagnostic to the callsite seems to fix the hotspot. Probably some interaction with string interpolation, or something else. Test case: ran `yarn ts:analyze-trace`, hotspot for Diagnostic.ts no longer present

Lauren Tan committed Oct 14, 2022 at 17:36 UTC 9e8224cc5973d5d3d919b154d78352fe193a1376
2 files changed +4 -2
compiler/forget/src/Diagnostic.ts
+2 -1
@@ -154,6 +154,7 @@ export type DiagnosticOpts =
154 path: NodePath;
155 context: {
156 callee: NodePath | NodePath[];
157 + init: NodePath | NodePath[];
158 };
159 }
160 | { code: "E0008"; path: NodePath; context: { input: NodePath } }
@@ -224,7 +225,7 @@ function getDiagnosticMessage(opts: DiagnosticOpts): DiagnosticMessage {
225 body: `\`${getSource(
226 opts.context.callee
227 )}\` does not have a return value.`,
227 - suggestion: `Do \`${getSource(opts.path.get("init"))}\` instead.`,
228 + suggestion: `Do \`${getSource(opts.context.init)}\` instead.`,
229 };
230 case "E0008":
231 return {
compiler/forget/src/IR/Hook.ts
+2 -1
@@ -505,11 +505,12 @@ function matchHookCallRetVals(
505
506 function matchVoid(_pattern: Void, lvals: NodePath<t.LVal>) {
507 if (lvals.isPatternLike()) {
508 + let init = lvals.parentPath.get("init");
509 let callee = lvals.parentPath.get("init.callee");
510 context.createDiagnostic({
511 code: "E0007",
512 path: lvals.parentPath,
512 - context: { callee },
513 + context: { callee, init },
514 });
515 }
516 }