mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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:
@@ -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 {
|
||||
|
||||
@@ -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 },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user