build: upgrade to TypeScript 2.6 (#21144)

Fixes #20653

PR Close #21144
This commit is contained in:
Chuck Jazdzewski
2017-12-22 09:36:47 -08:00
committed by Igor Minar
parent 83c1383701
commit 83d207d0a7
45 changed files with 331 additions and 215 deletions

View File

@ -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": {

View File

@ -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.Diagnostic>):
{ts: ts.Diagnostic[], ng: Diagnostic[]} {
const ts: ts.Diagnostic[] = [];
const ng: Diagnostic[] = [];

View File

@ -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,
});

View File

@ -44,7 +44,8 @@ function createSyntheticIndexHost<H extends ts.CompilerHost>(
newHost.writeFile =
(fileName: string, data: string, writeByteOrderMark: boolean,
onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]) => {
onError: ((message: string) => void) | undefined,
sourceFiles: Readonly<ts.SourceFile>[]) => {
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<H extends ts.CompilerHost>(
}
export function createBundleIndexHost<H extends ts.CompilerHost>(
ngOptions: CompilerOptions, rootFiles: string[],
ngOptions: CompilerOptions, rootFiles: ReadonlyArray<string>,
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<H extends ts.CompilerHost>(
const content = privateEntriesToIndex(libraryIndex, metadataBundle.privates);
host = createSyntheticIndexHost(host, {name, content, metadata});
return {host, indexName: name};
}
}

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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<ts.Diagnostic>;
getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<Diagnostic>;
getTsSyntacticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken):
ts.Diagnostic[];
getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): Diagnostic[];
ReadonlyArray<ts.Diagnostic>;
getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<Diagnostic>;
getTsSemanticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken):
ts.Diagnostic[];
ReadonlyArray<ts.Diagnostic>;
getNgSemanticDiagnostics(fileName?: string, cancellationToken?: ts.CancellationToken):
Diagnostic[];
ReadonlyArray<Diagnostic>;
loadNgStructureAsync(): Promise<void>;
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<ts.Diagnostic|Diagnostic>;
export type Diagnostics = ReadonlyArray<ts.Diagnostic|Diagnostic>;
export function formatDiagnostics(diags: Diagnostics): string {
return formatDiagnosticsOrig(diags);
}
}

View File

@ -17,7 +17,7 @@ import {createMessageDiagnostic} from './transformers/util';
const TS_EXT = /\.ts$/;
export type Diagnostics = Array<ts.Diagnostic|api.Diagnostic>;
export type Diagnostics = ReadonlyArray<ts.Diagnostic|api.Diagnostic>;
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<ts.Diagnostic|api.Diagnostic> = [];
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<ts.Diagnostic|api.Diagnostic> = [];
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;
}

View File

@ -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<ts.SourceFile> = []) {
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();
}
}
}

View File

@ -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<ts.Diagnostic>;
/**
* Retrieve options diagnostics for the Angular options used to create the program.
*/
getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken): Diagnostic[];
getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<Diagnostic>;
/**
* 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<ts.Diagnostic>;
/**
* 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<Diagnostic>;
/**
* 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<ts.Diagnostic>;
/**
* 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<Diagnostic>;
/**
* Load Angular structural information asynchronously. If this method is not called then the

View File

@ -62,7 +62,7 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos
private flatModuleIndexRedirectNames = new Set<string>();
private rootDirs: string[];
private moduleResolutionCache: ts.ModuleResolutionCache;
private originalSourceFiles = new Map<string, ts.SourceFile|undefined>();
private originalSourceFiles = new Map<string, ts.SourceFile|null>();
private originalFileExistsCache = new Map<string, boolean>();
private generatedSourceFiles = new Map<string, GenSourceFile>();
private generatedCodeFor = new Map<string, string[]>();
@ -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<string>, private options: CompilerOptions,
private context: CompilerHost, private metadataProvider: MetadataProvider,
private codeGenerator: CodeGenerator,
private librarySummaries = new Map<string, LibrarySummary>()) {
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<ts.FileReference> =
(sf as any).originalReferencedFiles;
if (!originalReferencedFiles) {
originalReferencedFiles = sf.referencedFiles;
(sf as any).originalReferencedFiles = originalReferencedFiles;

View File

@ -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<string, LibrarySummary>|undefined;
private oldProgramEmittedGeneratedFiles: Map<string, GeneratedFile>|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<string>, 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<Diagnostic> {
return [...this._optionsDiagnostics, ...getNgOptionDiagnostics(this.options)];
}
getTsSyntacticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken):
ts.Diagnostic[] {
ReadonlyArray<ts.Diagnostic> {
return this.tsProgram.getSyntacticDiagnostics(sourceFile, cancellationToken);
}
getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): Diagnostic[] {
getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<Diagnostic> {
return this.structuralDiagnostics;
}
getTsSemanticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken):
ts.Diagnostic[] {
ReadonlyArray<ts.Diagnostic> {
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<Diagnostic> {
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<ts.SourceFile, ts.FileReference[]>();
const augmentedReferences = new Map<ts.SourceFile, ReadonlyArray<ts.FileReference>>();
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<Diagnostic> {
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<string>,
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<Diagnostic> {
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];
}

View File

@ -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});
};

View File

@ -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);

View File

@ -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) {

View File

@ -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);

View File

@ -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', () => {

View File

@ -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; }

View File

@ -431,14 +431,15 @@ describe('ng program', () => {
});
const host = ng.createCompilerHost({options});
const written = new Map < string, {
original: ts.SourceFile[]|undefined;
original: ReadonlyArray<ts.SourceFile>|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<ts.SourceFile>) => {
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);