Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(language-service): Improve signature selection for pipes with args #33456

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -335,4 +335,4 @@ function offsetSpan(span: Span, amount: number): Span {

function spanOf(sourceSpan: ParseSourceSpan): Span {
return {start: sourceSpan.start.offset, end: sourceSpan.end.offset};
}
}
4 changes: 2 additions & 2 deletions packages/compiler-cli/src/diagnostics/typescript_symbols.ts
Expand Up @@ -557,7 +557,7 @@ class PipeSymbol implements Symbol {

selectSignature(types: Symbol[]): Signature|undefined {
let signature = selectSignature(this.tsType, this.context, types) !;
if (types.length == 1) {
if (types.length > 0) {
const parameterType = types[0];
if (parameterType instanceof TypeWrapper) {
let resultType: ts.Type|undefined = undefined;
Expand All @@ -575,7 +575,7 @@ class PipeSymbol implements Symbol {
}
break;
case 'slice':
resultType = getTypeParameterOf(parameterType.tsType, 'Array');
resultType = parameterType.tsType;
break;
}
if (resultType) {
Expand Down
20 changes: 20 additions & 0 deletions packages/language-service/test/diagnostics_spec.ts
Expand Up @@ -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', () => {
it('should report access to an unknown field', () => {
const diags = ngLS.getDiagnostics(EXPRESSION_CASES).map(d => d.messageText);
Expand Down
Expand Up @@ -188,6 +188,7 @@ export class TestComponent {
export class TemplateReference {
title = 'Some title';
hero: Hero = {id: 1, name: 'Windstorm'};
heroes: Hero[] = [this.hero];
anyValue: any;
myClick(event: any) {}
}
Expand Down