mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 04:43:37 -05:00
Add sortBeforeComparison option back to arrayIsEqualTo
This commit is contained in:
@@ -360,7 +360,8 @@ namespace ts {
|
||||
let newFileNames = ts.map(parsedCommandLine.fileNames, compilerHost.getCanonicalFileName);
|
||||
let canonicalRootFileNames = ts.map(rootFileNames, compilerHost.getCanonicalFileName);
|
||||
|
||||
if (!arrayIsEqualTo(newFileNames.sort(), canonicalRootFileNames.sort())) {
|
||||
// We check if the project file list has changed. If so, we just throw away the old program and start fresh.
|
||||
if (!arrayIsEqualTo(newFileNames, canonicalRootFileNames, /*equaler*/ undefined, /*sortBeforeComparison*/ true)) {
|
||||
setCachedProgram(undefined);
|
||||
startTimerForRecompilation();
|
||||
}
|
||||
|
||||
@@ -82,17 +82,21 @@ namespace ts {
|
||||
return node.end - node.pos;
|
||||
}
|
||||
|
||||
export function arrayIsEqualTo<T>(arr1: T[], arr2: T[], comparer?: (a: T, b: T) => boolean): boolean {
|
||||
if (!arr1 || !arr2) {
|
||||
return arr1 === arr2;
|
||||
export function arrayIsEqualTo<T>(array1: T[], array2: T[], equaler?: (a: T, b: T) => boolean,
|
||||
sortBeforeComparison?: boolean, comparer?: (a: T, b: T) => number): boolean {
|
||||
if (!array1 || !array2) {
|
||||
return array1 === array2;
|
||||
}
|
||||
|
||||
if (arr1.length !== arr2.length) {
|
||||
if (array1.length !== array2.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < arr1.length; ++i) {
|
||||
let equals = comparer ? comparer(arr1[i], arr2[i]) : arr1[i] === arr2[i];
|
||||
let newArray1 = sortBeforeComparison ? array1.slice().sort(comparer) : array1;
|
||||
let newArray2 = sortBeforeComparison ? array2.slice().sort(comparer) : array2;
|
||||
|
||||
for (let i = 0; i < array1.length; ++i) {
|
||||
let equals = equaler ? equaler(newArray1[i], newArray2[i]) : newArray1[i] === newArray2[i];
|
||||
if (!equals) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -576,7 +576,8 @@ namespace ts.server {
|
||||
let newRootFiles = projectOptions.files.map((f => this.getCanonicalFileName(f)));
|
||||
let currentRootFiles = project.getRootFiles().map((f => this.getCanonicalFileName(f)));
|
||||
|
||||
if (!arrayIsEqualTo(currentRootFiles.sort(), newRootFiles.sort())) {
|
||||
// We check if the project file list has changed. If so, we update the project.
|
||||
if (!arrayIsEqualTo(currentRootFiles, newRootFiles, /*equaler*/ undefined, /*sortBeforeComparison*/ true)) {
|
||||
// For configured projects, the change is made outside the tsconfig file, and
|
||||
// it is not likely to affect the project for other files opened by the client. We can
|
||||
// just update the current project.
|
||||
|
||||
Reference in New Issue
Block a user