fix(language-service): Improve signature selection for pipes with args (#33456)
Pipes with arguments like `slice:0` or `slice:0:1` should not produce diagnostic errors. PR closes https://github.com/angular/vscode-ng-language-service/issues/345 PR Close #33456
This commit is contained in:
parent
5ed6abe3df
commit
1de757993d
|
@ -557,7 +557,7 @@ class PipeSymbol implements Symbol {
|
||||||
|
|
||||||
selectSignature(types: Symbol[]): Signature|undefined {
|
selectSignature(types: Symbol[]): Signature|undefined {
|
||||||
let signature = selectSignature(this.tsType, this.context, types) !;
|
let signature = selectSignature(this.tsType, this.context, types) !;
|
||||||
if (types.length == 1) {
|
if (types.length > 0) {
|
||||||
const parameterType = types[0];
|
const parameterType = types[0];
|
||||||
if (parameterType instanceof TypeWrapper) {
|
if (parameterType instanceof TypeWrapper) {
|
||||||
let resultType: ts.Type|undefined = undefined;
|
let resultType: ts.Type|undefined = undefined;
|
||||||
|
@ -575,7 +575,7 @@ class PipeSymbol implements Symbol {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'slice':
|
case 'slice':
|
||||||
resultType = getTypeParameterOf(parameterType.tsType, 'Array');
|
resultType = parameterType.tsType;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (resultType) {
|
if (resultType) {
|
||||||
|
|
|
@ -76,6 +76,26 @@ describe('diagnostics', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not produce diagnostics for slice pipe with arguments', () => {
|
||||||
|
mockHost.override(TEST_TEMPLATE, `
|
||||||
|
<div *ngFor="let h of heroes | slice:0:1">
|
||||||
|
{{h.name}}
|
||||||
|
</div>`);
|
||||||
|
const diags = ngLS.getDiagnostics(TEST_TEMPLATE);
|
||||||
|
expect(diags).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should produce diagnostics for slice pipe with args when member is invalid', () => {
|
||||||
|
mockHost.override(TEST_TEMPLATE, `
|
||||||
|
<div *ngFor="let h of heroes | slice:0:1">
|
||||||
|
{{h.age}}
|
||||||
|
</div>`);
|
||||||
|
const diags = ngLS.getDiagnostics(TEST_TEMPLATE);
|
||||||
|
expect(diags.length).toBe(1);
|
||||||
|
expect(diags[0].messageText)
|
||||||
|
.toBe(`Identifier 'age' is not defined. 'Hero' does not contain such a member`);
|
||||||
|
});
|
||||||
|
|
||||||
describe('in expression-cases.ts', () => {
|
describe('in expression-cases.ts', () => {
|
||||||
it('should report access to an unknown field', () => {
|
it('should report access to an unknown field', () => {
|
||||||
const diags = ngLS.getDiagnostics(EXPRESSION_CASES).map(d => d.messageText);
|
const diags = ngLS.getDiagnostics(EXPRESSION_CASES).map(d => d.messageText);
|
||||||
|
|
|
@ -188,6 +188,7 @@ export class TestComponent {
|
||||||
export class TemplateReference {
|
export class TemplateReference {
|
||||||
title = 'Some title';
|
title = 'Some title';
|
||||||
hero: Hero = {id: 1, name: 'Windstorm'};
|
hero: Hero = {id: 1, name: 'Windstorm'};
|
||||||
|
heroes: Hero[] = [this.hero];
|
||||||
anyValue: any;
|
anyValue: any;
|
||||||
myClick(event: any) {}
|
myClick(event: any) {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue