diff --git a/src/compiler/builder.ts b/src/compiler/builder.ts index 849732f0afb..04d520cb228 100644 --- a/src/compiler/builder.ts +++ b/src/compiler/builder.ts @@ -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()); } } } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 3748dd9b9a4..ac8f1ee8f97 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -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 = []): ExpandResult { basePath = normalizePath(basePath); diff --git a/src/compiler/core.ts b/src/compiler/core.ts index c163de24466..751177c4ef8 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -459,14 +459,12 @@ namespace ts { return result; } - export function flatMapIter(iter: Iterator): T[]; - export function flatMapIter(iter: Iterator, mapfn: (x: T) => U | U[] | undefined): U[]; - export function flatMapIter(iter: Iterator, mapfn?: (x: any) => any): any[] { - const result = []; + export function flatMapIter(iter: Iterator, 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, exclude?: ReadonlyArray, include?: ReadonlyArray, 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, exclude?: ReadonlyArray, include?: ReadonlyArray, depth?: number): string[]; + export interface CachedHost extends PartialSystem { addOrDeleteFileOrFolder(fileOrFolder: string): void; clearCache(): void; } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index c642d99ff9d..2dd3e465268 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -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. diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 193997a8a86..aafb97f4131 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -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, exclude?: ReadonlyArray, include?: ReadonlyArray, 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, exclude?: ReadonlyArray, include?: ReadonlyArray, depth?: number): string[]; getModifiedTime?(path: string): Date; /** * This should be cryptographically secure. diff --git a/src/compiler/watchedProgram.ts b/src/compiler/watchedProgram.ts index ca0292fa533..5229e11ea97 100644 --- a/src/compiler/watchedProgram.ts +++ b/src/compiler/watchedProgram.ts @@ -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)); } diff --git a/src/services/services.ts b/src/services/services.ts index ba1c48b9037..b06f92344d3 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -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)) {