Use the results from affected file enumerator apis as Affected File result

This commit is contained in:
Sheetal Nandi 2017-11-14 16:53:07 -08:00
parent 85ce1d0398
commit e102fee363
4 changed files with 36 additions and 25 deletions

View File

@ -331,11 +331,18 @@ namespace ts {
}
}
/**
* Returns the result with affected file
*/
function toAffectedFileResult<T>(result: T, affectedFile?: SourceFile): AffectedFileResult<T> {
return { result, affectedFile };
}
/**
* Emits the next affected file, and returns the EmitResult along with source files emitted
* Returns undefined when iteration is complete
*/
function emitNextAffectedFile(programOfThisState: Program, writeFileCallback: WriteFileCallback, cancellationToken?: CancellationToken, customTransformers?: CustomTransformers): AffectedFileEmitResult | undefined {
function emitNextAffectedFile(programOfThisState: Program, writeFileCallback: WriteFileCallback, cancellationToken?: CancellationToken, customTransformers?: CustomTransformers): AffectedFileResult<EmitResult> {
const affectedFile = getNextAffectedFile(programOfThisState);
if (!affectedFile) {
// Done
@ -343,21 +350,22 @@ namespace ts {
}
else if (affectedFile === programOfThisState) {
// When whole program is affected, do emit only once (eg when --out or --outFile is specified)
return programOfThisState.emit(/*targetSourceFile*/ undefined, writeFileCallback, cancellationToken, /*emitOnlyDtsFiles*/ false, customTransformers);
return toAffectedFileResult(programOfThisState.emit(/*targetSourceFile*/ undefined, writeFileCallback, cancellationToken, /*emitOnlyDtsFiles*/ false, customTransformers));
}
// Emit the affected file
const targetSourceFile = affectedFile as SourceFile;
const result = programOfThisState.emit(targetSourceFile, writeFileCallback, cancellationToken, /*emitOnlyDtsFiles*/ false, customTransformers) as AffectedFileEmitResult;
result.affectedFile = targetSourceFile;
return result;
return toAffectedFileResult(
programOfThisState.emit(targetSourceFile, writeFileCallback, cancellationToken, /*emitOnlyDtsFiles*/ false, customTransformers),
targetSourceFile
);
}
/**
* Return the semantic diagnostics for the next affected file or undefined if iteration is complete
* If provided ignoreSourceFile would be called before getting the diagnostics and would ignore the sourceFile if the returned value was true
*/
function getSemanticDiagnosticsOfNextAffectedFile(programOfThisState: Program, cancellationToken?: CancellationToken, ignoreSourceFile?: (sourceFile: SourceFile) => boolean): ReadonlyArray<Diagnostic> {
function getSemanticDiagnosticsOfNextAffectedFile(programOfThisState: Program, cancellationToken?: CancellationToken, ignoreSourceFile?: (sourceFile: SourceFile) => boolean): AffectedFileResult<ReadonlyArray<Diagnostic>> {
while (true) {
const affectedFile = getNextAffectedFile(programOfThisState);
if (!affectedFile) {
@ -366,7 +374,7 @@ namespace ts {
}
else if (affectedFile === programOfThisState) {
// When whole program is affected, get all semantic diagnostics (eg when --out or --outFile is specified)
return programOfThisState.getSemanticDiagnostics(/*targetSourceFile*/ undefined, cancellationToken);
return toAffectedFileResult(programOfThisState.getSemanticDiagnostics(/*targetSourceFile*/ undefined, cancellationToken));
}
// Get diagnostics for the affected file if its not ignored
@ -376,7 +384,10 @@ namespace ts {
continue;
}
return getSemanticDiagnosticsOfFile(programOfThisState, targetSourceFile, cancellationToken);
return toAffectedFileResult(
getSemanticDiagnosticsOfFile(programOfThisState, targetSourceFile, cancellationToken),
targetSourceFile
);
}
}
@ -682,9 +693,7 @@ namespace ts {
text: string;
}
export interface AffectedFileEmitResult extends EmitResult {
affectedFile?: SourceFile;
}
export type AffectedFileResult<T> = { result: T; affectedFile?: SourceFile; } | undefined;
export interface BuilderOptions {
getCanonicalFileName: (fileName: string) => string;
@ -714,7 +723,7 @@ namespace ts {
* Gets the semantic diagnostics from the program for the next affected file and caches it
* Returns undefined if the iteration is complete
*/
getSemanticDiagnosticsOfNextAffectedFile(programOfThisState: Program, cancellationToken?: CancellationToken, ignoreSourceFile?: (sourceFile: SourceFile) => boolean): ReadonlyArray<Diagnostic>;
getSemanticDiagnosticsOfNextAffectedFile(programOfThisState: Program, cancellationToken?: CancellationToken, ignoreSourceFile?: (sourceFile: SourceFile) => boolean): AffectedFileResult<ReadonlyArray<Diagnostic>>;
/**
* Gets the semantic diagnostics from the program corresponding to this state of file (if provided) or whole program
@ -733,7 +742,7 @@ namespace ts {
/**
* Emits the next affected file's emit result (EmitResult and sourceFiles emitted) or returns undefined if iteration is complete
*/
emitNextAffectedFile(programOfThisState: Program, writeFileCallback: WriteFileCallback, cancellationToken?: CancellationToken, customTransformers?: CustomTransformers): AffectedFileEmitResult | undefined;
emitNextAffectedFile(programOfThisState: Program, writeFileCallback: WriteFileCallback, cancellationToken?: CancellationToken, customTransformers?: CustomTransformers): AffectedFileResult<EmitResult>;
/**
* Gets the semantic diagnostics from the program corresponding to this state of file (if provided) or whole program

View File

@ -116,11 +116,11 @@ namespace ts {
let sourceMaps: SourceMapData[];
let emitSkipped: boolean;
let affectedEmitResult: AffectedFileEmitResult;
let affectedEmitResult: AffectedFileResult<EmitResult>;
while (affectedEmitResult = builder.emitNextAffectedFile(program, writeFile)) {
emitSkipped = emitSkipped || affectedEmitResult.emitSkipped;
addRange(diagnostics, affectedEmitResult.diagnostics);
sourceMaps = addRange(sourceMaps, affectedEmitResult.sourceMaps);
emitSkipped = emitSkipped || affectedEmitResult.result.emitSkipped;
addRange(diagnostics, affectedEmitResult.result.diagnostics);
sourceMaps = addRange(sourceMaps, affectedEmitResult.result.sourceMaps);
}
if (reportSemanticDiagnostics) {

View File

@ -3771,9 +3771,10 @@ declare namespace ts {
writeByteOrderMark: boolean;
text: string;
}
interface AffectedFileEmitResult extends EmitResult {
type AffectedFileResult<T> = {
result: T;
affectedFile?: SourceFile;
}
} | undefined;
interface BuilderOptions {
getCanonicalFileName: (fileName: string) => string;
computeHash: (data: string) => string;
@ -3799,7 +3800,7 @@ declare namespace ts {
* Gets the semantic diagnostics from the program for the next affected file and caches it
* Returns undefined if the iteration is complete
*/
getSemanticDiagnosticsOfNextAffectedFile(programOfThisState: Program, cancellationToken?: CancellationToken, ignoreSourceFile?: (sourceFile: SourceFile) => boolean): ReadonlyArray<Diagnostic>;
getSemanticDiagnosticsOfNextAffectedFile(programOfThisState: Program, cancellationToken?: CancellationToken, ignoreSourceFile?: (sourceFile: SourceFile) => boolean): AffectedFileResult<ReadonlyArray<Diagnostic>>;
/**
* Gets the semantic diagnostics from the program corresponding to this state of file (if provided) or whole program
* The semantic diagnostics are cached and managed here
@ -3816,7 +3817,7 @@ declare namespace ts {
/**
* Emits the next affected file's emit result (EmitResult and sourceFiles emitted) or returns undefined if iteration is complete
*/
emitNextAffectedFile(programOfThisState: Program, writeFileCallback: WriteFileCallback, cancellationToken?: CancellationToken, customTransformers?: CustomTransformers): AffectedFileEmitResult | undefined;
emitNextAffectedFile(programOfThisState: Program, writeFileCallback: WriteFileCallback, cancellationToken?: CancellationToken, customTransformers?: CustomTransformers): AffectedFileResult<EmitResult>;
/**
* Gets the semantic diagnostics from the program corresponding to this state of file (if provided) or whole program
* The semantic diagnostics are cached and managed here

View File

@ -3718,9 +3718,10 @@ declare namespace ts {
writeByteOrderMark: boolean;
text: string;
}
interface AffectedFileEmitResult extends EmitResult {
type AffectedFileResult<T> = {
result: T;
affectedFile?: SourceFile;
}
} | undefined;
interface BuilderOptions {
getCanonicalFileName: (fileName: string) => string;
computeHash: (data: string) => string;
@ -3746,7 +3747,7 @@ declare namespace ts {
* Gets the semantic diagnostics from the program for the next affected file and caches it
* Returns undefined if the iteration is complete
*/
getSemanticDiagnosticsOfNextAffectedFile(programOfThisState: Program, cancellationToken?: CancellationToken, ignoreSourceFile?: (sourceFile: SourceFile) => boolean): ReadonlyArray<Diagnostic>;
getSemanticDiagnosticsOfNextAffectedFile(programOfThisState: Program, cancellationToken?: CancellationToken, ignoreSourceFile?: (sourceFile: SourceFile) => boolean): AffectedFileResult<ReadonlyArray<Diagnostic>>;
/**
* Gets the semantic diagnostics from the program corresponding to this state of file (if provided) or whole program
* The semantic diagnostics are cached and managed here
@ -3763,7 +3764,7 @@ declare namespace ts {
/**
* Emits the next affected file's emit result (EmitResult and sourceFiles emitted) or returns undefined if iteration is complete
*/
emitNextAffectedFile(programOfThisState: Program, writeFileCallback: WriteFileCallback, cancellationToken?: CancellationToken, customTransformers?: CustomTransformers): AffectedFileEmitResult | undefined;
emitNextAffectedFile(programOfThisState: Program, writeFileCallback: WriteFileCallback, cancellationToken?: CancellationToken, customTransformers?: CustomTransformers): AffectedFileResult<EmitResult>;
/**
* Gets the semantic diagnostics from the program corresponding to this state of file (if provided) or whole program
* The semantic diagnostics are cached and managed here