Skip to content

Commit

Permalink
Making APIs as internal so that we can enable them after we have figu…
Browse files Browse the repository at this point in the history
…red out final details
  • Loading branch information
sheetalkamat committed Oct 2, 2017
1 parent 898559b commit 7f969e8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 378 deletions.
29 changes: 12 additions & 17 deletions src/compiler/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,12 @@ namespace ts {
text: string;
}

export interface ChangedProgramFiles {
/** Minimal set of list of files that require emit */
readonly filesToEmit: ReadonlyArray<string>;
/** File paths of source files changed/added/removed or affected by changed files */
readonly changedFiles: ReadonlyArray<string>;
}

/* @internal */
export interface Builder {
/**
* This is the callback when file infos in the builder are updated
* Call this to feed new program
*/
onProgramUpdateGraph(program: Program, hasInvalidatedResolution: HasInvalidatedResolution): void;
updateProgram(newProgram: Program): void;
getFilesAffectedBy(program: Program, path: Path): string[];
emitFile(program: Program, path: Path): EmitOutput;

Expand Down Expand Up @@ -97,6 +91,7 @@ namespace ts {
signature: string;
}

/* @internal */
export function createBuilder(
getCanonicalFileName: (fileName: string) => string,
getEmitOutput: (program: Program, sourceFile: SourceFile, emitOnlyDtsFiles: boolean, isDetailed: boolean) => EmitOutput | EmitOutputDetailed,
Expand All @@ -110,15 +105,15 @@ namespace ts {
const changedFileNames = createMap<string>();
let emitHandler: EmitHandler;
return {
onProgramUpdateGraph,
updateProgram,
getFilesAffectedBy,
emitFile,
emitChangedFiles,
getSemanticDiagnostics,
clear
};

function createProgramGraph(program: Program, hasInvalidatedResolution: HasInvalidatedResolution) {
function createProgramGraph(program: Program) {
const currentIsModuleEmit = program.getCompilerOptions().module !== ModuleKind.None;
if (isModuleEmit !== currentIsModuleEmit) {
isModuleEmit = currentIsModuleEmit;
Expand All @@ -135,7 +130,7 @@ namespace ts {
// Remove existing file info
onDeleteValue: removeExistingFileInfo,
// We will update in place instead of deleting existing value and adding new one
onExistingValue: (existingInfo, sourceFile) => updateExistingFileInfo(program, existingInfo, sourceFile, hasInvalidatedResolution)
onExistingValue: (existingInfo, sourceFile) => updateExistingFileInfo(program, existingInfo, sourceFile)
}
);
}
Expand All @@ -157,27 +152,27 @@ namespace ts {
emitHandler.onRemoveSourceFile(path);
}

function updateExistingFileInfo(program: Program, existingInfo: FileInfo, sourceFile: SourceFile, hasInvalidatedResolution: HasInvalidatedResolution) {
function updateExistingFileInfo(program: Program, existingInfo: FileInfo, sourceFile: SourceFile) {
if (existingInfo.version !== sourceFile.version) {
registerChangedFile(sourceFile.path, sourceFile.fileName);
existingInfo.version = sourceFile.version;
emitHandler.onUpdateSourceFile(program, sourceFile);
}
else if (hasInvalidatedResolution(sourceFile.path) &&
else if (program.hasInvalidatedResolution(sourceFile.path) &&
emitHandler.onUpdateSourceFileWithSameVersion(program, sourceFile)) {
registerChangedFile(sourceFile.path, sourceFile.fileName);
}
}

function ensureProgramGraph(program: Program) {
if (!emitHandler) {
createProgramGraph(program, returnFalse);
createProgramGraph(program);
}
}

function onProgramUpdateGraph(program: Program, hasInvalidatedResolution: HasInvalidatedResolution) {
function updateProgram(newProgram: Program) {
if (emitHandler) {
createProgramGraph(program, hasInvalidatedResolution);
createProgramGraph(newProgram);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ namespace ts {
getSourceFileFromReference,
sourceFileToPackageName,
redirectTargetsSet,
hasInvalidatedResolution
};

verifyCompilerOptions();
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2525,6 +2525,8 @@ namespace ts {
/* @internal */ sourceFileToPackageName: Map<string>;
/** Set of all source files that some other source file redirects to. */
/* @internal */ redirectTargetsSet: Map<true>;
/** Returns true when file in the program had invalidated resolution at the time of program creation. */
hasInvalidatedResolution: HasInvalidatedResolution;
}

/* @internal */
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/// <reference path="builder.ts" />
/// <reference path="resolutionCache.ts"/>

/* @internal */
namespace ts {
export type DiagnosticReporter = (diagnostic: Diagnostic) => void;
export type ParseConfigFile = (configFileName: string, optionsToExtend: CompilerOptions, system: DirectoryStructureHost, reportDiagnostic: DiagnosticReporter, reportWatchDiagnostic: DiagnosticReporter) => ParsedCommandLine;
Expand Down Expand Up @@ -341,7 +342,7 @@ namespace ts {
compilerHost.hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames;
program = createProgram(rootFileNames, compilerOptions, compilerHost, program);
resolutionCache.finishCachingPerDirectoryResolution();
builder.onProgramUpdateGraph(program, hasInvalidatedResolution);
builder.updateProgram(program);

// Update watches
updateMissingFilePathsWatch(program, missingFilesMap || (missingFilesMap = createMap()), watchMissingFilePath);
Expand Down
Loading

0 comments on commit 7f969e8

Please sign in to comment.