From 64aae3a9dfbd9a39c4c0fe837b53c6068747fcaa Mon Sep 17 00:00:00 2001 From: Keen Yee Liau Date: Mon, 14 Oct 2019 15:24:59 -0700 Subject: [PATCH] test(language-service): test project cleanup (#33157) This PR adds es2015 lib to the `tsconfig.json` of the test project so that `Promise` could be used. Note this only affects diagnostics in the IDE. The tsconfig in Language Service Mock Host is the actual config values used, and it already has es2015 lib. - Other minor cleanup: Rename imports in `main.ts`. - Add more cases to `parsing-cases.ts`, which are tested in later PRs PR Close #33157 --- .../language-service/test/project/app/main.ts | 66 ++++++++++--------- .../test/project/app/parsing-cases.ts | 24 +++++++ .../test/project/tsconfig.json | 1 + .../test/typescript_host_spec.ts | 2 +- 4 files changed, 60 insertions(+), 33 deletions(-) diff --git a/packages/language-service/test/project/app/main.ts b/packages/language-service/test/project/app/main.ts index 1564789f7f..344c23c819 100644 --- a/packages/language-service/test/project/app/main.ts +++ b/packages/language-service/test/project/app/main.ts @@ -11,43 +11,45 @@ import {NgModule} from '@angular/core'; import {FormsModule} from '@angular/forms'; import {AppComponent} from './app.component'; -import {ExpectNumericType, LowercasePipe, PrivateReference, WrongFieldReference, WrongSubFieldReference} from './expression-cases'; -import {UnknownEven, UnknownPeople, UnknownTrackBy} from './ng-for-cases'; -import {ShowIf} from './ng-if-cases'; -import {AttributeBinding, CaseIncompleteOpen, CaseMissingClosing, CaseUnknown, EmptyInterpolation, EventBinding, ForLetIEqual, ForOfEmpty, ForOfLetEmpty, ForUsingComponent, NoValueAttribute, NumberModel, Pipes, PropertyBinding, References, StringModel, TemplateReference, TestComponent, TwoWayBinding} from './parsing-cases'; +import * as ExpressionCases from './expression-cases'; +import * as NgForCases from './ng-for-cases'; +import * as NgIfCases from './ng-if-cases'; +import * as ParsingCases from './parsing-cases'; @NgModule({ imports: [CommonModule, FormsModule], declarations: [ AppComponent, - CaseIncompleteOpen, - CaseMissingClosing, - CaseUnknown, - Pipes, - TemplateReference, - NoValueAttribute, - AttributeBinding, - StringModel, - NumberModel, - PropertyBinding, - EventBinding, - TwoWayBinding, - EmptyInterpolation, - ForOfEmpty, - ForOfLetEmpty, - ForLetIEqual, - ForUsingComponent, - References, - TestComponent, - WrongFieldReference, - WrongSubFieldReference, - PrivateReference, - ExpectNumericType, - UnknownPeople, - UnknownEven, - UnknownTrackBy, - ShowIf, - LowercasePipe, + ExpressionCases.ExpectNumericType, + ExpressionCases.LowercasePipe, + ExpressionCases.PrivateReference, + ExpressionCases.WrongFieldReference, + ExpressionCases.WrongSubFieldReference, + NgForCases.UnknownEven, + NgForCases.UnknownPeople, + NgForCases.UnknownTrackBy, + NgIfCases.ShowIf, + ParsingCases.AsyncForUsingComponent, + ParsingCases.AttributeBinding, + ParsingCases.CaseIncompleteOpen, + ParsingCases.CaseMissingClosing, + ParsingCases.CaseUnknown, + ParsingCases.EmptyInterpolation, + ParsingCases.EventBinding, + ParsingCases.FooComponent, + ParsingCases.ForLetIEqual, + ParsingCases.ForOfEmpty, + ParsingCases.ForOfLetEmpty, + ParsingCases.ForUsingComponent, + ParsingCases.NoValueAttribute, + ParsingCases.NumberModel, + ParsingCases.Pipes, + ParsingCases.PropertyBinding, + ParsingCases.References, + ParsingCases.StringModel, + ParsingCases.TemplateReference, + ParsingCases.TestComponent, + ParsingCases.TwoWayBinding, ] }) export class AppModule { diff --git a/packages/language-service/test/project/app/parsing-cases.ts b/packages/language-service/test/project/app/parsing-cases.ts index cd9fa37a4d..d967243b9b 100644 --- a/packages/language-service/test/project/app/parsing-cases.ts +++ b/packages/language-service/test/project/app/parsing-cases.ts @@ -91,9 +91,22 @@ export class NumberModel { @Output('outputAlias') modelChanged: EventEmitter = new EventEmitter(); } +@Component({ + selector: 'foo-component', + template: ` +
+
+ `, +}) +export class FooComponent { + text: string = 'some text'; + value: number = 42; +} + interface Person { name: string; age: number; + street: string; } @Component({ @@ -125,6 +138,17 @@ export class ForUsingComponent { people: Person[] = []; } +@Component({ + template: ` +
+ {{person.~{async-person-name}name}} +
+ `, +}) +export class AsyncForUsingComponent { + people: Promise = Promise.resolve([]); +} + @Component({ template: `
diff --git a/packages/language-service/test/project/tsconfig.json b/packages/language-service/test/project/tsconfig.json index 0e793bb214..dca7200ff1 100644 --- a/packages/language-service/test/project/tsconfig.json +++ b/packages/language-service/test/project/tsconfig.json @@ -1,6 +1,7 @@ { "//00": "This file is used for IDE only, actual compilation options is in MockTypescriptHost in test_utils.ts", "compilerOptions": { + "lib": ["es2015"], "strict": true, "experimentalDecorators": true, "baseUrl": "../../../..", diff --git a/packages/language-service/test/typescript_host_spec.ts b/packages/language-service/test/typescript_host_spec.ts index df9fabbe9a..8105ddf2c5 100644 --- a/packages/language-service/test/typescript_host_spec.ts +++ b/packages/language-service/test/typescript_host_spec.ts @@ -95,7 +95,7 @@ describe('TypeScriptServiceHost', () => { const tsLS = ts.createLanguageService(tsLSHost); const ngLSHost = new TypeScriptServiceHost(tsLSHost, tsLS); const templates = ngLSHost.getTemplates('/app/parsing-cases.ts'); - expect(templates.length).toBe(16); + expect(templates.length).toBe(18); }); it('should be able to find external template', () => {