move to invocationErrorDetails
This commit is contained in:
parent
d00f2b53ad
commit
6051fc1814
1 changed files with 15 additions and 17 deletions
|
@ -26049,7 +26049,7 @@ namespace ts {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function invocationErrorDetails(apparentType: Type, kind: SignatureKind): { messageChain: DiagnosticMessageChain, relatedMessage: DiagnosticMessage | undefined } {
|
function invocationErrorDetails(errorTarget: Node, apparentType: Type, kind: SignatureKind): { messageChain: DiagnosticMessageChain, relatedMessage: DiagnosticMessage | undefined } {
|
||||||
let errorInfo: DiagnosticMessageChain | undefined;
|
let errorInfo: DiagnosticMessageChain | undefined;
|
||||||
const isCall = kind === SignatureKind.Call;
|
const isCall = kind === SignatureKind.Call;
|
||||||
const awaitedType = getAwaitedType(apparentType);
|
const awaitedType = getAwaitedType(apparentType);
|
||||||
|
@ -26118,6 +26118,15 @@ namespace ts {
|
||||||
typeToString(apparentType)
|
typeToString(apparentType)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Diagnose get accessors incorrectly called as functions
|
||||||
|
if (isCallExpression(errorTarget.parent) && errorTarget.parent.arguments.length === 0) {
|
||||||
|
const { resolvedSymbol } = getNodeLinks(errorTarget);
|
||||||
|
if (resolvedSymbol && resolvedSymbol.flags & SymbolFlags.GetAccessor) {
|
||||||
|
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messageChain: chainDiagnosticMessages(
|
messageChain: chainDiagnosticMessages(
|
||||||
errorInfo,
|
errorInfo,
|
||||||
|
@ -26127,21 +26136,10 @@ namespace ts {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function invocationError(errorTarget: Node, apparentType: Type, kind: SignatureKind, relatedInformation?: DiagnosticRelatedInformation) {
|
function invocationError(errorTarget: Node, apparentType: Type, kind: SignatureKind, relatedInformation?: DiagnosticRelatedInformation) {
|
||||||
let diagnostic;
|
const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(errorTarget, apparentType, kind);
|
||||||
if (isCallExpression(errorTarget.parent) && errorTarget.parent.arguments.length === 0) {
|
const diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, messageChain);
|
||||||
// Diagnose get accessors incorrectly called as functions
|
if (relatedInfo) {
|
||||||
const { resolvedSymbol } = getNodeLinks(errorTarget);
|
addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo));
|
||||||
if (resolvedSymbol && resolvedSymbol.flags & SymbolFlags.GetAccessor) {
|
|
||||||
diagnostic = createDiagnosticForNode(errorTarget, Diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without);
|
|
||||||
addRelatedInfo(diagnostic, createDiagnosticForNode(resolvedSymbol.valueDeclaration, Diagnostics._0_is_declared_here, symbolToString(resolvedSymbol)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!diagnostic) {
|
|
||||||
const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(apparentType, kind);
|
|
||||||
diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, messageChain);
|
|
||||||
if (relatedInfo) {
|
|
||||||
addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (isCallExpression(errorTarget.parent)) {
|
if (isCallExpression(errorTarget.parent)) {
|
||||||
const { start, length } = getDiagnosticSpanForCallNode(errorTarget.parent, /* doNotIncludeArguments */ true);
|
const { start, length } = getDiagnosticSpanForCallNode(errorTarget.parent, /* doNotIncludeArguments */ true);
|
||||||
|
@ -26242,7 +26240,7 @@ namespace ts {
|
||||||
|
|
||||||
const headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
|
const headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
|
||||||
if (!callSignatures.length) {
|
if (!callSignatures.length) {
|
||||||
const errorDetails = invocationErrorDetails(apparentType, SignatureKind.Call);
|
const errorDetails = invocationErrorDetails(node.expression, apparentType, SignatureKind.Call);
|
||||||
const messageChain = chainDiagnosticMessages(errorDetails.messageChain, headMessage);
|
const messageChain = chainDiagnosticMessages(errorDetails.messageChain, headMessage);
|
||||||
const diag = createDiagnosticForNodeFromMessageChain(node.expression, messageChain);
|
const diag = createDiagnosticForNodeFromMessageChain(node.expression, messageChain);
|
||||||
if (errorDetails.relatedMessage) {
|
if (errorDetails.relatedMessage) {
|
||||||
|
|
Loading…
Reference in a new issue