Skip to content

Commit

Permalink
Merge pull request #31432 from microsoft/builderAPI
Browse files Browse the repository at this point in the history
Api for tsc --build and --incremental
  • Loading branch information
sheetalkamat committed Jun 5, 2019
2 parents 9da0524 + 098c900 commit 5c21fad
Show file tree
Hide file tree
Showing 23 changed files with 2,345 additions and 1,452 deletions.
24 changes: 10 additions & 14 deletions src/compiler/builder.ts
Expand Up @@ -796,6 +796,7 @@ namespace ts {
(result as SemanticDiagnosticsBuilderProgram).getSemanticDiagnosticsOfNextAffectedFile = getSemanticDiagnosticsOfNextAffectedFile;
}
else if (kind === BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram) {
(result as EmitAndSemanticDiagnosticsBuilderProgram).getSemanticDiagnosticsOfNextAffectedFile = getSemanticDiagnosticsOfNextAffectedFile;
(result as EmitAndSemanticDiagnosticsBuilderProgram).emitNextAffectedFile = emitNextAffectedFile;
}
else {
Expand Down Expand Up @@ -913,6 +914,11 @@ namespace ts {
);
}

// Add file to affected file pending emit to handle for later emit time
if (kind === BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram) {
addToAffectedFilesPendingEmit(state, [(affected as SourceFile).path]);
}

// Get diagnostics for the affected file if its not ignored
if (ignoreSourceFile && ignoreSourceFile(affected as SourceFile)) {
// Get next affected file
Expand Down Expand Up @@ -951,18 +957,8 @@ namespace ts {

// When semantic builder asks for diagnostics of the whole program,
// ensure that all the affected files are handled
let affected: SourceFile | Program | undefined;
let affectedFilesPendingEmit: Path[] | undefined;
while (affected = getNextAffectedFile(state, cancellationToken, computeHash)) {
if (affected !== state.program && kind === BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram) {
(affectedFilesPendingEmit || (affectedFilesPendingEmit = [])).push((affected as SourceFile).path);
}
doneWithAffectedFile(state, affected);
}

// In case of emit builder, cache the files to be emitted
if (affectedFilesPendingEmit) {
addToAffectedFilesPendingEmit(state, affectedFilesPendingEmit);
// tslint:disable-next-line no-empty
while (getSemanticDiagnosticsOfNextAffectedFile(cancellationToken)) {
}

let diagnostics: Diagnostic[] | undefined;
Expand Down Expand Up @@ -997,7 +993,7 @@ namespace ts {
return map;
}

export function createBuildProgramUsingProgramBuildInfo(program: ProgramBuildInfo): EmitAndSemanticDiagnosticsBuilderProgram & SemanticDiagnosticsBuilderProgram {
export function createBuildProgramUsingProgramBuildInfo(program: ProgramBuildInfo): EmitAndSemanticDiagnosticsBuilderProgram {
const fileInfos = createMapFromTemplate(program.fileInfos);
const state: ReusableBuilderProgramState = {
fileInfos,
Expand Down Expand Up @@ -1181,7 +1177,7 @@ namespace ts {
* The builder that can handle the changes in program and iterate through changed file to emit the files
* The semantic diagnostics are cached per file and managed by clearing for the changed/affected files
*/
export interface EmitAndSemanticDiagnosticsBuilderProgram extends BuilderProgram {
export interface EmitAndSemanticDiagnosticsBuilderProgram extends SemanticDiagnosticsBuilderProgram {
/**
* Emits the next affected file's emit result (EmitResult and sourceFiles emitted) or returns undefined if iteration is complete
* The first of writeFile if provided, writeFile of BuilderProgramHost if provided, writeFile of compiler host
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/commandLineParser.ts
Expand Up @@ -1022,8 +1022,7 @@ namespace ts {
}
}

/* @internal */
export interface OptionsBase {
interface OptionsBase {
[option: string]: CompilerOptionsValue | undefined;
}

Expand Down
15 changes: 12 additions & 3 deletions src/compiler/emitter.ts
Expand Up @@ -284,7 +284,6 @@ namespace ts {
// Write build information if applicable
if (!buildInfoPath || targetSourceFile || emitSkipped) return;
const program = host.getProgramBuildInfo();
if (!bundle && !program) return;
if (host.isEmitBlocked(buildInfoPath) || compilerOptions.noEmit) {
emitSkipped = true;
return;
Expand Down Expand Up @@ -638,7 +637,12 @@ namespace ts {
}

/*@internal*/
export function emitUsingBuildInfo(config: ParsedCommandLine, host: EmitUsingBuildInfoHost, getCommandLine: (ref: ProjectReference) => ParsedCommandLine | undefined): EmitUsingBuildInfoResult {
export function emitUsingBuildInfo(
config: ParsedCommandLine,
host: EmitUsingBuildInfoHost,
getCommandLine: (ref: ProjectReference) => ParsedCommandLine | undefined,
customTransformers?: CustomTransformers
): EmitUsingBuildInfoResult {
const { buildInfoPath, jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath } = getOutputPathsForBundle(config.options, /*forceDtsPaths*/ false);
const buildInfoText = host.readFile(Debug.assertDefined(buildInfoPath));
if (!buildInfoText) return buildInfoPath!;
Expand Down Expand Up @@ -723,7 +727,12 @@ namespace ts {
useCaseSensitiveFileNames: () => host.useCaseSensitiveFileNames(),
getProgramBuildInfo: returnUndefined
};
emitFiles(notImplementedResolver, emitHost, /*targetSourceFile*/ undefined, getTransformers(config.options), /*emitOnlyDtsFiles*/ false);
emitFiles(
notImplementedResolver,
emitHost,
/*targetSourceFile*/ undefined,
getTransformers(config.options, customTransformers)
);
return outputFiles;
}

Expand Down

0 comments on commit 5c21fad

Please sign in to comment.