Skip to content

Commit a32914f

Browse files
author
Andy Hanson
committed
Combine forEachExpectedEmitFile and forEachEmittedFile
1 parent 8886cef commit a32914f

File tree

4 files changed

+12
-20
lines changed

4 files changed

+12
-20
lines changed

src/compiler/declarationEmitter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace ts {
3232

3333
export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, targetSourceFile: SourceFile): Diagnostic[] {
3434
const declarationDiagnostics = createDiagnosticCollection();
35-
forEachExpectedEmitFile(host, getDeclarationDiagnosticsFromFile, targetSourceFile);
35+
forEachEmittedFile(host, getDeclarationDiagnosticsFromFile, targetSourceFile);
3636
return declarationDiagnostics.getDiagnostics(targetSourceFile ? targetSourceFile.fileName : undefined);
3737

3838
function getDeclarationDiagnosticsFromFile({ declarationFilePath }: EmitFileNames, sources: SourceFile[], isBundledEmit: boolean) {
@@ -1788,7 +1788,7 @@ namespace ts {
17881788
}
17891789
else {
17901790
// Get the declaration file path
1791-
forEachExpectedEmitFile(host, getDeclFileName, referencedFile, emitOnlyDtsFiles);
1791+
forEachEmittedFile(host, getDeclFileName, referencedFile, emitOnlyDtsFiles);
17921792
}
17931793

17941794
if (declFileName) {

src/compiler/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ namespace ts {
7373

7474
// Emit each output file
7575
performance.mark("beforePrint");
76-
forEachEmittedFile(host, transformed, emitFile, emitOnlyDtsFiles);
76+
forEachEmittedFile(host, emitFile, transformed, emitOnlyDtsFiles);
7777
performance.measure("printTime", "beforePrint");
7878

7979
// Clean up emit nodes on parse tree

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,7 @@ namespace ts {
17071707
if (!options.noEmit && !options.suppressOutputPathCheck) {
17081708
const emitHost = getEmitHost();
17091709
const emitFilesSeen = createFileMap<boolean>(!host.useCaseSensitiveFileNames() ? key => key.toLocaleLowerCase() : undefined);
1710-
forEachExpectedEmitFile(emitHost, (emitFileNames) => {
1710+
forEachEmittedFile(emitHost, (emitFileNames) => {
17111711
verifyEmitFilePath(emitFileNames.jsFilePath, emitFilesSeen);
17121712
verifyEmitFilePath(emitFileNames.declarationFilePath, emitFilesSeen);
17131713
});

src/compiler/utilities.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,27 +2590,20 @@ namespace ts {
25902590
}
25912591

25922592
/**
2593-
* Iterates over the source files that are expected to have an emit output. This function
2594-
* is used by the legacy emitter and the declaration emitter and should not be used by
2595-
* the tree transforming emitter.
2593+
* Iterates over the source files that are expected to have an emit output.
25962594
*
25972595
* @param host An EmitHost.
25982596
* @param action The action to execute.
2599-
* @param targetSourceFile An optional target source file to emit.
2597+
* @param sourceFilesOrTargetSourceFile
2598+
* If an array, the full list of source files to emit.
2599+
* Else, calls `getSourceFilesToEmit` with the (optional) target source file to determine the list of source files to emit.
26002600
*/
2601-
export function forEachExpectedEmitFile(host: EmitHost,
2602-
action: (emitFileNames: EmitFileNames, sourceFiles: SourceFile[], isBundledEmit: boolean, emitOnlyDtsFiles: boolean) => void,
2603-
targetSourceFile?: SourceFile,
2601+
export function forEachEmittedFile(
2602+
host: EmitHost, action: (emitFileNames: EmitFileNames, sourceFiles: SourceFile[], isBundledEmit: boolean, emitOnlyDtsFiles: boolean) => void,
2603+
sourceFilesOrTargetSourceFile?: SourceFile[] | SourceFile,
26042604
emitOnlyDtsFiles?: boolean) {
2605-
forEachEmittedFile(host, getSourceFilesToEmit(host, targetSourceFile), action, emitOnlyDtsFiles);
2606-
}
26072605

2608-
/**
2609-
* Iterates over each source file to emit.
2610-
*/
2611-
export function forEachEmittedFile(host: EmitHost, sourceFiles: SourceFile[],
2612-
action: (emitFileNames: EmitFileNames, sourceFiles: SourceFile[], isBundledEmit: boolean, emitOnlyDtsFiles: boolean) => void,
2613-
emitOnlyDtsFiles?: boolean) {
2606+
const sourceFiles = isArray(sourceFilesOrTargetSourceFile) ? sourceFilesOrTargetSourceFile : getSourceFilesToEmit(host, sourceFilesOrTargetSourceFile);
26142607
const options = host.getCompilerOptions();
26152608
if (options.outFile || options.out) {
26162609
if (sourceFiles.length) {
@@ -2622,7 +2615,6 @@ namespace ts {
26222615
}
26232616
else {
26242617
for (const sourceFile of sourceFiles) {
2625-
const options = host.getCompilerOptions();
26262618
const jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, getOutputExtension(sourceFile, options));
26272619
const sourceMapFilePath = getSourceMapFilePath(jsFilePath, options);
26282620
const declarationFilePath = !isSourceFileJavaScript(sourceFile) && (emitOnlyDtsFiles || options.declaration) ? getDeclarationEmitOutputFilePath(sourceFile, host) : undefined;

0 commit comments

Comments
 (0)