From a32914f6872b9c5764d77f77ea85c7160ff9ae28 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 23 Jan 2017 11:14:29 -0800 Subject: [PATCH] Combine `forEachExpectedEmitFile` and `forEachEmittedFile` --- src/compiler/declarationEmitter.ts | 4 ++-- src/compiler/emitter.ts | 2 +- src/compiler/program.ts | 2 +- src/compiler/utilities.ts | 24 ++++++++---------------- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 2287de179e3..46df4fed689 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -32,7 +32,7 @@ namespace ts { export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, targetSourceFile: SourceFile): Diagnostic[] { const declarationDiagnostics = createDiagnosticCollection(); - forEachExpectedEmitFile(host, getDeclarationDiagnosticsFromFile, targetSourceFile); + forEachEmittedFile(host, getDeclarationDiagnosticsFromFile, targetSourceFile); return declarationDiagnostics.getDiagnostics(targetSourceFile ? targetSourceFile.fileName : undefined); function getDeclarationDiagnosticsFromFile({ declarationFilePath }: EmitFileNames, sources: SourceFile[], isBundledEmit: boolean) { @@ -1788,7 +1788,7 @@ namespace ts { } else { // Get the declaration file path - forEachExpectedEmitFile(host, getDeclFileName, referencedFile, emitOnlyDtsFiles); + forEachEmittedFile(host, getDeclFileName, referencedFile, emitOnlyDtsFiles); } if (declFileName) { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1c4662fa587..cc006a06637 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -73,7 +73,7 @@ namespace ts { // Emit each output file performance.mark("beforePrint"); - forEachEmittedFile(host, transformed, emitFile, emitOnlyDtsFiles); + forEachEmittedFile(host, emitFile, transformed, emitOnlyDtsFiles); performance.measure("printTime", "beforePrint"); // Clean up emit nodes on parse tree diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 851e206d448..650711afc79 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1707,7 +1707,7 @@ namespace ts { if (!options.noEmit && !options.suppressOutputPathCheck) { const emitHost = getEmitHost(); const emitFilesSeen = createFileMap(!host.useCaseSensitiveFileNames() ? key => key.toLocaleLowerCase() : undefined); - forEachExpectedEmitFile(emitHost, (emitFileNames) => { + forEachEmittedFile(emitHost, (emitFileNames) => { verifyEmitFilePath(emitFileNames.jsFilePath, emitFilesSeen); verifyEmitFilePath(emitFileNames.declarationFilePath, emitFilesSeen); }); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index f59d384e490..b7cc0f0de6d 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2590,27 +2590,20 @@ namespace ts { } /** - * Iterates over the source files that are expected to have an emit output. This function - * is used by the legacy emitter and the declaration emitter and should not be used by - * the tree transforming emitter. + * Iterates over the source files that are expected to have an emit output. * * @param host An EmitHost. * @param action The action to execute. - * @param targetSourceFile An optional target source file to emit. + * @param sourceFilesOrTargetSourceFile + * If an array, the full list of source files to emit. + * Else, calls `getSourceFilesToEmit` with the (optional) target source file to determine the list of source files to emit. */ - export function forEachExpectedEmitFile(host: EmitHost, - action: (emitFileNames: EmitFileNames, sourceFiles: SourceFile[], isBundledEmit: boolean, emitOnlyDtsFiles: boolean) => void, - targetSourceFile?: SourceFile, + export function forEachEmittedFile( + host: EmitHost, action: (emitFileNames: EmitFileNames, sourceFiles: SourceFile[], isBundledEmit: boolean, emitOnlyDtsFiles: boolean) => void, + sourceFilesOrTargetSourceFile?: SourceFile[] | SourceFile, emitOnlyDtsFiles?: boolean) { - forEachEmittedFile(host, getSourceFilesToEmit(host, targetSourceFile), action, emitOnlyDtsFiles); - } - /** - * Iterates over each source file to emit. - */ - export function forEachEmittedFile(host: EmitHost, sourceFiles: SourceFile[], - action: (emitFileNames: EmitFileNames, sourceFiles: SourceFile[], isBundledEmit: boolean, emitOnlyDtsFiles: boolean) => void, - emitOnlyDtsFiles?: boolean) { + const sourceFiles = isArray(sourceFilesOrTargetSourceFile) ? sourceFilesOrTargetSourceFile : getSourceFilesToEmit(host, sourceFilesOrTargetSourceFile); const options = host.getCompilerOptions(); if (options.outFile || options.out) { if (sourceFiles.length) { @@ -2622,7 +2615,6 @@ namespace ts { } else { for (const sourceFile of sourceFiles) { - const options = host.getCompilerOptions(); const jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, getOutputExtension(sourceFile, options)); const sourceMapFilePath = getSourceMapFilePath(jsFilePath, options); const declarationFilePath = !isSourceFileJavaScript(sourceFile) && (emitOnlyDtsFiles || options.declaration) ? getDeclarationEmitOutputFilePath(sourceFile, host) : undefined;