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
This commit is contained in:
Lauren Tan
2022-10-14 17:36:20 -04:00
parent 33735b90fe
commit 9e8224cc59
2 changed files with 4 additions and 2 deletions
+2 -1
View File
@@ -154,6 +154,7 @@ export type DiagnosticOpts =
path: NodePath;
context: {
callee: NodePath | NodePath[];
init: NodePath | NodePath[];
};
}
| { code: "E0008"; path: NodePath; context: { input: NodePath } }
@@ -224,7 +225,7 @@ function getDiagnosticMessage(opts: DiagnosticOpts): DiagnosticMessage {
body: `\`${getSource(
opts.context.callee
)}\` does not have a return value.`,
suggestion: `Do \`${getSource(opts.path.get("init"))}\` instead.`,
suggestion: `Do \`${getSource(opts.context.init)}\` instead.`,
};
case "E0008":
return {
+2 -1
View File
@@ -505,11 +505,12 @@ function matchHookCallRetVals(
function matchVoid(_pattern: Void, lvals: NodePath<t.LVal>) {
if (lvals.isPatternLike()) {
let init = lvals.parentPath.get("init");
let callee = lvals.parentPath.get("init.callee");
context.createDiagnostic({
code: "E0007",
path: lvals.parentPath,
context: { callee },
context: { callee, init },
});
}
}