From 83d207d0a795bc1945c4661cb5ab73d2e671c1ce Mon Sep 17 00:00:00 2001 From: Chuck Jazdzewski Date: Fri, 22 Dec 2017 09:36:47 -0800 Subject: [PATCH] build: upgrade to TypeScript 2.6 (#21144) Fixes #20653 PR Close #21144 --- WORKSPACE | 3 +- integration/_payload-limits.json | 2 +- integration/bazel/WORKSPACE | 7 +-- .../hello_world__systemjs_umd/package.json | 4 +- integration/typings_test_ts24/include-all.ts | 10 +++- integration/typings_test_ts24/package.json | 3 ++ integration/typings_test_ts25/include-all.ts | 10 +++- integration/typings_test_ts25/package.json | 3 ++ integration/typings_test_ts26/include-all.ts | 47 ++++++++++++++++++ integration/typings_test_ts26/package.json | 30 ++++++++++++ integration/typings_test_ts26/tsconfig.json | 24 ++++++++++ package.json | 4 +- packages/bazel/package.json | 2 +- packages/common/src/i18n/locale_en.ts | 15 +++--- packages/compiler-cli/package.json | 4 +- .../src/diagnostics/translate_diagnostics.ts | 3 +- packages/compiler-cli/src/main.ts | 10 ++-- .../src/metadata/bundle_index_host.ts | 7 +-- packages/compiler-cli/src/metadata/bundler.ts | 4 +- packages/compiler-cli/src/metadata/schema.ts | 45 +++++++++-------- packages/compiler-cli/src/ngtools_api2.ts | 18 +++---- packages/compiler-cli/src/perform_compile.ts | 10 ++-- packages/compiler-cli/src/perform_watch.ts | 4 +- packages/compiler-cli/src/transformers/api.ts | 12 ++--- .../src/transformers/compiler_host.ts | 10 ++-- .../compiler-cli/src/transformers/program.ts | 48 +++++++++++-------- .../test/diagnostics/check_types_spec.ts | 8 ++-- .../test/metadata/collector_spec.ts | 47 ++++++------------ .../test/metadata/symbols_spec.ts | 3 +- .../test/metadata/typescript.mocks.ts | 3 ++ packages/compiler-cli/test/ngc_spec.ts | 2 +- .../compiler-cli/test/perform_watch_spec.ts | 4 +- .../test/transformers/program_spec.ts | 9 ++-- packages/compiler/test/aot/test_util.ts | 6 +-- packages/language-service/src/ts_plugin.ts | 23 +++++---- .../language-service/test/ts_plugin_spec.ts | 6 ++- .../service-worker/worker/src/app-version.ts | 4 +- packages/service-worker/worker/src/assets.ts | 3 +- .../service-worker/worker/src/db-cache.ts | 4 +- .../worker/src/service-worker.d.ts | 29 +---------- .../service-worker/worker/testing/cache.ts | 9 ++-- .../service-worker/worker/testing/fetch.ts | 31 +++++++----- .../service-worker/worker/testing/mock.ts | 2 +- scripts/ci/env.sh | 2 +- yarn.lock | 12 ++--- 45 files changed, 331 insertions(+), 215 deletions(-) create mode 100644 integration/typings_test_ts26/include-all.ts create mode 100644 integration/typings_test_ts26/package.json create mode 100644 integration/typings_test_ts26/tsconfig.json diff --git a/WORKSPACE b/WORKSPACE index e94abab6f1..c40e30c0ea 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -16,7 +16,8 @@ node_repositories(package_json = ["//:package.json"]) git_repository( name = "build_bazel_rules_typescript", remote = "https://github.com/bazelbuild/rules_typescript.git", - tag = "0.7.1", +# tag = "0.7.1+", + commit = "89d2c75066bea3d9c942f29dd1d2ea543c58d6d5" ) load("@build_bazel_rules_typescript//:setup.bzl", "ts_setup_workspace") diff --git a/integration/_payload-limits.json b/integration/_payload-limits.json index c2d1626bda..d40ec97f1d 100644 --- a/integration/_payload-limits.json +++ b/integration/_payload-limits.json @@ -1,4 +1,4 @@ { -"cli-hello-world":{"master":{"gzip7":{"inline":847,"main":42533,"polyfills":20207},"gzip9":{"inline":847,"main":42483,"polyfills":20204},"uncompressed":{"inline":1447,"main":154295,"polyfills":61254}}}, +"cli-hello-world":{"master":{"gzip7":{"inline":847,"main":42533,"polyfills":20207},"gzip9":{"inline":847,"main":42483,"polyfills":20204},"uncompressed":{"inline":1447,"main":151954,"polyfills":61254}}}, "hello_world__closure":{"master":{"gzip7":{"bundle":32793},"gzip9":{"bundle":32758},"uncompressed":{"bundle":100661}}} } diff --git a/integration/bazel/WORKSPACE b/integration/bazel/WORKSPACE index 4c5693f5e2..57fca31224 100644 --- a/integration/bazel/WORKSPACE +++ b/integration/bazel/WORKSPACE @@ -14,12 +14,13 @@ node_repositories(package_json = ["//:package.json"]) git_repository( name = "build_bazel_rules_typescript", remote = "https://github.com/bazelbuild/rules_typescript.git", - tag = "0.6.0", +# tag = "0.6.0", + commit = "89d2c75066bea3d9c942f29dd1d2ea543c58d6d5" ) -load("@build_bazel_rules_typescript//:defs.bzl", "ts_repositories") +load("@build_bazel_rules_typescript//:setup.bzl", "ts_setup_workspace") -ts_repositories() +ts_setup_workspace() local_repository( name = "angular", diff --git a/integration/hello_world__systemjs_umd/package.json b/integration/hello_world__systemjs_umd/package.json index cf411ebe0a..d8d1e7da26 100644 --- a/integration/hello_world__systemjs_umd/package.json +++ b/integration/hello_world__systemjs_umd/package.json @@ -5,7 +5,7 @@ "license": "MIT", "scripts": { "postinstall": "webdriver-manager update --gecko false --standalone false $CHROMEDRIVER_VERSION_ARG", - "test": "concurrently \"npm run serve\" \"npm run protractor\" --kill-others --success first", + "test": "concurrently \"yarn serve\" \"yarn protractor\" --kill-others --success first", "serve": "lite-server -c bs-config.e2e.json", "preprotractor": "tsc -p e2e", "protractor": "protractor protractor.config.js" @@ -17,7 +17,7 @@ "@angular/platform-browser": "file:../../dist/packages-dist/platform-browser", "@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic", "core-js": "2.4.1", - "plugin-typescript": "6.0.4", + "plugin-typescript": "8.0.0", "rxjs": "file:../../node_modules/rxjs", "systemjs": "0.20.2", "typescript": "file:../../node_modules/typescript", diff --git a/integration/typings_test_ts24/include-all.ts b/integration/typings_test_ts24/include-all.ts index eaa53d24c2..78cefe0030 100644 --- a/integration/typings_test_ts24/include-all.ts +++ b/integration/typings_test_ts24/include-all.ts @@ -13,13 +13,16 @@ import * as coreTesting from '@angular/core/testing'; import * as forms from '@angular/forms'; import * as http from '@angular/http'; import * as httpTesting from '@angular/http/testing'; -import * as platformBrowserDynamic from '@angular/platform-browser-dynamic'; import * as platformBrowser from '@angular/platform-browser'; import * as platformBrowserTesting from '@angular/platform-browser/testing'; +import * as platformBrowserDynamic from '@angular/platform-browser-dynamic'; import * as platformServer from '@angular/platform-server'; import * as platformServerTesting from '@angular/platform-server/testing'; +import * as platformWebworker from '@angular/platform-webworker'; +import * as platformWebworkerDynamic from '@angular/platform-webworker-dynamic'; import * as router from '@angular/router'; import * as routerTesting from '@angular/router/testing'; +import * as serviceWorker from '@angular/service-worker'; import * as upgrade from '@angular/upgrade'; export default { @@ -35,7 +38,10 @@ export default { platformBrowserDynamic, platformServer, platformServerTesting, + platformWebworker, + platformWebworkerDynamic, router, routerTesting, - upgrade + serviceWorker, + upgrade, }; diff --git a/integration/typings_test_ts24/package.json b/integration/typings_test_ts24/package.json index e4e147c6bb..b1e66e33f6 100644 --- a/integration/typings_test_ts24/package.json +++ b/integration/typings_test_ts24/package.json @@ -14,7 +14,10 @@ "@angular/platform-browser": "file:../../dist/packages-dist/platform-browser", "@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic", "@angular/platform-server": "file:../../dist/packages-dist/platform-server", + "@angular/platform-webworker": "file:../../dist/packages-dist/platform-webworker", + "@angular/platform-webworker-dynamic": "file:../../dist/packages-dist/platform-webworker-dynamic", "@angular/router": "file:../../dist/packages-dist/router", + "@angular/service-worker": "file:../../dist/packages-dist/service-worker", "@angular/upgrade": "file:../../dist/packages-dist/upgrade", "@types/jasmine": "2.5.41", "rxjs": "file:../../node_modules/rxjs", diff --git a/integration/typings_test_ts25/include-all.ts b/integration/typings_test_ts25/include-all.ts index eaa53d24c2..78cefe0030 100644 --- a/integration/typings_test_ts25/include-all.ts +++ b/integration/typings_test_ts25/include-all.ts @@ -13,13 +13,16 @@ import * as coreTesting from '@angular/core/testing'; import * as forms from '@angular/forms'; import * as http from '@angular/http'; import * as httpTesting from '@angular/http/testing'; -import * as platformBrowserDynamic from '@angular/platform-browser-dynamic'; import * as platformBrowser from '@angular/platform-browser'; import * as platformBrowserTesting from '@angular/platform-browser/testing'; +import * as platformBrowserDynamic from '@angular/platform-browser-dynamic'; import * as platformServer from '@angular/platform-server'; import * as platformServerTesting from '@angular/platform-server/testing'; +import * as platformWebworker from '@angular/platform-webworker'; +import * as platformWebworkerDynamic from '@angular/platform-webworker-dynamic'; import * as router from '@angular/router'; import * as routerTesting from '@angular/router/testing'; +import * as serviceWorker from '@angular/service-worker'; import * as upgrade from '@angular/upgrade'; export default { @@ -35,7 +38,10 @@ export default { platformBrowserDynamic, platformServer, platformServerTesting, + platformWebworker, + platformWebworkerDynamic, router, routerTesting, - upgrade + serviceWorker, + upgrade, }; diff --git a/integration/typings_test_ts25/package.json b/integration/typings_test_ts25/package.json index 9283f40ee5..237747e132 100644 --- a/integration/typings_test_ts25/package.json +++ b/integration/typings_test_ts25/package.json @@ -14,7 +14,10 @@ "@angular/platform-browser": "file:../../dist/packages-dist/platform-browser", "@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic", "@angular/platform-server": "file:../../dist/packages-dist/platform-server", + "@angular/platform-webworker": "file:../../dist/packages-dist/platform-webworker", + "@angular/platform-webworker-dynamic": "file:../../dist/packages-dist/platform-webworker-dynamic", "@angular/router": "file:../../dist/packages-dist/router", + "@angular/service-worker": "file:../../dist/packages-dist/service-worker", "@angular/upgrade": "file:../../dist/packages-dist/upgrade", "@types/jasmine": "2.5.41", "rxjs": "file:../../node_modules/rxjs", diff --git a/integration/typings_test_ts26/include-all.ts b/integration/typings_test_ts26/include-all.ts new file mode 100644 index 0000000000..78cefe0030 --- /dev/null +++ b/integration/typings_test_ts26/include-all.ts @@ -0,0 +1,47 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import * as compiler from '@angular/compiler'; +import * as compilerTesting from '@angular/compiler/testing'; +import * as core from '@angular/core'; +import * as coreTesting from '@angular/core/testing'; +import * as forms from '@angular/forms'; +import * as http from '@angular/http'; +import * as httpTesting from '@angular/http/testing'; +import * as platformBrowser from '@angular/platform-browser'; +import * as platformBrowserTesting from '@angular/platform-browser/testing'; +import * as platformBrowserDynamic from '@angular/platform-browser-dynamic'; +import * as platformServer from '@angular/platform-server'; +import * as platformServerTesting from '@angular/platform-server/testing'; +import * as platformWebworker from '@angular/platform-webworker'; +import * as platformWebworkerDynamic from '@angular/platform-webworker-dynamic'; +import * as router from '@angular/router'; +import * as routerTesting from '@angular/router/testing'; +import * as serviceWorker from '@angular/service-worker'; +import * as upgrade from '@angular/upgrade'; + +export default { + compiler, + compilerTesting, + core, + coreTesting, + forms, + http, + httpTesting, + platformBrowser, + platformBrowserTesting, + platformBrowserDynamic, + platformServer, + platformServerTesting, + platformWebworker, + platformWebworkerDynamic, + router, + routerTesting, + serviceWorker, + upgrade, +}; diff --git a/integration/typings_test_ts26/package.json b/integration/typings_test_ts26/package.json new file mode 100644 index 0000000000..5b952ea8fa --- /dev/null +++ b/integration/typings_test_ts26/package.json @@ -0,0 +1,30 @@ +{ + "name": "angular-integration", + "description": "Assert that users with TypeScript 2.6 can type-check an Angular application", + "version": "0.0.0", + "license": "MIT", + "dependencies": { + "@angular/animations": "file:../../dist/packages-dist/animations", + "@angular/common": "file:../../dist/packages-dist/common", + "@angular/compiler": "file:../../dist/packages-dist/compiler", + "@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli", + "@angular/core": "file:../../dist/packages-dist/core", + "@angular/forms": "file:../../dist/packages-dist/forms", + "@angular/http": "file:../../dist/packages-dist/http", + "@angular/platform-browser": "file:../../dist/packages-dist/platform-browser", + "@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic", + "@angular/platform-server": "file:../../dist/packages-dist/platform-server", + "@angular/platform-webworker": "file:../../dist/packages-dist/platform-webworker", + "@angular/platform-webworker-dynamic": "file:../../dist/packages-dist/platform-webworker-dynamic", + "@angular/router": "file:../../dist/packages-dist/router", + "@angular/service-worker": "file:../../dist/packages-dist/service-worker", + "@angular/upgrade": "file:../../dist/packages-dist/upgrade", + "@types/jasmine": "2.5.41", + "rxjs": "file:../../node_modules/rxjs", + "typescript": "2.6.x", + "zone.js": "file:../../node_modules/zone.js" + }, + "scripts": { + "test": "tsc" + } +} diff --git a/integration/typings_test_ts26/tsconfig.json b/integration/typings_test_ts26/tsconfig.json new file mode 100644 index 0000000000..cb5491eaac --- /dev/null +++ b/integration/typings_test_ts26/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "module": "commonjs", + "moduleResolution": "node", + "outDir": "../../dist/typings_test_ts26/", + "rootDir": ".", + "target": "es5", + "lib": [ + "es5", + "dom", + "es2015.collection", + "es2015.iterable", + "es2015.promise" + ], + "types": [], + "strictNullChecks": true + }, + "files": [ + "include-all.ts", + "node_modules/@types/jasmine/index.d.ts" + ] +} diff --git a/package.json b/package.json index 0be845c281..f96a55811b 100644 --- a/package.json +++ b/package.json @@ -96,11 +96,11 @@ "source-map-support": "0.4.18", "systemjs": "0.18.10", "ts-api-guardian": "0.2.2", - "tsickle": "0.25.5", + "tsickle": "0.26.0", "tslint": "5.7.0", "tslint-eslint-rules": "4.1.1", "tsutils": "2.12.1", - "typescript": "2.5.x", + "typescript": "2.6.x", "uglify-js": "2.8.29", "universal-analytics": "0.4.15", "vlq": "0.2.2", diff --git a/packages/bazel/package.json b/packages/bazel/package.json index 0f91fb5c4f..0e959b039d 100644 --- a/packages/bazel/package.json +++ b/packages/bazel/package.json @@ -6,7 +6,7 @@ "license": "MIT", "peerDependencies": { "@angular/compiler-cli": "0.0.0-PLACEHOLDER", - "typescript": ">=2.4.2 <2.6" + "typescript": ">=2.4.2 <2.7" }, "dependencies": { "@types/node": "6.0.84" diff --git a/packages/common/src/i18n/locale_en.ts b/packages/common/src/i18n/locale_en.ts index ba79d690f9..173fd30213 100644 --- a/packages/common/src/i18n/locale_en.ts +++ b/packages/common/src/i18n/locale_en.ts @@ -9,6 +9,13 @@ // THIS CODE IS GENERATED - DO NOT MODIFY // See angular/tools/gulp-tasks/cldr/extract.js +function converter(n: number): number { + let i = Math.floor(Math.abs(n)), v = n.toString().replace(/^[^.]*\.?/, '').length; + if (i === 1 && v === 0) return 1; + return 5; +} + + export default [ 'en', [ @@ -42,11 +49,5 @@ export default [ '{1} \'at\' {0}', ], ['.', ',', ';', '%', '+', '-', 'E', '×', '‰', '∞', 'NaN', ':'], - ['#,##0.###', '#,##0%', '¤#,##0.00', '#E0'], '$', 'US Dollar', - function(n: number): - number { - let i = Math.floor(Math.abs(n)), v = n.toString().replace(/^[^.]*\.?/, '').length; - if (i === 1 && v === 0) return 1; - return 5; - } + ['#,##0.###', '#,##0%', '¤#,##0.00', '#E0'], '$', 'US Dollar', converter ]; diff --git a/packages/compiler-cli/package.json b/packages/compiler-cli/package.json index c7fb9a026b..3c739261f2 100644 --- a/packages/compiler-cli/package.json +++ b/packages/compiler-cli/package.json @@ -11,11 +11,11 @@ "dependencies": { "reflect-metadata": "^0.1.2", "minimist": "^1.2.0", - "tsickle": "^0.25.5", + "tsickle": "^0.26.0", "chokidar": "^1.4.2" }, "peerDependencies": { - "typescript": ">=2.4.2 <2.6", + "typescript": ">=2.4.2 <2.7", "@angular/compiler": "0.0.0-PLACEHOLDER" }, "repository": { diff --git a/packages/compiler-cli/src/diagnostics/translate_diagnostics.ts b/packages/compiler-cli/src/diagnostics/translate_diagnostics.ts index aff0162d8b..46d98c2177 100644 --- a/packages/compiler-cli/src/diagnostics/translate_diagnostics.ts +++ b/packages/compiler-cli/src/diagnostics/translate_diagnostics.ts @@ -16,7 +16,8 @@ export interface TypeCheckHost { parseSourceSpanOf(fileName: string, line: number, character: number): ParseSourceSpan|null; } -export function translateDiagnostics(host: TypeCheckHost, untranslatedDiagnostics: ts.Diagnostic[]): +export function translateDiagnostics( + host: TypeCheckHost, untranslatedDiagnostics: ReadonlyArray): {ts: ts.Diagnostic[], ng: Diagnostic[]} { const ts: ts.Diagnostic[] = []; const ng: Diagnostic[] = []; diff --git a/packages/compiler-cli/src/main.ts b/packages/compiler-cli/src/main.ts index 476f78dd10..9fc109d752 100644 --- a/packages/compiler-cli/src/main.ts +++ b/packages/compiler-cli/src/main.ts @@ -38,6 +38,7 @@ export function main( return reportErrorsAndExit(compileDiags, options, consoleError); } + function createEmitCallback(options: api.CompilerOptions): api.TsEmitCallback|undefined { const transformDecorators = options.annotationsAs !== 'decorators'; const transformTypesToClosure = options.annotateForClosureCompiler; @@ -50,7 +51,10 @@ function createEmitCallback(options: api.CompilerOptions): api.TsEmitCallback|un // as TypeScript elided the import. options.emitDecoratorMetadata = true; } - const tsickleHost: tsickle.TsickleHost = { + const tsickleHost: Pick< + tsickle.TsickleHost, 'shouldSkipTsickleProcessing'|'pathToModuleName'| + 'shouldIgnoreWarningsForPath'|'fileNameToModuleId'|'googmodule'|'untyped'| + 'convertIndexImportShorthand'|'transformDecorators'|'transformTypesToClosure'> = { shouldSkipTsickleProcessing: (fileName) => /\.d\.ts$/.test(fileName) || GENERATED_FILES.test(fileName), pathToModuleName: (context, importPath) => '', @@ -72,8 +76,8 @@ function createEmitCallback(options: api.CompilerOptions): api.TsEmitCallback|un options }) => tsickle.emitWithTsickle( - program, tsickleHost, host, options, targetSourceFile, writeFile, - cancellationToken, emitOnlyDtsFiles, { + program, {...tsickleHost, options, host}, host, options, targetSourceFile, + writeFile, cancellationToken, emitOnlyDtsFiles, { beforeTs: customTransformers.before, afterTs: customTransformers.after, }); diff --git a/packages/compiler-cli/src/metadata/bundle_index_host.ts b/packages/compiler-cli/src/metadata/bundle_index_host.ts index fb7af2ea1f..e89aa72b8b 100644 --- a/packages/compiler-cli/src/metadata/bundle_index_host.ts +++ b/packages/compiler-cli/src/metadata/bundle_index_host.ts @@ -44,7 +44,8 @@ function createSyntheticIndexHost( newHost.writeFile = (fileName: string, data: string, writeByteOrderMark: boolean, - onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]) => { + onError: ((message: string) => void) | undefined, + sourceFiles: Readonly[]) => { delegate.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles); if (fileName.match(DTS) && sourceFiles && sourceFiles.length == 1 && path.normalize(sourceFiles[0].fileName) == normalSyntheticIndexName) { @@ -57,7 +58,7 @@ function createSyntheticIndexHost( } export function createBundleIndexHost( - ngOptions: CompilerOptions, rootFiles: string[], + ngOptions: CompilerOptions, rootFiles: ReadonlyArray, host: H): {host: H, indexName?: string, errors?: ts.Diagnostic[]} { const files = rootFiles.filter(f => !DTS.test(f)); if (files.length != 1) { @@ -86,4 +87,4 @@ export function createBundleIndexHost( const content = privateEntriesToIndex(libraryIndex, metadataBundle.privates); host = createSyntheticIndexHost(host, {name, content, metadata}); return {host, indexName: name}; -} \ No newline at end of file +} diff --git a/packages/compiler-cli/src/metadata/bundler.ts b/packages/compiler-cli/src/metadata/bundler.ts index 373fa18435..b0444a96db 100644 --- a/packages/compiler-cli/src/metadata/bundler.ts +++ b/packages/compiler-cli/src/metadata/bundler.ts @@ -563,7 +563,7 @@ export class MetadataBundler { private convertExpressionNode(moduleName: string, value: MetadataSymbolicExpression): MetadataSymbolicExpression { - const result: MetadataSymbolicExpression = {__symbolic: value.__symbolic}; + const result: MetadataSymbolicExpression = { __symbolic: value.__symbolic } as any; for (const key in value) { (result as any)[key] = this.convertValue(moduleName, (value as any)[key]); } @@ -598,7 +598,7 @@ export class CompilerHostAdapter implements MetadataBundlerHost { getMetadataFor(fileName: string): ModuleMetadata|undefined { const sourceFile = this.host.getSourceFile(fileName + '.ts', ts.ScriptTarget.Latest); - return this.collector.getMetadata(sourceFile); + return sourceFile && this.collector.getMetadata(sourceFile); } } diff --git a/packages/compiler-cli/src/metadata/schema.ts b/packages/compiler-cli/src/metadata/schema.ts index a5ca3fce74..5a5d7d281b 100644 --- a/packages/compiler-cli/src/metadata/schema.ts +++ b/packages/compiler-cli/src/metadata/schema.ts @@ -99,15 +99,24 @@ export function isFunctionMetadata(value: any): value is FunctionMetadata { } export type MetadataValue = string | number | boolean | undefined | null | MetadataObject | - MetadataArray | MetadataSymbolicExpression | MetadataError; + MetadataArray | MetadataSymbolicExpression | MetadataSymbolicReferenceExpression | + MetadataSymbolicBinaryExpression | MetadataSymbolicIndexExpression | + MetadataSymbolicCallExpression | MetadataSymbolicPrefixExpression | + MetadataSymbolicIfExpression | MetadataSymbolicSpreadExpression | + MetadataSymbolicSelectExpression | MetadataError; export interface MetadataObject { [name: string]: MetadataValue; } export interface MetadataArray { [name: number]: MetadataValue; } -export interface MetadataSymbolicExpression { - __symbolic: 'binary'|'call'|'index'|'new'|'pre'|'reference'|'select'|'spread'|'if'; -} +export type MetadataSymbolicExpression = MetadataSymbolicBinaryExpression | + MetadataSymbolicIndexExpression | MetadataSymbolicIndexExpression | + MetadataSymbolicCallExpression | MetadataSymbolicCallExpression | + MetadataSymbolicPrefixExpression | MetadataSymbolicIfExpression | + MetadataGlobalReferenceExpression | MetadataModuleReferenceExpression | + MetadataImportedSymbolReferenceExpression | MetadataImportedDefaultReferenceExpression | + MetadataSymbolicSelectExpression | MetadataSymbolicSpreadExpression; + export function isMetadataSymbolicExpression(value: any): value is MetadataSymbolicExpression { if (value) { switch (value.__symbolic) { @@ -126,7 +135,7 @@ export function isMetadataSymbolicExpression(value: any): value is MetadataSymbo return false; } -export interface MetadataSymbolicBinaryExpression extends MetadataSymbolicExpression { +export interface MetadataSymbolicBinaryExpression { __symbolic: 'binary'; operator: '&&'|'||'|'|'|'^'|'&'|'=='|'!='|'==='|'!=='|'<'|'>'|'<='|'>='|'instanceof'|'in'|'as'| '<<'|'>>'|'>>>'|'+'|'-'|'*'|'/'|'%'|'**'; @@ -138,7 +147,7 @@ export function isMetadataSymbolicBinaryExpression(value: any): return value && value.__symbolic === 'binary'; } -export interface MetadataSymbolicIndexExpression extends MetadataSymbolicExpression { +export interface MetadataSymbolicIndexExpression { __symbolic: 'index'; expression: MetadataValue; index: MetadataValue; @@ -148,7 +157,7 @@ export function isMetadataSymbolicIndexExpression(value: any): return value && value.__symbolic === 'index'; } -export interface MetadataSymbolicCallExpression extends MetadataSymbolicExpression { +export interface MetadataSymbolicCallExpression { __symbolic: 'call'|'new'; expression: MetadataValue; arguments?: MetadataValue[]; @@ -158,7 +167,7 @@ export function isMetadataSymbolicCallExpression(value: any): return value && (value.__symbolic === 'call' || value.__symbolic === 'new'); } -export interface MetadataSymbolicPrefixExpression extends MetadataSymbolicExpression { +export interface MetadataSymbolicPrefixExpression { __symbolic: 'pre'; operator: '+'|'-'|'~'|'!'; operand: MetadataValue; @@ -168,7 +177,7 @@ export function isMetadataSymbolicPrefixExpression(value: any): return value && value.__symbolic === 'pre'; } -export interface MetadataSymbolicIfExpression extends MetadataSymbolicExpression { +export interface MetadataSymbolicIfExpression { __symbolic: 'if'; condition: MetadataValue; thenExpression: MetadataValue; @@ -190,8 +199,7 @@ export interface MetadataSourceLocationInfo { character?: number; } -export interface MetadataGlobalReferenceExpression extends MetadataSymbolicExpression, - MetadataSourceLocationInfo { +export interface MetadataGlobalReferenceExpression extends MetadataSourceLocationInfo { __symbolic: 'reference'; name: string; arguments?: MetadataValue[]; @@ -201,8 +209,7 @@ export function isMetadataGlobalReferenceExpression(value: any): return value && value.name && !value.module && isMetadataSymbolicReferenceExpression(value); } -export interface MetadataModuleReferenceExpression extends MetadataSymbolicExpression, - MetadataSourceLocationInfo { +export interface MetadataModuleReferenceExpression extends MetadataSourceLocationInfo { __symbolic: 'reference'; module: string; } @@ -212,8 +219,7 @@ export function isMetadataModuleReferenceExpression(value: any): isMetadataSymbolicReferenceExpression(value); } -export interface MetadataImportedSymbolReferenceExpression extends MetadataSymbolicExpression, - MetadataSourceLocationInfo { +export interface MetadataImportedSymbolReferenceExpression extends MetadataSourceLocationInfo { __symbolic: 'reference'; module: string; name: string; @@ -224,8 +230,7 @@ export function isMetadataImportedSymbolReferenceExpression(value: any): return value && value.module && !!value.name && isMetadataSymbolicReferenceExpression(value); } -export interface MetadataImportedDefaultReferenceExpression extends MetadataSymbolicExpression, - MetadataSourceLocationInfo { +export interface MetadataImportedDefaultReferenceExpression extends MetadataSourceLocationInfo { __symbolic: 'reference'; module: string; default: @@ -245,17 +250,17 @@ export function isMetadataSymbolicReferenceExpression(value: any): return value && value.__symbolic === 'reference'; } -export interface MetadataSymbolicSelectExpression extends MetadataSymbolicExpression { +export interface MetadataSymbolicSelectExpression { __symbolic: 'select'; expression: MetadataValue; - name: string; + member: string; } export function isMetadataSymbolicSelectExpression(value: any): value is MetadataSymbolicSelectExpression { return value && value.__symbolic === 'select'; } -export interface MetadataSymbolicSpreadExpression extends MetadataSymbolicExpression { +export interface MetadataSymbolicSpreadExpression { __symbolic: 'spread'; expression: MetadataValue; } diff --git a/packages/compiler-cli/src/ngtools_api2.ts b/packages/compiler-cli/src/ngtools_api2.ts index 0342638585..bde6a9cf43 100644 --- a/packages/compiler-cli/src/ngtools_api2.ts +++ b/packages/compiler-cli/src/ngtools_api2.ts @@ -108,15 +108,15 @@ export interface LazyRoute { export interface Program { getTsProgram(): ts.Program; - getTsOptionDiagnostics(cancellationToken?: ts.CancellationToken): ts.Diagnostic[]; - getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken): Diagnostic[]; + getTsOptionDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray; + getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray; getTsSyntacticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken): - ts.Diagnostic[]; - getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): Diagnostic[]; + ReadonlyArray; + getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray; getTsSemanticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken): - ts.Diagnostic[]; + ReadonlyArray; getNgSemanticDiagnostics(fileName?: string, cancellationToken?: ts.CancellationToken): - Diagnostic[]; + ReadonlyArray; loadNgStructureAsync(): Promise; listLazyRoutes(entryRoute?: string): LazyRoute[]; emit({emitFlags, cancellationToken, customTransformers, emitCallback}: { @@ -132,7 +132,7 @@ export function createProgram( {rootNames, options, host, oldProgram}: {rootNames: string[], options: CompilerOptions, host: CompilerHost, oldProgram?: Program}): Program { - return createProgramOrig({rootNames, options, host, oldProgram: oldProgram as ProgramOrig}); + return createProgramOrig({rootNames, options, host, oldProgram: oldProgram as any}); } // Wrapper for createCompilerHost. @@ -143,7 +143,7 @@ export function createCompilerHost( } // Wrapper for formatDiagnostics. -export type Diagnostics = Array; +export type Diagnostics = ReadonlyArray; export function formatDiagnostics(diags: Diagnostics): string { return formatDiagnosticsOrig(diags); -} \ No newline at end of file +} diff --git a/packages/compiler-cli/src/perform_compile.ts b/packages/compiler-cli/src/perform_compile.ts index 8135298d4f..c03201c60f 100644 --- a/packages/compiler-cli/src/perform_compile.ts +++ b/packages/compiler-cli/src/perform_compile.ts @@ -17,7 +17,7 @@ import {createMessageDiagnostic} from './transformers/util'; const TS_EXT = /\.ts$/; -export type Diagnostics = Array; +export type Diagnostics = ReadonlyArray; export function filterErrorsAndWarnings(diagnostics: Diagnostics): Diagnostics { return diagnostics.filter(d => d.category !== ts.DiagnosticCategory.Message); @@ -199,7 +199,7 @@ export function performCompilation({rootNames, options, host, oldProgram, emitCa }): PerformCompilationResult { let program: api.Program|undefined; let emitResult: ts.EmitResult|undefined; - let allDiagnostics: Diagnostics = []; + let allDiagnostics: Array = []; try { if (!host) { host = ng.createCompilerHost({options}); @@ -240,7 +240,7 @@ export function performCompilation({rootNames, options, host, oldProgram, emitCa } } function defaultGatherDiagnostics(program: api.Program): Diagnostics { - const allDiagnostics: Diagnostics = []; + const allDiagnostics: Array = []; function checkDiagnostics(diags: Diagnostics | undefined) { if (diags) { @@ -257,7 +257,7 @@ function defaultGatherDiagnostics(program: api.Program): Diagnostics { // Check syntactic diagnostics checkOtherDiagnostics = - checkOtherDiagnostics && checkDiagnostics(program.getTsSyntacticDiagnostics()); + checkOtherDiagnostics && checkDiagnostics(program.getTsSyntacticDiagnostics() as Diagnostics); // Check TypeScript semantic and Angular structure diagnostics checkOtherDiagnostics = @@ -267,7 +267,7 @@ function defaultGatherDiagnostics(program: api.Program): Diagnostics { // Check Angular semantic diagnostics checkOtherDiagnostics = - checkOtherDiagnostics && checkDiagnostics(program.getNgSemanticDiagnostics()); + checkOtherDiagnostics && checkDiagnostics(program.getNgSemanticDiagnostics() as Diagnostics); return allDiagnostics; } diff --git a/packages/compiler-cli/src/perform_watch.ts b/packages/compiler-cli/src/perform_watch.ts index d27026eed7..0cf9cd5edd 100644 --- a/packages/compiler-cli/src/perform_watch.ts +++ b/packages/compiler-cli/src/perform_watch.ts @@ -161,7 +161,7 @@ export function performWatchCompilation(host: PerformWatchHost): const originalWriteFileCallback = cachedCompilerHost.writeFile; cachedCompilerHost.writeFile = function( fileName: string, data: string, writeByteOrderMark: boolean, - onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]) { + onError?: (message: string) => void, sourceFiles: ReadonlyArray = []) { ingoreFilesForWatch.add(path.normalize(fileName)); return originalWriteFileCallback(fileName, data, writeByteOrderMark, onError, sourceFiles); }; @@ -275,4 +275,4 @@ export function performWatchCompilation(host: PerformWatchHost): [createMessageDiagnostic('File change detected. Starting incremental compilation.')]); doCompilation(); } -} \ No newline at end of file +} diff --git a/packages/compiler-cli/src/transformers/api.ts b/packages/compiler-cli/src/transformers/api.ts index d7e6f8addf..5cf769cba0 100644 --- a/packages/compiler-cli/src/transformers/api.ts +++ b/packages/compiler-cli/src/transformers/api.ts @@ -266,12 +266,12 @@ export interface Program { * faster than calling `getTsProgram().getOptionsDiagnostics()` since it does not need to * collect Angular structural information to produce the errors. */ - getTsOptionDiagnostics(cancellationToken?: ts.CancellationToken): ts.Diagnostic[]; + getTsOptionDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray; /** * Retrieve options diagnostics for the Angular options used to create the program. */ - getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken): Diagnostic[]; + getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray; /** * Retrieve the syntax diagnostics from TypeScript. This is faster than calling @@ -279,7 +279,7 @@ export interface Program { * information to produce the errors. */ getTsSyntacticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken): - ts.Diagnostic[]; + ReadonlyArray; /** * Retrieve the diagnostics for the structure of an Angular application is correctly formed. @@ -292,14 +292,14 @@ export interface Program { * * Angular structural information is required to produce these diagnostics. */ - getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): Diagnostic[]; + getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray; /** * Retrieve the semantic diagnostics from TypeScript. This is equivilent to calling * `getTsProgram().getSemanticDiagnostics()` directly and is included for completeness. */ getTsSemanticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken): - ts.Diagnostic[]; + ReadonlyArray; /** * Retrieve the Angular semantic diagnostics. @@ -307,7 +307,7 @@ export interface Program { * Angular structural information is required to produce these diagnostics. */ getNgSemanticDiagnostics(fileName?: string, cancellationToken?: ts.CancellationToken): - Diagnostic[]; + ReadonlyArray; /** * Load Angular structural information asynchronously. If this method is not called then the diff --git a/packages/compiler-cli/src/transformers/compiler_host.ts b/packages/compiler-cli/src/transformers/compiler_host.ts index a66e46ab62..6a0f57bf7c 100644 --- a/packages/compiler-cli/src/transformers/compiler_host.ts +++ b/packages/compiler-cli/src/transformers/compiler_host.ts @@ -62,7 +62,7 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos private flatModuleIndexRedirectNames = new Set(); private rootDirs: string[]; private moduleResolutionCache: ts.ModuleResolutionCache; - private originalSourceFiles = new Map(); + private originalSourceFiles = new Map(); private originalFileExistsCache = new Map(); private generatedSourceFiles = new Map(); private generatedCodeFor = new Map(); @@ -76,8 +76,9 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos directoryExists?: (directoryName: string) => boolean; constructor( - private rootFiles: string[], private options: CompilerOptions, private context: CompilerHost, - private metadataProvider: MetadataProvider, private codeGenerator: CodeGenerator, + private rootFiles: ReadonlyArray, private options: CompilerOptions, + private context: CompilerHost, private metadataProvider: MetadataProvider, + private codeGenerator: CodeGenerator, private librarySummaries = new Map()) { this.moduleResolutionCache = ts.createModuleResolutionCache( this.context.getCurrentDirectory !(), this.context.getCanonicalFileName.bind(this.context)); @@ -565,7 +566,8 @@ function addReferencesToSourceFile(sf: ts.SourceFile, genFileNames: string[]) { // value for `referencedFiles` around in cache the original host is caching ts.SourceFiles. // Note: cloning the ts.SourceFile is expensive as the nodes in have parent pointers, // i.e. we would also need to clone and adjust all nodes. - let originalReferencedFiles: ts.FileReference[]|undefined = (sf as any).originalReferencedFiles; + let originalReferencedFiles: ReadonlyArray = + (sf as any).originalReferencedFiles; if (!originalReferencedFiles) { originalReferencedFiles = sf.referencedFiles; (sf as any).originalReferencedFiles = originalReferencedFiles; diff --git a/packages/compiler-cli/src/transformers/program.ts b/packages/compiler-cli/src/transformers/program.ts index c7b0079ea0..d5cca5a58d 100644 --- a/packages/compiler-cli/src/transformers/program.ts +++ b/packages/compiler-cli/src/transformers/program.ts @@ -40,6 +40,7 @@ const defaultEmitCallback: TsEmitCallback = targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers); class AngularCompilerProgram implements Program { + private rootNames: string[]; private metadataCache: LowerMetadataCache; private oldProgramLibrarySummaries: Map|undefined; private oldProgramEmittedGeneratedFiles: Map|undefined; @@ -60,8 +61,9 @@ class AngularCompilerProgram implements Program { private _optionsDiagnostics: Diagnostic[] = []; constructor( - private rootNames: string[], private options: CompilerOptions, private host: CompilerHost, - oldProgram?: Program) { + rootNames: ReadonlyArray, private options: CompilerOptions, + private host: CompilerHost, oldProgram?: Program) { + this.rootNames = [...rootNames]; const [major, minor] = ts.version.split('.'); if (Number(major) < 2 || (Number(major) === 2 && Number(minor) < 4)) { throw new Error('The Angular Compiler requires TypeScript >= 2.4.'); @@ -74,7 +76,8 @@ class AngularCompilerProgram implements Program { } if (options.flatModuleOutFile) { - const {host: bundleHost, indexName, errors} = createBundleIndexHost(options, rootNames, host); + const {host: bundleHost, indexName, errors} = + createBundleIndexHost(options, this.rootNames, host); if (errors) { // TODO(tbosch): once we move MetadataBundler from tsc_wrapped into compiler_cli, // directly create ng.Diagnostic instead of using ts.Diagnostic here. @@ -85,7 +88,7 @@ class AngularCompilerProgram implements Program { code: DEFAULT_ERROR_CODE }))); } else { - rootNames.push(indexName !); + this.rootNames.push(indexName !); this.host = bundleHost; } } @@ -133,21 +136,21 @@ class AngularCompilerProgram implements Program { return this.tsProgram.getOptionsDiagnostics(cancellationToken); } - getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken): Diagnostic[] { + getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray { return [...this._optionsDiagnostics, ...getNgOptionDiagnostics(this.options)]; } getTsSyntacticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken): - ts.Diagnostic[] { + ReadonlyArray { return this.tsProgram.getSyntacticDiagnostics(sourceFile, cancellationToken); } - getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): Diagnostic[] { + getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray { return this.structuralDiagnostics; } getTsSemanticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken): - ts.Diagnostic[] { + ReadonlyArray { const sourceFiles = sourceFile ? [sourceFile] : this.tsProgram.getSourceFiles(); let diags: ts.Diagnostic[] = []; sourceFiles.forEach(sf => { @@ -159,7 +162,7 @@ class AngularCompilerProgram implements Program { } getNgSemanticDiagnostics(fileName?: string, cancellationToken?: ts.CancellationToken): - Diagnostic[] { + ReadonlyArray { let diags: ts.Diagnostic[] = []; this.tsProgram.getSourceFiles().forEach(sf => { if (GENERATED_FILES.test(sf.fileName) && !sf.isDeclarationFile) { @@ -245,7 +248,7 @@ class AngularCompilerProgram implements Program { const emitOnlyDtsFiles = (emitFlags & (EmitFlags.DTS | EmitFlags.JS)) == EmitFlags.DTS; // Restore the original references before we emit so TypeScript doesn't emit // a reference to the .d.ts file. - const augmentedReferences = new Map(); + const augmentedReferences = new Map>(); for (const sourceFile of this.tsProgram.getSourceFiles()) { const originalReferences = getOriginalReferences(sourceFile); if (originalReferences) { @@ -295,7 +298,8 @@ class AngularCompilerProgram implements Program { // Restore the references back to the augmented value to ensure that the // checks that TypeScript makes for project structure reuse will succeed. for (const [sourceFile, references] of Array.from(augmentedReferences)) { - sourceFile.referencedFiles = references; + // TODO(chuckj): Remove any cast after updating build to 2.6 + (sourceFile as any).referencedFiles = references; } } this.emittedSourceFiles = emittedSourceFiles; @@ -312,7 +316,8 @@ class AngularCompilerProgram implements Program { if (!outSrcMapping.length) { // if no files were emitted by TypeScript, also don't emit .json files - emitResult.diagnostics.push(createMessageDiagnostic(`Emitted no files.`)); + emitResult.diagnostics = + emitResult.diagnostics.concat([createMessageDiagnostic(`Emitted no files.`)]); return emitResult; } @@ -346,12 +351,12 @@ class AngularCompilerProgram implements Program { } const emitEnd = Date.now(); if (this.options.diagnostics) { - emitResult.diagnostics.push(createMessageDiagnostic([ + emitResult.diagnostics = emitResult.diagnostics.concat([createMessageDiagnostic([ `Emitted in ${emitEnd - emitStart}ms`, `- ${emittedUserTsCount} user ts files`, `- ${genTsFiles.length} generated ts files`, `- ${genJsonFiles.length + metadataJsonCount} generated json files`, - ].join('\n'))); + ].join('\n'))]); } return emitResult; } @@ -378,7 +383,7 @@ class AngularCompilerProgram implements Program { return this._analyzedModules !; } - private get structuralDiagnostics(): Diagnostic[] { + private get structuralDiagnostics(): ReadonlyArray { let diagnostics = this._structuralDiagnostics; if (!diagnostics) { this.initSync(); @@ -645,10 +650,11 @@ class AngularCompilerProgram implements Program { } } -export function createProgram( - {rootNames, options, host, oldProgram}: - {rootNames: string[], options: CompilerOptions, host: CompilerHost, oldProgram?: Program}): - Program { +export function createProgram({rootNames, options, host, oldProgram}: { + rootNames: ReadonlyArray, + options: CompilerOptions, + host: CompilerHost, oldProgram?: Program +}): Program { return new AngularCompilerProgram(rootNames, options, host, oldProgram); } @@ -689,7 +695,7 @@ function getAotCompilerOptions(options: CompilerOptions): AotCompilerOptions { }; } -function getNgOptionDiagnostics(options: CompilerOptions): Diagnostic[] { +function getNgOptionDiagnostics(options: CompilerOptions): ReadonlyArray { if (options.annotationsAs) { switch (options.annotationsAs) { case 'decorators': @@ -767,7 +773,7 @@ export function i18nExtract( const content = i18nSerialize(bundle, formatName, options); const dstFile = outFile || `messages.${ext}`; const dstPath = path.resolve(options.outDir || options.basePath, dstFile); - host.writeFile(dstPath, content, false); + host.writeFile(dstPath, content, false, undefined, []); return [dstPath]; } diff --git a/packages/compiler-cli/test/diagnostics/check_types_spec.ts b/packages/compiler-cli/test/diagnostics/check_types_spec.ts index 00d48489ad..f125a5f2ab 100644 --- a/packages/compiler-cli/test/diagnostics/check_types_spec.ts +++ b/packages/compiler-cli/test/diagnostics/check_types_spec.ts @@ -84,7 +84,7 @@ describe('ng type checker', () => { }); describe('type narrowing', () => { - const a = (files: MockFiles, options: object = {}) => { + const a = (files: MockFiles, options: ng.AngularCompilerOptions = {}) => { accept(files, {fullTemplateTypeCheck: true, ...options}); }; @@ -517,7 +517,7 @@ describe('ng type checker', () => { }); describe('casting $any', () => { - const a = (files: MockFiles, options: object = {}) => { + const a = (files: MockFiles, options: ng.AngularCompilerOptions = {}) => { accept( {'src/app.component.ts': '', 'src/lib.ts': '', ...files}, {fullTemplateTypeCheck: true, ...options}); @@ -525,7 +525,7 @@ describe('ng type checker', () => { const r = (message: string | RegExp, location: RegExp | null, files: MockFiles, - options: object = {}) => { + options: ng.AngularCompilerOptions = {}) => { reject( message, location, {'src/app.component.ts': '', 'src/lib.ts': '', ...files}, {fullTemplateTypeCheck: true, ...options}); @@ -621,7 +621,7 @@ describe('ng type checker', () => { }); describe('regressions ', () => { - const a = (files: MockFiles, options: object = {}) => { + const a = (files: MockFiles, options: ng.AngularCompilerOptions = {}) => { accept(files, {fullTemplateTypeCheck: true, ...options}); }; diff --git a/packages/compiler-cli/test/metadata/collector_spec.ts b/packages/compiler-cli/test/metadata/collector_spec.ts index e88e72aa33..34ca4a4979 100644 --- a/packages/compiler-cli/test/metadata/collector_spec.ts +++ b/packages/compiler-cli/test/metadata/collector_spec.ts @@ -22,38 +22,21 @@ describe('Collector', () => { beforeEach(() => { host = new Host(FILES, [ - '/app/app.component.ts', - '/app/cases-data.ts', - '/app/error-cases.ts', - '/promise.ts', - '/unsupported-1.ts', - '/unsupported-2.ts', - '/unsupported-3.ts', - 'class-arity.ts', - 'declarations.d.ts', - 'import-star.ts', - 'exported-classes.ts', - 'exported-functions.ts', - 'exported-enum.ts', - 'exported-type.ts', - 'exported-consts.ts', - 'local-symbol-ref.ts', - 'local-function-ref.ts', - 'local-symbol-ref-func.ts', - 'local-symbol-ref-func-dynamic.ts', - 'private-enum.ts', - 're-exports.ts', - 're-exports-2.ts', - 'export-as.d.ts', - 'named-module.d.ts', - 'static-field-reference.ts', - 'static-method.ts', - 'static-method-call.ts', - 'static-method-with-if.ts', - 'static-method-with-default.ts', - 'class-inheritance.ts', - 'class-inheritance-parent.ts', - 'class-inheritance-declarations.d.ts', + '/app/app.component.ts', '/app/cases-data.ts', + '/app/error-cases.ts', '/promise.ts', + '/unsupported-1.ts', '/unsupported-2.ts', + '/unsupported-3.ts', 'class-arity.ts', + 'declarations.d.ts', 'import-star.ts', + 'exported-classes.ts', 'exported-functions.ts', + 'exported-enum.ts', 'exported-type.ts', + 'exported-consts.ts', 'local-symbol-ref.ts', + 'local-function-ref.ts', 'local-symbol-ref-func.ts', + 'private-enum.ts', 're-exports.ts', + 're-exports-2.ts', 'export-as.d.ts', + 'named-module.d.ts', 'static-field-reference.ts', + 'static-method.ts', 'static-method-call.ts', + 'static-method-with-if.ts', 'static-method-with-default.ts', + 'class-inheritance.ts', 'class-inheritance-parent.ts', 'interface-reference.ts' ]); service = ts.createLanguageService(host, documentRegistry); diff --git a/packages/compiler-cli/test/metadata/symbols_spec.ts b/packages/compiler-cli/test/metadata/symbols_spec.ts index c0cacb0db6..9ec9041fc3 100644 --- a/packages/compiler-cli/test/metadata/symbols_spec.ts +++ b/packages/compiler-cli/test/metadata/symbols_spec.ts @@ -91,7 +91,8 @@ describe('Symbols', () => { }); it('should be able to resolve any symbol in core global scope', () => { - const core = program.getSourceFiles().find(source => source.fileName.endsWith('lib.d.ts')); + const core = (program.getSourceFiles() as ts.SourceFile[]) + .find(source => source.fileName.endsWith('lib.d.ts')); expect(core).toBeDefined(); const visit = (node: ts.Node): boolean => { switch (node.kind) { diff --git a/packages/compiler-cli/test/metadata/typescript.mocks.ts b/packages/compiler-cli/test/metadata/typescript.mocks.ts index d63bd7a5c7..517191ec07 100644 --- a/packages/compiler-cli/test/metadata/typescript.mocks.ts +++ b/packages/compiler-cli/test/metadata/typescript.mocks.ts @@ -161,6 +161,9 @@ export function expectNoDiagnostics(diagnostics: ts.Diagnostic[]) { const {line, character} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); // tslint:disable-next-line:no-console console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); + } else { + // tslint:disable-next-line:no-console + console.log(message); } } expect(diagnostics.length).toBe(0); diff --git a/packages/compiler-cli/test/ngc_spec.ts b/packages/compiler-cli/test/ngc_spec.ts index a7cf6a2c2b..65bc967120 100644 --- a/packages/compiler-cli/test/ngc_spec.ts +++ b/packages/compiler-cli/test/ngc_spec.ts @@ -684,7 +684,7 @@ describe('ngc transformer command-line', () => { expect(exitCode).toEqual(0); const mymodulejs = path.resolve(outDir, 'mymodule.js'); const mymoduleSource = fs.readFileSync(mymodulejs, 'utf8'); - expect(mymoduleSource).toContain(`import { A } from "submodule"`); + expect(mymoduleSource).toContain(`import { A } from 'submodule'`); }); describe('expression lowering', () => { diff --git a/packages/compiler-cli/test/perform_watch_spec.ts b/packages/compiler-cli/test/perform_watch_spec.ts index 5d30f371e6..76de99d25f 100644 --- a/packages/compiler-cli/test/perform_watch_spec.ts +++ b/packages/compiler-cli/test/perform_watch_spec.ts @@ -166,10 +166,10 @@ class MockWatchHost { nextTimeoutListenerId = 1; timeoutListeners: {[id: string]: (() => void)} = {}; fileChangeListeners: Array<((event: FileChangeEvent, fileName: string) => void)|null> = []; - diagnostics: ng.Diagnostics = []; + diagnostics: ng.Diagnostic[] = []; constructor(public config: ng.ParsedConfiguration) {} - reportDiagnostics(diags: ng.Diagnostics) { this.diagnostics.push(...diags); } + reportDiagnostics(diags: ng.Diagnostics) { this.diagnostics.push(...(diags as ng.Diagnostic[])); } readConfiguration() { return this.config; } createCompilerHost(options: ng.CompilerOptions) { return ng.createCompilerHost({options}); } createEmitCallback() { return undefined; } diff --git a/packages/compiler-cli/test/transformers/program_spec.ts b/packages/compiler-cli/test/transformers/program_spec.ts index 6b52e110ba..89cdaefafd 100644 --- a/packages/compiler-cli/test/transformers/program_spec.ts +++ b/packages/compiler-cli/test/transformers/program_spec.ts @@ -431,14 +431,15 @@ describe('ng program', () => { }); const host = ng.createCompilerHost({options}); const written = new Map < string, { - original: ts.SourceFile[]|undefined; + original: ReadonlyArray|undefined; data: string; } > (); host.writeFile = (fileName: string, data: string, writeByteOrderMark: boolean, - onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]) => { + onError: (message: string) => void|undefined, + sourceFiles: ReadonlyArray) => { written.set(fileName, {original: sourceFiles, data}); }; const program = ng.createProgram( @@ -510,9 +511,9 @@ describe('ng program', () => { const host = ng.createCompilerHost({options}); const writtenFileNames: string[] = []; const oldWriteFile = host.writeFile; - host.writeFile = (fileName, data, writeByteOrderMark) => { + host.writeFile = (fileName, data, writeByteOrderMark, onError, sourceFiles) => { writtenFileNames.push(fileName); - oldWriteFile(fileName, data, writeByteOrderMark); + oldWriteFile(fileName, data, writeByteOrderMark, onError, sourceFiles); }; compile(/*oldProgram*/ undefined, options, /*rootNames*/ undefined, host); diff --git a/packages/compiler/test/aot/test_util.ts b/packages/compiler/test/aot/test_util.ts index 4fa62fa501..546b656938 100644 --- a/packages/compiler/test/aot/test_util.ts +++ b/packages/compiler/test/aot/test_util.ts @@ -172,7 +172,7 @@ export class EmittingCompilerHost implements ts.CompilerHost { writeFile: ts.WriteFileCallback = (fileName: string, data: string, writeByteOrderMark: boolean, - onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]) => { + onError?: (message: string) => void, sourceFiles?: ReadonlyArray) => { this.addWrittenFile(fileName, data); if (this.options.emitMetadata && sourceFiles && sourceFiles.length && DTS.test(fileName)) { const metadataFilePath = fileName.replace(DTS, '.metadata.json'); @@ -430,7 +430,7 @@ export class MockMetadataBundlerHost implements MetadataBundlerHost { getMetadataFor(moduleName: string): ModuleMetadata|undefined { const source = this.host.getSourceFile(moduleName + '.ts', ts.ScriptTarget.Latest); - return this.collector.getMetadata(source); + return source && this.collector.getMetadata(source); } } @@ -603,7 +603,7 @@ export function expectNoDiagnostics(program: ts.Program) { return ''; } - function expectNoDiagnostics(diagnostics: ts.Diagnostic[]) { + function expectNoDiagnostics(diagnostics: ReadonlyArray) { if (diagnostics && diagnostics.length) { throw new Error( 'Errors from TypeScript:\n' + diff --git a/packages/language-service/src/ts_plugin.ts b/packages/language-service/src/ts_plugin.ts index 77f73fbbe1..81a92964c8 100644 --- a/packages/language-service/src/ts_plugin.ts +++ b/packages/language-service/src/ts_plugin.ts @@ -64,13 +64,15 @@ function angularOnlyFilter(ls: ts.LanguageService): ts.LanguageService { getFormattingEditsAfterKeystroke: (fileName, position, key, options) => [], getDocCommentTemplateAtPosition: (fileName, position) => undefined, isValidBraceCompletionAtPosition: (fileName, position, openingBrace) => undefined, + getSpanOfEnclosingComment: (fileName, position, onlyMultiLine) => undefined, getCodeFixesAtPosition: (fileName, start, end, errorCodes) => [], + applyCodeActionCommand: (action: any) => Promise.resolve(undefined), getEmitOutput: fileName => undefined, getProgram: () => ls.getProgram(), dispose: () => ls.dispose(), getApplicableRefactors: (fileName, positionOrRaneg) => [], getEditsForRefactor: (fileName, formatOptions, positionOrRange, refactorName, actionName) => - undefined, + undefined }; } @@ -130,9 +132,9 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS getSemanticClassifications: tryFilenameOneCall(ls.getSemanticClassifications), getEncodedSyntacticClassifications: tryFilenameOneCall(ls.getEncodedSyntacticClassifications), getEncodedSemanticClassifications: tryFilenameOneCall(ls.getEncodedSemanticClassifications), - getCompletionsAtPosition: tryFilenameOneCall(ls.getCompletionsAtPosition), - getCompletionEntryDetails: tryFilenameTwoCall(ls.getCompletionEntryDetails), - getCompletionEntrySymbol: tryFilenameTwoCall(ls.getCompletionEntrySymbol), + getCompletionsAtPosition: tryFilenameTwoCall(ls.getCompletionsAtPosition), + getCompletionEntryDetails: tryFilenameFourCall(ls.getCompletionEntryDetails), + getCompletionEntrySymbol: tryFilenameThreeCall(ls.getCompletionEntrySymbol), getQuickInfoAtPosition: tryFilenameOneCall(ls.getQuickInfoAtPosition), getNameOrDottedNameSpan: tryFilenameTwoCall(ls.getNameOrDottedNameSpan), getBreakpointStatementAtPosition: tryFilenameOneCall(ls.getBreakpointStatementAtPosition), @@ -162,13 +164,15 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS getFormattingEditsAfterKeystroke: tryFilenameThreeCall(ls.getFormattingEditsAfterKeystroke), getDocCommentTemplateAtPosition: tryFilenameOneCall(ls.getDocCommentTemplateAtPosition), isValidBraceCompletionAtPosition: tryFilenameTwoCall(ls.isValidBraceCompletionAtPosition), + getSpanOfEnclosingComment: tryFilenameTwoCall(ls.getSpanOfEnclosingComment), getCodeFixesAtPosition: tryFilenameFourCall(ls.getCodeFixesAtPosition), + applyCodeActionCommand: + ((action: any) => tryCall(undefined, () => ls.applyCodeActionCommand(action))), getEmitOutput: tryFilenameCall(ls.getEmitOutput), getProgram: () => ls.getProgram(), dispose: () => ls.dispose(), - getApplicableRefactors: (fileName, positionOrRaneg) => [], - getEditsForRefactor: (fileName, formatOptions, positionOrRange, refactorName, actionName) => - undefined, + getApplicableRefactors: tryFilenameOneCall(ls.getApplicableRefactors), + getEditsForRefactor: tryFilenameFourCall(ls.getEditsForRefactor) }; } @@ -234,8 +238,9 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS serviceHost.setSite(ls); projectHostMap.set(info.project, serviceHost); - proxy.getCompletionsAtPosition = function(fileName: string, position: number) { - let base = oldLS.getCompletionsAtPosition(fileName, position) || { + proxy.getCompletionsAtPosition = function( + fileName: string, position: number, options: ts.GetCompletionsAtPositionOptions|undefined) { + let base = oldLS.getCompletionsAtPosition(fileName, position, options) || { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, diff --git a/packages/language-service/test/ts_plugin_spec.ts b/packages/language-service/test/ts_plugin_spec.ts index 28fd1d14f1..c82d878597 100644 --- a/packages/language-service/test/ts_plugin_spec.ts +++ b/packages/language-service/test/ts_plugin_spec.ts @@ -203,12 +203,14 @@ describe('plugin', () => { } function contains(fileName: string, locationMarker: string, ...names: string[]) { const location = getMarkerLocation(fileName, locationMarker); - expectEntries(locationMarker, plugin.getCompletionsAtPosition(fileName, location), ...names); + expectEntries( + locationMarker, plugin.getCompletionsAtPosition(fileName, location, undefined), ...names); } function expectEmpty(fileName: string, locationMarker: string) { const location = getMarkerLocation(fileName, locationMarker); - expect(plugin.getCompletionsAtPosition(fileName, location).entries || []).toEqual([]); + expect(plugin.getCompletionsAtPosition(fileName, location, undefined).entries || []).toEqual([ + ]); } function expectSemanticError(fileName: string, locationMarker: string, message: string) { diff --git a/packages/service-worker/worker/src/app-version.ts b/packages/service-worker/worker/src/app-version.ts index 0ec3f50f0f..9fbbcd6e5e 100644 --- a/packages/service-worker/worker/src/app-version.ts +++ b/packages/service-worker/worker/src/app-version.ts @@ -124,7 +124,7 @@ export class AppVersion implements UpdateSource { // No response has been found yet. Maybe this group will have one. return group.handleFetch(req, context); - }, Promise.resolve(null)); + }, Promise.resolve(null)); // The result of the above is the asset response, if there is any, or null otherwise. Return the // asset @@ -142,7 +142,7 @@ export class AppVersion implements UpdateSource { } return group.handleFetch(req, context); - }, Promise.resolve(null)); + }, Promise.resolve(null)); // If the data caching group returned a response, go with it. if (data !== null) { diff --git a/packages/service-worker/worker/src/assets.ts b/packages/service-worker/worker/src/assets.ts index aaaf9f399e..9e7fff4b3c 100644 --- a/packages/service-worker/worker/src/assets.ts +++ b/packages/service-worker/worker/src/assets.ts @@ -276,6 +276,7 @@ export abstract class AssetGroup { const cache = await this.cache; // Start with the set of all cached URLs. return (await cache.keys()) + .map(request => request.url) // Exclude the URLs which have hashes. .filter(url => !this.hashes.has(url)); } @@ -608,4 +609,4 @@ export class LazyAssetGroup extends AssetGroup { } }, Promise.resolve()); } -} \ No newline at end of file +} diff --git a/packages/service-worker/worker/src/db-cache.ts b/packages/service-worker/worker/src/db-cache.ts index 2da7c79fa7..581aadf2fb 100644 --- a/packages/service-worker/worker/src/db-cache.ts +++ b/packages/service-worker/worker/src/db-cache.ts @@ -51,7 +51,7 @@ export class CacheTable implements Table { 'delete'(key: string): Promise { return this.cache.delete(this.request(key)); } keys(): Promise { - return this.cache.keys().then(keys => keys.map(key => key.substr(1))); + return this.cache.keys().then(requests => requests.map(req => req.url.substr(1))); } read(key: string): Promise { @@ -66,4 +66,4 @@ export class CacheTable implements Table { write(key: string, value: Object): Promise { return this.cache.put(this.request(key), this.adapter.newResponse(JSON.stringify(value))); } -} \ No newline at end of file +} diff --git a/packages/service-worker/worker/src/service-worker.d.ts b/packages/service-worker/worker/src/service-worker.d.ts index 06a9969af8..9d01e81e58 100644 --- a/packages/service-worker/worker/src/service-worker.d.ts +++ b/packages/service-worker/worker/src/service-worker.d.ts @@ -25,33 +25,6 @@ interface ExtendableEvent extends Event { waitUntil(fn: Promise): void; } -// CacheStorage API - -interface Cache { - add(request: Request): Promise; - addAll(requestArray: Array): Promise; - 'delete'(request: Request, options?: CacheStorageOptions): Promise; - keys(request?: Request, options?: CacheStorageOptions): Promise>; - match(request: Request, options?: CacheStorageOptions): Promise; - matchAll(request: Request, options?: CacheStorageOptions): Promise>; - put(request: Request|string, response: Response): Promise; -} - -interface CacheStorage { - 'delete'(cacheName: string): Promise; - has(cacheName: string): Promise; - keys(): Promise>; - match(request: Request, options?: CacheStorageOptions): Promise; - open(cacheName: string): Promise; -} - -interface CacheStorageOptions { - cacheName?: string; - ignoreMethod?: boolean; - ignoreSearch?: boolean; - ignoreVary?: boolean; -} - // Client API declare class Client { @@ -145,4 +118,4 @@ interface ServiceWorkerGlobalScope { fetch(request: Request|string): Promise; skipWaiting(): Promise; -} \ No newline at end of file +} diff --git a/packages/service-worker/worker/testing/cache.ts b/packages/service-worker/worker/testing/cache.ts index 0c4a730bc9..e56c43410a 100644 --- a/packages/service-worker/worker/testing/cache.ts +++ b/packages/service-worker/worker/testing/cache.ts @@ -41,7 +41,7 @@ export class MockCacheStorage implements CacheStorage { if (!this.caches.has(name)) { this.caches.set(name, new MockCache(this.origin)); } - return this.caches.get(name) !; + return this.caches.get(name) as any; } async match(req: Request): Promise { @@ -74,7 +74,7 @@ export class MockCacheStorage implements CacheStorage { } } -export class MockCache implements Cache { +export class MockCache { private cache = new Map(); constructor(private origin: string, hydrated?: DehydratedCache) { @@ -122,7 +122,6 @@ export class MockCache implements Cache { return res !; } - async matchAll(request?: Request|string, options?: CacheQueryOptions): Promise { if (request === undefined) { return Array.from(this.cache.values()); @@ -149,7 +148,7 @@ export class MockCache implements Cache { dehydrate(): DehydratedCache { const dehydrated: DehydratedCache = {}; Array.from(this.cache.keys()).forEach(url => { - const resp = this.cache.get(url) !as MockResponse; + const resp = this.cache.get(url) as MockResponse; const dehydratedResp = { body: resp._body, status: resp.status, @@ -163,4 +162,4 @@ export class MockCache implements Cache { }); return dehydrated; } -} \ No newline at end of file +} diff --git a/packages/service-worker/worker/testing/fetch.ts b/packages/service-worker/worker/testing/fetch.ts index aeacf1a4c3..3a55f84a6a 100644 --- a/packages/service-worker/worker/testing/fetch.ts +++ b/packages/service-worker/worker/testing/fetch.ts @@ -57,17 +57,26 @@ export class MockBody implements Body { export class MockHeaders implements Headers { map = new Map(); + + [Symbol.iterator]() { return this.map[Symbol.iterator](); } + append(name: string, value: string): void { this.map.set(name, value); } delete (name: string): void { this.map.delete(name); } + entries() { return this.map.entries(); } + forEach(callback: Function): void { this.map.forEach(callback as any); } get(name: string): string|null { return this.map.get(name) || null; } has(name: string): boolean { return this.map.has(name); } + keys() { return this.map.keys(); } + set(name: string, value: string): void { this.map.set(name, value); } + + values() { return this.map.values(); } } export class MockRequest extends MockBody implements Request { @@ -91,13 +100,12 @@ export class MockRequest extends MockBody implements Request { throw 'Not implemented'; } this.url = input; - if (init.headers !== undefined) { - if (init.headers instanceof MockHeaders) { - this.headers = init.headers; + const headers = init.headers as{[key: string]: string}; + if (headers !== undefined) { + if (headers instanceof MockHeaders) { + this.headers = headers; } else { - Object.keys(init.headers).forEach(header => { - this.headers.set(header, init.headers[header]); - }); + Object.keys(headers).forEach(header => { this.headers.set(header, headers[header]); }); } } if (init.mode !== undefined) { @@ -134,13 +142,12 @@ export class MockResponse extends MockBody implements Response { super(typeof body === 'string' ? body : null); this.status = (init.status !== undefined) ? init.status : 200; this.statusText = init.statusText || 'OK'; - if (init.headers !== undefined) { - if (init.headers instanceof MockHeaders) { - this.headers = init.headers; + const headers = init.headers as{[key: string]: string}; + if (headers !== undefined) { + if (headers instanceof MockHeaders) { + this.headers = headers; } else { - Object.keys(init.headers).forEach(header => { - this.headers.set(header, init.headers[header]); - }); + Object.keys(headers).forEach(header => { this.headers.set(header, headers[header]); }); } } if (init.type !== undefined) { diff --git a/packages/service-worker/worker/testing/mock.ts b/packages/service-worker/worker/testing/mock.ts index 7ec168841d..9ceadaf7a3 100644 --- a/packages/service-worker/worker/testing/mock.ts +++ b/packages/service-worker/worker/testing/mock.ts @@ -212,4 +212,4 @@ export function tmpHashTable(manifest: Manifest): Map { map.set(url, hash); }); return map; -} \ No newline at end of file +} diff --git a/scripts/ci/env.sh b/scripts/ci/env.sh index 5fcb8ea961..fc57a04356 100755 --- a/scripts/ci/env.sh +++ b/scripts/ci/env.sh @@ -42,7 +42,7 @@ setEnvVar CHROMIUM_VERSION 494239 # Chrome 62 linux stable, see https://www.chro setEnvVar CHROMEDRIVER_VERSION_ARG "--versions.chrome 2.33" setEnvVar BAZEL_VERSION 0.8.1 setEnvVar SAUCE_CONNECT_VERSION 4.4.9 -setEnvVar ANGULAR_CLI_VERSION 1.5.0-rc.2 +setEnvVar ANGULAR_CLI_VERSION 1.6.2 setEnvVar PROJECT_ROOT $(cd ${thisDir}/../..; pwd) if [[ ${TRAVIS:-} ]]; then diff --git a/yarn.lock b/yarn.lock index 442566b062..716af993c4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7083,9 +7083,9 @@ ts-api-guardian@0.2.2: minimist "^1.2.0" typescript "2.0.10" -tsickle@0.25.5: - version "0.25.5" - resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.25.5.tgz#2891d29f97c4aab1306e06378d8496d1765a4bfe" +tsickle@0.26.0: + version "0.26.0" + resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.26.0.tgz#40b30a2dd6abcb33b182e37596674bd1cfe4039c" dependencies: minimist "^1.2.0" mkdirp "^0.5.1" @@ -7186,9 +7186,9 @@ typescript@2.0.10: version "2.0.10" resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.0.10.tgz#ccdd4ed86fd5550a407101a0814012e1b3fac3dd" -typescript@2.5.x: - version "2.5.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.5.3.tgz#df3dcdc38f3beb800d4bc322646b04a3f6ca7f0d" +typescript@2.6.x: + version "2.6.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.2.tgz#3c5b6fd7f6de0914269027f03c0946758f7673a4" uglify-js@1.2.6, uglify-js@~1.2.5: version "1.2.6"