feat(language-service): improve non-callable error message (#35271)
This commit improves the context of a non-callable function error message by providing the affected call target and its non-callable type. PR Close #35271
This commit is contained in:

committed by
Andrew Kushnir

parent
168a393589
commit
acc483e2eb
@ -1023,4 +1023,19 @@ describe('diagnostics', () => {
|
||||
expect(content.substring(start !, start ! + length !)).toBe(expression);
|
||||
}
|
||||
});
|
||||
|
||||
describe('function calls', () => {
|
||||
it('should report error for non-callable function call', () => {
|
||||
mockHost.override(TEST_TEMPLATE, `
|
||||
<p>{{myClick()()}}</p>
|
||||
`);
|
||||
|
||||
const content = mockHost.readFile(TEST_TEMPLATE) !;
|
||||
const diags = ngLS.getSemanticDiagnostics(TEST_TEMPLATE);
|
||||
expect(diags.length).toBe(1);
|
||||
const {messageText, start, length} = diags[0] !;
|
||||
expect(messageText).toBe(`Call target 'myClick()' has non-callable type 'void'.`);
|
||||
expect(content.substring(start !, start ! + length !)).toBe('myClick()()');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AotSummaryResolver, CompileMetadataResolver, CompilerConfig, DEFAULT_INTERPOLATION_CONFIG, DirectiveNormalizer, DirectiveResolver, DomElementSchemaRegistry, HtmlParser, I18NHtmlParser, InterpolationConfig, JitSummaryResolver, Lexer, NgAnalyzedModules, NgModuleResolver, ParseTreeResult, Parser, PipeResolver, ResourceLoader, StaticReflector, StaticSymbol, StaticSymbolCache, StaticSymbolResolver, StaticSymbolResolverHost, SummaryResolver, TemplateParser, analyzeNgModules, createOfflineCompileUrlResolver} from '@angular/compiler';
|
||||
import {AotSummaryResolver, CompileMetadataResolver, CompilerConfig, DirectiveNormalizer, DirectiveResolver, DomElementSchemaRegistry, HtmlParser, I18NHtmlParser, JitSummaryResolver, Lexer, NgAnalyzedModules, NgModuleResolver, ParseTreeResult, Parser, PipeResolver, ResourceLoader, StaticReflector, StaticSymbol, StaticSymbolCache, StaticSymbolResolver, StaticSymbolResolverHost, TemplateParser, analyzeNgModules, createOfflineCompileUrlResolver} from '@angular/compiler';
|
||||
import {Directory, MockAotContext} from '@angular/compiler-cli/test/mocks';
|
||||
import {setup} from '@angular/compiler-cli/test/test_support';
|
||||
import {ViewEncapsulation, ɵConsole as Console} from '@angular/core';
|
||||
@ -238,7 +238,8 @@ export function getDiagnosticTemplateInfo(
|
||||
fileName: templateFile,
|
||||
offset: 0, query, members,
|
||||
htmlAst: compiledTemplate.htmlAst,
|
||||
templateAst: compiledTemplate.templateAst
|
||||
templateAst: compiledTemplate.templateAst,
|
||||
source: sourceFile.text,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user