diff --git a/src/compiler/core.ts b/src/compiler/core.ts index f7ea05836701e..4f34de95a526d 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -361,11 +361,11 @@ namespace ts { return false; } - export function filterMutate(array: T[], f: (x: T) => boolean): void { + export function filterMutate(array: T[], f: (x: T, i: number, array: T[]) => boolean): void { let outIndex = 0; - for (const item of array) { - if (f(item)) { - array[outIndex] = item; + for (let i = 0; i < array.length; i++) { + if (f(array[i], i, array)) { + array[outIndex] = array[i]; outIndex++; } } diff --git a/src/server/project.ts b/src/server/project.ts index 524b6c4d28d3d..ae4dfb1f5c97a 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -494,7 +494,7 @@ namespace ts.server { this.projectStateVersion++; } - private extractUnresolvedImportsFromSourceFile(file: SourceFile, result: string[]) { + private extractUnresolvedImportsFromSourceFile(file: SourceFile, result: Push) { const cached = this.cachedUnresolvedImportsPerFile.get(file.path); if (cached) { // found cached result - use it and return @@ -554,7 +554,7 @@ namespace ts.server { for (const sourceFile of this.program.getSourceFiles()) { this.extractUnresolvedImportsFromSourceFile(sourceFile, result); } - this.lastCachedUnresolvedImportsList = toSortedArray(result); + this.lastCachedUnresolvedImportsList = toDeduplicatedSortedArray(result); } unresolvedImports = this.lastCachedUnresolvedImportsList; diff --git a/src/server/utilities.ts b/src/server/utilities.ts index fc88f11408a93..5efb20d074fae 100644 --- a/src/server/utilities.ts +++ b/src/server/utilities.ts @@ -262,6 +262,15 @@ namespace ts.server { return arr as SortedArray; } + export function toDeduplicatedSortedArray(arr: string[]): SortedArray { + arr.sort(); + filterMutate(arr, isNonDuplicateInSortedArray); + return arr as SortedArray; + } + function isNonDuplicateInSortedArray(value: T, index: number, array: T[]) { + return index === 0 || value !== array[index - 1]; + } + export function enumerateInsertsAndDeletes(newItems: SortedReadonlyArray, oldItems: SortedReadonlyArray, inserted: (newItem: T) => void, deleted: (oldItem: T) => void, compare?: Comparer) { compare = compare || compareValues; let newIndex = 0; diff --git a/src/services/jsTyping.ts b/src/services/jsTyping.ts index 4de7bb3191d10..5e7b7d424f894 100644 --- a/src/services/jsTyping.ts +++ b/src/services/jsTyping.ts @@ -35,7 +35,7 @@ namespace ts.JsTyping { "crypto", "stream", "util", "assert", "tty", "domain", "constants", "process", "v8", "timers", "console"]; - const nodeCoreModules = arrayToMap(nodeCoreModuleList, x => x); + const nodeCoreModules = arrayToSet(nodeCoreModuleList); /** * A map of loose file names to library names that we are confident require typings