feat: add support for TypeScript 3.3 (and drop older versions) (#29004)

https://blogs.msdn.microsoft.com/typescript/2019/01/31/announcing-typescript-3-3/

BREAKING CHANGE: TypeScript 3.1 and 3.2 are no longer supported.

Please update your TypeScript version to 3.3

PR Close #29004
This commit is contained in:
Igor Minar
2019-02-02 01:02:16 -08:00
committed by Kara Erickson
parent 9a7f5601fa
commit 75748d6044
21 changed files with 59 additions and 167 deletions

View File

@ -24,7 +24,7 @@
},
"peerDependencies": {
"@angular/compiler": "0.0.0-PLACEHOLDER",
"typescript": ">=3.1.1 <3.3"
"typescript": ">=3.3.3333 <3.4"
},
"engines": {
"node": ">=8.0"

View File

@ -44,6 +44,9 @@ export class GeneratedShimsHostWrapper implements ts.CompilerHost {
if (delegate.directoryExists !== undefined) {
this.directoryExists = (directoryName: string) => delegate.directoryExists !(directoryName);
}
if (delegate.getDirectories !== undefined) {
this.getDirectories = (path: string) => delegate.getDirectories !(path);
}
}
resolveTypeReferenceDirectives?:
@ -84,7 +87,7 @@ export class GeneratedShimsHostWrapper implements ts.CompilerHost {
getCurrentDirectory(): string { return this.delegate.getCurrentDirectory(); }
getDirectories(path: string): string[] { return this.delegate.getDirectories(path); }
getDirectories?: (path: string) => string[];
getCanonicalFileName(fileName: string): string {
return this.delegate.getCanonicalFileName(fileName);

View File

@ -41,6 +41,9 @@ export class SyntheticFilesCompilerHost implements PluginCompilerHost {
this.syntheticFiles.set(generated.fileName, generated);
}
}
if (delegate.getDirectories !== undefined) {
this.getDirectories = (path: string) => delegate.getDirectories !(path);
}
}
fileExists(filePath: string): boolean {
@ -88,7 +91,7 @@ export class SyntheticFilesCompilerHost implements PluginCompilerHost {
getNewLine(): string { return this.delegate.getNewLine(); }
getDirectories(path: string) { return this.delegate.getDirectories(path); }
getDirectories?: (path: string) => string[];
readFile(fileName: string): string|undefined { return this.delegate.readFile(fileName); }

View File

@ -34,6 +34,10 @@ export class TypeCheckProgramHost implements ts.CompilerHost {
// as efficient as possible. To support both of these requirements, all of the program's
// source files are loaded into the cache up front.
program.getSourceFiles().forEach(file => { this.sfCache.set(file.fileName, file); });
if (delegate.getDirectories !== undefined) {
this.getDirectories = (path: string) => delegate.getDirectories !(path);
}
}
getSourceFile(
@ -77,7 +81,7 @@ export class TypeCheckProgramHost implements ts.CompilerHost {
getCurrentDirectory(): string { return this.delegate.getCurrentDirectory(); }
getDirectories(path: string): string[] { return this.delegate.getDirectories(path); }
getDirectories?: (path: string) => string[];
getCanonicalFileName(fileName: string): string {
return this.delegate.getCanonicalFileName(fileName);

View File

@ -72,14 +72,14 @@ const defaultEmitCallback: TsEmitCallback =
* Minimum supported TypeScript version
* ∀ supported typescript version v, v >= MIN_TS_VERSION
*/
const MIN_TS_VERSION = '3.1.1';
const MIN_TS_VERSION = '3.3.3333';
/**
* Supremum of supported TypeScript versions
* ∀ supported typescript version v, v < MAX_TS_VERSION
* MAX_TS_VERSION is not considered as a supported TypeScript version
*/
const MAX_TS_VERSION = '3.3.0';
const MAX_TS_VERSION = '3.4.0';
class AngularCompilerProgram implements Program {
private rootNames: string[];
@ -463,14 +463,14 @@ class AngularCompilerProgram implements Program {
// Match behavior of tsc: only produce emit diagnostics if it would block
// emit. If noEmitOnError is false, the emit will happen in spite of any
// errors, so we should not report them.
if (this.options.noEmitOnError === true) {
if (emitResult && this.options.noEmitOnError === true) {
// translate the diagnostics in the emitResult as well.
const translatedEmitDiags = translateDiagnostics(this.hostAdapter, emitResult.diagnostics);
emitResult.diagnostics = translatedEmitDiags.ts.concat(
this.structuralDiagnostics.concat(translatedEmitDiags.ng).map(ngToTsDiagnostic));
}
if (!outSrcMapping.length) {
if (emitResult && !outSrcMapping.length) {
// if no files were emitted by TypeScript, also don't emit .json files
emitResult.diagnostics =
emitResult.diagnostics.concat([createMessageDiagnostic(`Emitted no files.`)]);
@ -506,7 +506,7 @@ class AngularCompilerProgram implements Program {
});
}
const emitEnd = Date.now();
if (this.options.diagnostics) {
if (emitResult && this.options.diagnostics) {
emitResult.diagnostics = emitResult.diagnostics.concat([createMessageDiagnostic([
`Emitted in ${emitEnd - emitStart}ms`,
`- ${emittedUserTsCount} user ts files`,

View File

@ -2803,7 +2803,7 @@ describe('ngtsc behavioral tests', () => {
const fileoverview = `
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
`;
expect(trim(jsContents).startsWith(trim(fileoverview))).toBeTruthy();
@ -2820,7 +2820,7 @@ describe('ngtsc behavioral tests', () => {
const fileoverview = `
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
`;
expect(trim(jsContents).startsWith(trim(fileoverview))).toBeTruthy();
@ -2852,7 +2852,7 @@ describe('ngtsc behavioral tests', () => {
* @fileoverview Some Comp overview
* @modName {some_comp}
*
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
`;
expect(trim(jsContents).startsWith(trim(fileoverview))).toBeTruthy();
@ -2880,7 +2880,7 @@ describe('ngtsc behavioral tests', () => {
* @fileoverview Some Comp overview
* @modName {some_comp}
*
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
`;
expect(trim(jsContents).startsWith(trim(fileoverview))).toBeTruthy();