mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 20:37:00 -05:00
Deduplicate unresolvedImports (#17248)
* Deduplicate unresolvedImports * Add `isNonDuplicateInSortedArray` helper
This commit is contained in:
@@ -361,11 +361,11 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function filterMutate<T>(array: T[], f: (x: T) => boolean): void {
|
||||
export function filterMutate<T>(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++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -495,7 +495,7 @@ namespace ts.server {
|
||||
this.projectStateVersion++;
|
||||
}
|
||||
|
||||
private extractUnresolvedImportsFromSourceFile(file: SourceFile, result: string[]) {
|
||||
private extractUnresolvedImportsFromSourceFile(file: SourceFile, result: Push<string>) {
|
||||
const cached = this.cachedUnresolvedImportsPerFile.get(file.path);
|
||||
if (cached) {
|
||||
// found cached result - use it and return
|
||||
@@ -555,7 +555,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;
|
||||
|
||||
|
||||
@@ -262,6 +262,15 @@ namespace ts.server {
|
||||
return arr as SortedArray<T>;
|
||||
}
|
||||
|
||||
export function toDeduplicatedSortedArray(arr: string[]): SortedArray<string> {
|
||||
arr.sort();
|
||||
filterMutate(arr, isNonDuplicateInSortedArray);
|
||||
return arr as SortedArray<string>;
|
||||
}
|
||||
function isNonDuplicateInSortedArray<T>(value: T, index: number, array: T[]) {
|
||||
return index === 0 || value !== array[index - 1];
|
||||
}
|
||||
|
||||
export function enumerateInsertsAndDeletes<T>(newItems: SortedReadonlyArray<T>, oldItems: SortedReadonlyArray<T>, inserted: (newItem: T) => void, deleted: (oldItem: T) => void, compare?: Comparer<T>) {
|
||||
compare = compare || compareValues;
|
||||
let newIndex = 0;
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace ts.JsTyping {
|
||||
"crypto", "stream", "util", "assert", "tty", "domain",
|
||||
"constants", "process", "v8", "timers", "console"];
|
||||
|
||||
const nodeCoreModules = arrayToMap(<string[]>nodeCoreModuleList, x => x);
|
||||
const nodeCoreModules = arrayToSet(nodeCoreModuleList);
|
||||
|
||||
/**
|
||||
* A map of loose file names to library names that we are confident require typings
|
||||
|
||||
Reference in New Issue
Block a user