From 17e702bf8b1072c1832096babff77aab202ae265 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Thu, 6 Dec 2018 23:01:08 -0800 Subject: [PATCH] feat: add support for typescript 3.2 (#27536) https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-2.html https://blogs.msdn.microsoft.com/typescript/2018/11/29/announcing-typescript-3-2/ Any application using tsickle for closure compatibility will need to update it's tsickle dependency to 0.34 PR Close #27536 --- integration/typings_test_ts31/include-all.ts | 26 ++++++- integration/typings_test_ts32/include-all.ts | 73 +++++++++++++++++++ integration/typings_test_ts32/package.json | 31 ++++++++ integration/typings_test_ts32/tsconfig.json | 24 ++++++ package.json | 6 +- packages/bazel/package.json | 4 +- packages/compiler-cli/package.json | 8 +- .../src/ngcc/src/packages/transformer.ts | 18 ++++- .../compiler-cli/src/transformers/program.ts | 2 +- packages/language-service/src/ts_plugin.ts | 12 ++- tools/ts-api-guardian/package.json | 6 +- tools/ts-api-guardian/yarn.lock | 8 +- yarn.lock | 16 ++-- 13 files changed, 200 insertions(+), 34 deletions(-) create mode 100644 integration/typings_test_ts32/include-all.ts create mode 100644 integration/typings_test_ts32/package.json create mode 100644 integration/typings_test_ts32/tsconfig.json diff --git a/integration/typings_test_ts31/include-all.ts b/integration/typings_test_ts31/include-all.ts index ca81c56472..9eba62111f 100644 --- a/integration/typings_test_ts31/include-all.ts +++ b/integration/typings_test_ts31/include-all.ts @@ -6,6 +6,15 @@ * found in the LICENSE file at https://angular.io/license */ + + +import * as animations from '@angular/animations'; +import * as animationsBrowser from '@angular/animations/browser'; +import * as animationsBrowserTesting from '@angular/animations/browser/testing'; +import * as common from '@angular/common'; +import * as commonHttp from '@angular/common/http'; +import * as commonTesting from '@angular/common/testing'; +import * as commonHttpTesting from '@angular/common/testing'; import * as compiler from '@angular/compiler'; import * as compilerTesting from '@angular/compiler/testing'; import * as core from '@angular/core'; @@ -15,18 +24,29 @@ 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 platformBrowserDynamicTesting from '@angular/platform-browser-dynamic/testing'; +import * as platformBrowserAnimations from '@angular/platform-browser/animations'; +import * as platformBrowserTesting from '@angular/platform-browser/testing'; 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 routerUpgrade from '@angular/router/upgrade'; import * as serviceWorker from '@angular/service-worker'; import * as upgrade from '@angular/upgrade'; +import * as upgradeStatic from '@angular/upgrade/static'; export default { + animations, + animationsBrowser, + animationsBrowserTesting, + common, + commonTesting, + commonHttp, + commonHttpTesting, compiler, compilerTesting, core, @@ -38,12 +58,16 @@ export default { platformBrowser, platformBrowserTesting, platformBrowserDynamic, + platformBrowserDynamicTesting, + platformBrowserAnimations, platformServer, platformServerTesting, platformWebworker, platformWebworkerDynamic, router, routerTesting, + routerUpgrade, serviceWorker, upgrade, + upgradeStatic }; diff --git a/integration/typings_test_ts32/include-all.ts b/integration/typings_test_ts32/include-all.ts new file mode 100644 index 0000000000..9eba62111f --- /dev/null +++ b/integration/typings_test_ts32/include-all.ts @@ -0,0 +1,73 @@ +/** + * @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 animations from '@angular/animations'; +import * as animationsBrowser from '@angular/animations/browser'; +import * as animationsBrowserTesting from '@angular/animations/browser/testing'; +import * as common from '@angular/common'; +import * as commonHttp from '@angular/common/http'; +import * as commonTesting from '@angular/common/testing'; +import * as commonHttpTesting from '@angular/common/testing'; +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 elements from '@angular/elements'; +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 platformBrowserDynamic from '@angular/platform-browser-dynamic'; +import * as platformBrowserDynamicTesting from '@angular/platform-browser-dynamic/testing'; +import * as platformBrowserAnimations from '@angular/platform-browser/animations'; +import * as platformBrowserTesting from '@angular/platform-browser/testing'; +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 routerUpgrade from '@angular/router/upgrade'; +import * as serviceWorker from '@angular/service-worker'; +import * as upgrade from '@angular/upgrade'; +import * as upgradeStatic from '@angular/upgrade/static'; + +export default { + animations, + animationsBrowser, + animationsBrowserTesting, + common, + commonTesting, + commonHttp, + commonHttpTesting, + compiler, + compilerTesting, + core, + coreTesting, + elements, + forms, + http, + httpTesting, + platformBrowser, + platformBrowserTesting, + platformBrowserDynamic, + platformBrowserDynamicTesting, + platformBrowserAnimations, + platformServer, + platformServerTesting, + platformWebworker, + platformWebworkerDynamic, + router, + routerTesting, + routerUpgrade, + serviceWorker, + upgrade, + upgradeStatic +}; diff --git a/integration/typings_test_ts32/package.json b/integration/typings_test_ts32/package.json new file mode 100644 index 0000000000..4368880ee9 --- /dev/null +++ b/integration/typings_test_ts32/package.json @@ -0,0 +1,31 @@ +{ + "name": "angular-integration", + "description": "Assert that users with TypeScript 3.2 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/elements": "file:../../dist/packages-dist/elements", + "@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": "3.2.x", + "zone.js": "file:../../node_modules/zone.js" + }, + "scripts": { + "test": "tsc" + } +} \ No newline at end of file diff --git a/integration/typings_test_ts32/tsconfig.json b/integration/typings_test_ts32/tsconfig.json new file mode 100644 index 0000000000..4777e1cfa0 --- /dev/null +++ b/integration/typings_test_ts32/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "module": "commonjs", + "moduleResolution": "node", + "outDir": "../../dist/typings_test_ts31/", + "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 8fb88d06fe..29e3d7766b 100644 --- a/package.json +++ b/package.json @@ -76,9 +76,9 @@ "shelljs": "^0.8.1", "source-map": "^0.6.1", "source-map-support": "0.5.9", - "tsickle": "0.33.1", - "tslib": "^1.7.1", - "typescript": "~3.1.1", + "tsickle": "0.34.0", + "tslib": "^1.9.0", + "typescript": "~3.2.2", "xhr2": "0.1.4", "yargs": "9.0.1", "zone.js": "^0.8.26" diff --git a/packages/bazel/package.json b/packages/bazel/package.json index 86fdfa91ed..80fa0431fe 100644 --- a/packages/bazel/package.json +++ b/packages/bazel/package.json @@ -24,7 +24,7 @@ }, "peerDependencies": { "@angular/compiler-cli": "0.0.0-PLACEHOLDER", - "typescript": ">=3.1.1 <3.2" + "typescript": ">=3.1.1 <3.3" }, "repository": { "type": "git", @@ -38,4 +38,4 @@ "scripts": { "postinstall": "node ./check_version.js" } -} +} \ No newline at end of file diff --git a/packages/compiler-cli/package.json b/packages/compiler-cli/package.json index 1bb952413f..943f56264a 100644 --- a/packages/compiler-cli/package.json +++ b/packages/compiler-cli/package.json @@ -24,10 +24,10 @@ }, "peerDependencies": { "@angular/compiler": "0.0.0-PLACEHOLDER", - "typescript": ">=3.1.1 <3.2" + "typescript": ">=3.1.1 <3.3" }, - "engines" : { - "node" : ">=8.0" + "engines": { + "node": ">=8.0" }, "repository": { "type": "git", @@ -49,4 +49,4 @@ "ng-update": { "packageGroup": "NG_UPDATE_PACKAGE_GROUP" } -} +} \ No newline at end of file diff --git a/packages/compiler-cli/src/ngcc/src/packages/transformer.ts b/packages/compiler-cli/src/ngcc/src/packages/transformer.ts index e324e43524..1c4233fe74 100644 --- a/packages/compiler-cli/src/ngcc/src/packages/transformer.ts +++ b/packages/compiler-cli/src/ngcc/src/packages/transformer.ts @@ -8,11 +8,12 @@ import {dirname} from 'canonical-path'; import {existsSync, writeFileSync} from 'fs'; import {mkdir, mv} from 'shelljs'; +import * as ts from 'typescript'; -import {DecorationAnalyzer} from '../analysis/decoration_analyzer'; +import {CompiledFile, DecorationAnalyzer} from '../analysis/decoration_analyzer'; import {NgccReferencesRegistry} from '../analysis/ngcc_references_registry'; -import {PrivateDeclarationsAnalyzer} from '../analysis/private_declarations_analyzer'; -import {SwitchMarkerAnalyzer} from '../analysis/switch_marker_analyzer'; +import {ExportInfo, PrivateDeclarationsAnalyzer} from '../analysis/private_declarations_analyzer'; +import {SwitchMarkerAnalyses, SwitchMarkerAnalyzer} from '../analysis/switch_marker_analyzer'; import {Esm2015ReflectionHost} from '../host/esm2015_host'; import {Esm5ReflectionHost} from '../host/esm5_host'; import {NgccReflectionHost} from '../host/ngcc_host'; @@ -23,6 +24,7 @@ import {FileInfo, Renderer} from '../rendering/renderer'; import {EntryPoint} from './entry_point'; import {EntryPointBundle} from './entry_point_bundle'; + /** * A Package is stored in a directory on disk and that directory can contain one or more package * formats - e.g. fesm2015, UMD, etc. Additionally, each package provides typings (`.d.ts` files). @@ -96,7 +98,8 @@ export class Transformer { } } - analyzeProgram(reflectionHost: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle) { + analyzeProgram(reflectionHost: NgccReflectionHost, isCore: boolean, bundle: EntryPointBundle): + ProgramAnalyses { const typeChecker = bundle.src.program.getTypeChecker(); const referencesRegistry = new NgccReferencesRegistry(reflectionHost); const decorationAnalyzer = new DecorationAnalyzer( @@ -120,3 +123,10 @@ export class Transformer { writeFileSync(file.path, file.contents, 'utf8'); } } + + +interface ProgramAnalyses { + decorationAnalyses: Map; + switchMarkerAnalyses: SwitchMarkerAnalyses; + privateDeclarationsAnalyses: ExportInfo[]; +} diff --git a/packages/compiler-cli/src/transformers/program.ts b/packages/compiler-cli/src/transformers/program.ts index 140420e9af..85574b48a3 100644 --- a/packages/compiler-cli/src/transformers/program.ts +++ b/packages/compiler-cli/src/transformers/program.ts @@ -79,7 +79,7 @@ const MIN_TS_VERSION = '3.1.1'; * ∀ supported typescript version v, v < MAX_TS_VERSION * MAX_TS_VERSION is not considered as a supported TypeScript version */ -const MAX_TS_VERSION = '3.2.0'; +const MAX_TS_VERSION = '3.3.0'; class AngularCompilerProgram implements Program { private rootNames: string[]; diff --git a/packages/language-service/src/ts_plugin.ts b/packages/language-service/src/ts_plugin.ts index e021355fe9..d3300c39e1 100644 --- a/packages/language-service/src/ts_plugin.ts +++ b/packages/language-service/src/ts_plugin.ts @@ -275,7 +275,7 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS }; proxy.getDefinitionAtPosition = function( - fileName: string, position: number): ts.DefinitionInfo[] { + fileName: string, position: number): ReadonlyArray { let base = oldLS.getDefinitionAtPosition(fileName, position); if (base && base.length) { return base; @@ -283,10 +283,12 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS return tryOperation('get definition', () => { const ours = ls.getDefinitionAt(fileName, position); + let combined; + if (ours && ours.length) { - base = base || []; + combined = base && base.concat([]) || []; for (const loc of ours) { - base.push({ + combined.push({ fileName: loc.fileName, textSpan: {start: loc.span.start, length: loc.span.end - loc.span.start}, name: '', @@ -296,8 +298,10 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS containerKind: 'file' as any, }); } + } else { + combined = base; } - return base; + return combined; }) || []; }; diff --git a/tools/ts-api-guardian/package.json b/tools/ts-api-guardian/package.json index be2bcdec51..563d4426f2 100644 --- a/tools/ts-api-guardian/package.json +++ b/tools/ts-api-guardian/package.json @@ -11,7 +11,7 @@ "test": "test" }, "peerDependencies": { - "typescript": "~3.1.1" + "typescript": "~3.2.2" }, "dependencies": { "chalk": "^2.3.1", @@ -27,7 +27,7 @@ "chai": "^4.1.2", "jasmine": "^3.1.0", "source-map-support": "^0.5.9", - "typescript": "~3.1.1" + "typescript": "~3.2.2" }, "repository": {}, "keywords": [ @@ -45,4 +45,4 @@ "url": "https://github.com/angular/angular/issues" }, "homepage": "https://github.com/angular/angular/tools/ts-api-guardian" -} +} \ No newline at end of file diff --git a/tools/ts-api-guardian/yarn.lock b/tools/ts-api-guardian/yarn.lock index 32591fb986..1393229774 100644 --- a/tools/ts-api-guardian/yarn.lock +++ b/tools/ts-api-guardian/yarn.lock @@ -224,10 +224,10 @@ type-detect@^4.0.0: resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g== -typescript@~3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.1.1.tgz#3362ba9dd1e482ebb2355b02dfe8bcd19a2c7c96" - integrity sha512-Veu0w4dTc/9wlWNf2jeRInNodKlcdLgemvPsrNpfu5Pq39sgfFjvIIgTsvUHCoLBnMhPoUA+tFxsXjU6VexVRQ== +typescript@~3.2.2: + version "3.2.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.2.tgz#fe8101c46aa123f8353523ebdcf5730c2ae493e5" + integrity sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg== wrappy@1: version "1.0.2" diff --git a/yarn.lock b/yarn.lock index 5635d0f6b2..9fb0ee7b01 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8193,10 +8193,10 @@ trim-off-newlines@^1.0.0: resolved "https://registry.yarnpkg.com/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz#9f9ba9d9efa8764c387698bcbfeb2c848f11adb3" integrity sha1-n5up2e+odkw4dpi8v+sshI8RrbM= -tsickle@0.33.1: - version "0.33.1" - resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.33.1.tgz#eee4ebabeda3bcd8afc32cee34c822cbe3e839ec" - integrity sha512-SpW2G3PvDGs4a5sMXPlWnCWHWRviWjSlI3U0734e3fU3U39VAE0NPr8M3W1cuL/OU/YXheYipGeEwtIJ5k0NHQ== +tsickle@0.34.0: + version "0.34.0" + resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.34.0.tgz#10187fa6401a288a65efb93a60bf28b2ff95f90b" + integrity sha512-O3wCPRtL18Hc/ZBnaiKwmmjVzeCWTOTpsi0btfC7FWL3RnXpxLPxD6hoJ0QEXuSfG/0QJk+MWNjqT9N6fOyyIg== dependencies: minimist "^1.2.0" mkdirp "^0.5.1" @@ -8311,10 +8311,10 @@ typescript@3.1.6: resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.1.6.tgz#b6543a83cfc8c2befb3f4c8fba6896f5b0c9be68" integrity sha512-tDMYfVtvpb96msS1lDX9MEdHrW4yOuZ4Kdc4Him9oU796XldPYF/t2+uKoX0BBa0hXXwDlqYQbXY5Rzjzc5hBA== -typescript@~3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.1.1.tgz#3362ba9dd1e482ebb2355b02dfe8bcd19a2c7c96" - integrity sha512-Veu0w4dTc/9wlWNf2jeRInNodKlcdLgemvPsrNpfu5Pq39sgfFjvIIgTsvUHCoLBnMhPoUA+tFxsXjU6VexVRQ== +typescript@~3.2.2: + version "3.2.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.2.tgz#fe8101c46aa123f8353523ebdcf5730c2ae493e5" + integrity sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg== uglify-es@^3.3.9: version "3.3.9"