feat(language-service): completions support for tuple array (#33928)

PR Close #33928
This commit is contained in:
ivanwonder
2019-11-20 07:23:45 +00:00
committed by Miško Hevery
parent de7713d6ea
commit 5a227d8d7c
6 changed files with 33 additions and 5 deletions

View File

@ -125,6 +125,13 @@ describe('completions', () => {
expectContain(completions, CompletionKind.PROPERTY, ['id', 'name']);
});
it('should work with numeric index signatures (tuple arrays)', () => {
mockHost.override(TEST_TEMPLATE, `{{ tupleArray[1].~{tuple-array-number-index}}}`);
const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'tuple-array-number-index');
const completions = ngLS.getCompletionsAt(TEST_TEMPLATE, marker.start);
expectContain(completions, CompletionKind.PROPERTY, ['id', 'name']);
});
describe('with string index signatures', () => {
it('should work with index notation', () => {
mockHost.override(TEST_TEMPLATE, `{{ heroesByName['Jacky'].~{heroes-string-index}}}`);

View File

@ -150,6 +150,15 @@ describe('diagnostics', () => {
});
});
it('should produce diagnostics for invalid tuple type property access', () => {
mockHost.override(TEST_TEMPLATE, `
{{tupleArray[1].badProperty}}`);
const diags = ngLS.getDiagnostics(TEST_TEMPLATE);
expect(diags.length).toBe(1);
expect(diags[0].messageText)
.toBe(`Identifier 'badProperty' is not defined. 'Hero' does not contain such a member`);
});
it('should not produce errors on function.bind()', () => {
mockHost.override(TEST_TEMPLATE, `
<test-comp (test)="myClick.bind(this)">

View File

@ -189,6 +189,7 @@ export class TemplateReference {
title = 'Some title';
hero: Hero = {id: 1, name: 'Windstorm'};
heroes: Hero[] = [this.hero];
tupleArray: [string, Hero] = ['test', this.hero];
league: Hero[][] = [this.heroes];
heroesByName: {[name: string]: Hero} = {};
anyValue: any;