Updating according to feedback from PR

This commit is contained in:
Sheetal Nandi
2017-08-14 12:52:29 -07:00
parent 59d07dc488
commit 989508245b
7 changed files with 30 additions and 42 deletions

View File

@@ -60,7 +60,7 @@ namespace ts {
function writeFile(fileName: string, text: string, writeByteOrderMark: boolean, _onError: (message: string) => void, sourceFiles: SourceFile[]) {
outputFiles.push({ name: fileName, writeByteOrderMark, text });
if (isDetailed) {
emittedSourceFiles = concatenate(emittedSourceFiles, sourceFiles);
emittedSourceFiles = addRange(emittedSourceFiles, sourceFiles);
}
}
}
@@ -139,7 +139,7 @@ namespace ts {
function ensureProgramGraph(program: Program) {
if (!emitHandler) {
createProgramGraph(program, noop);
createProgramGraph(program, returnFalse);
}
}
@@ -457,7 +457,7 @@ namespace ts {
}
// Return array of values that needs emit
return flatMapIter(seenFileNamesMap.values());
return arrayFrom(seenFileNamesMap.values());
}
}
}

View File

@@ -1975,15 +1975,13 @@ namespace ts {
}
/**
* Expands an array of file specifications.
*
* @param fileNames The literal file names to include.
* @param include The wildcard file specifications to include.
* @param exclude The wildcard file specifications to exclude.
* Gets the file names from the provided config file specs that contain, files, include, exclude and
* other properties needed to resolve the file names
* @param spec The config file specs extracted with file names to include, wildcards to include/exclude and other details
* @param basePath The base path for any relative file specifications.
* @param options Compiler options.
* @param host The host used to resolve files and directories.
* @param errors An array for diagnostic reporting.
* @param extraFileExtensions optionaly file extra file extension information from host
*/
export function getFileNamesFromConfigSpecs(spec: ConfigFileSpecs, basePath: string, options: CompilerOptions, host: ParseConfigHost, extraFileExtensions: ReadonlyArray<JsFileExtensionInfo> = []): ExpandResult {
basePath = normalizePath(basePath);

View File

@@ -459,14 +459,12 @@ namespace ts {
return result;
}
export function flatMapIter<T>(iter: Iterator<T>): T[];
export function flatMapIter<T, U>(iter: Iterator<T>, mapfn: (x: T) => U | U[] | undefined): U[];
export function flatMapIter<T>(iter: Iterator<T>, mapfn?: (x: any) => any): any[] {
const result = [];
export function flatMapIter<T, U>(iter: Iterator<T>, mapfn: (x: T) => U | U[] | undefined): U[] {
const result: U[] = [];
while (true) {
const { value, done } = iter.next();
if (done) break;
const res = mapfn ? mapfn(value) : value;
const res = mapfn(value);
if (res) {
if (isArray(res)) {
result.push(...res);
@@ -1221,7 +1219,10 @@ namespace ts {
}
/** Does nothing. */
export function noop(): any {}
export function noop(): void { }
/** Do nothing and return false */
export function returnFalse(): false { return false; }
/** Throws an error because a function is not implemented. */
export function notImplemented(): never {
@@ -2626,25 +2627,11 @@ namespace ts {
return sourceFile.checkJsDirective ? sourceFile.checkJsDirective.enabled : compilerOptions.checkJs;
}
export interface HostForCaching {
export interface HostForCaching extends PartialSystem {
useCaseSensitiveFileNames: boolean;
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
fileExists(path: string): boolean;
directoryExists(path: string): boolean;
createDirectory(path: string): void;
getCurrentDirectory(): string;
getDirectories(path: string): string[];
readDirectory(path: string, extensions?: ReadonlyArray<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>, depth?: number): string[];
}
export interface CachedHost {
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
fileExists(path: string): boolean;
directoryExists(path: string): boolean;
createDirectory(path: string): void;
getCurrentDirectory(): string;
getDirectories(path: string): string[];
readDirectory(path: string, extensions?: ReadonlyArray<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>, depth?: number): string[];
export interface CachedHost extends PartialSystem {
addOrDeleteFileOrFolder(fileOrFolder: string): void;
clearCache(): void;
}

View File

@@ -585,7 +585,7 @@ namespace ts {
let moduleResolutionCache: ModuleResolutionCache;
let resolveModuleNamesWorker: (moduleNames: string[], containingFile: string) => ResolvedModuleFull[];
const hasInvalidatedResolution = host.hasInvalidatedResolution || noop;
const hasInvalidatedResolution = host.hasInvalidatedResolution || returnFalse;
if (host.resolveModuleNames) {
resolveModuleNamesWorker = (moduleNames, containingFile) => host.resolveModuleNames(checkAllDefined(moduleNames), containingFile).map(resolved => {
// An older host may have omitted extension, in which case we should infer it from the file extension of resolvedFileName.

View File

@@ -30,14 +30,23 @@ namespace ts {
mtime?: Date;
}
export interface System {
export interface PartialSystem {
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
fileExists(path: string): boolean;
directoryExists(path: string): boolean;
createDirectory(path: string): void;
getCurrentDirectory(): string;
getDirectories(path: string): string[];
readDirectory(path: string, extensions?: ReadonlyArray<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>, depth?: number): string[];
}
export interface System extends PartialSystem {
args: string[];
newLine: string;
useCaseSensitiveFileNames: boolean;
write(s: string): void;
readFile(path: string, encoding?: string): string | undefined;
getFileSize?(path: string): number;
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
/**
* @pollingInterval - this parameter is used in polling-based watchers and ignored in watchers that
* use native OS file watching
@@ -45,13 +54,7 @@ namespace ts {
watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher;
watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher;
resolvePath(path: string): string;
fileExists(path: string): boolean;
directoryExists(path: string): boolean;
createDirectory(path: string): void;
getExecutingFilePath(): string;
getCurrentDirectory(): string;
getDirectories(path: string): string[];
readDirectory(path: string, extensions?: ReadonlyArray<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>, depth?: number): string[];
getModifiedTime?(path: string): Date;
/**
* This should be cryptographically secure.

View File

@@ -630,7 +630,7 @@ namespace ts {
// Reload is pending, do the reload
if (!needsReload) {
const result = getFileNamesFromConfigSpecs(configFileSpecs, getDirectoryPath(configFileName), compilerOptions, host, /*extraFileExtension*/ []);
const result = getFileNamesFromConfigSpecs(configFileSpecs, getDirectoryPath(configFileName), compilerOptions, host);
if (!configFileSpecs.filesSpecs) {
reportDiagnostic(getErrorForNoInputFiles(configFileSpecs, configFileName));
}

View File

@@ -1116,7 +1116,7 @@ namespace ts {
let hostCache = new HostCache(host, getCanonicalFileName);
const rootFileNames = hostCache.getRootFileNames();
const hasInvalidatedResolution: HasInvalidatedResolution = host.hasInvalidatedResolution || noop;
const hasInvalidatedResolution: HasInvalidatedResolution = host.hasInvalidatedResolution || returnFalse;
// If the program is already up-to-date, we can reuse it
if (isProgramUptoDate(program, rootFileNames, hostCache.compilationSettings(), path => hostCache.getVersion(path), fileExists, hasInvalidatedResolution)) {