Skip to content

Commit 1b36407

Browse files
committed
Merge pull request #5263 from zhengbli/pr5127cr
Address code review of #5127
2 parents fb97e2f + 39254b5 commit 1b36407

File tree

5 files changed

+14
-24
lines changed

5 files changed

+14
-24
lines changed

src/compiler/core.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -844,9 +844,9 @@ namespace ts {
844844

845845
export function copyListRemovingItem<T>(item: T, list: T[]) {
846846
let copiedList: T[] = [];
847-
for (var i = 0, len = list.length; i < len; i++) {
848-
if (list[i] !== item) {
849-
copiedList.push(list[i]);
847+
for (let e of list) {
848+
if (e !== item) {
849+
copiedList.push(e);
850850
}
851851
}
852852
return copiedList;

src/compiler/sys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ namespace ts {
407407
// (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643)
408408
return _fs.watch(
409409
path,
410-
{ persisten: true, recursive: !!recursive },
410+
{ persistent: true, recursive: !!recursive },
411411
(eventName: string, relativeFileName: string) => {
412412
// In watchDirectory we only care about adding and removing files (when event name is
413413
// "rename"); changes made within files are handled by corresponding fileWatchers (when

src/compiler/tsc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ namespace ts {
360360
let newFileNames = ts.map(parsedCommandLine.fileNames, compilerHost.getCanonicalFileName);
361361
let canonicalRootFileNames = ts.map(rootFileNames, compilerHost.getCanonicalFileName);
362362

363-
if (!arrayStructurallyIsEqualTo(newFileNames, canonicalRootFileNames)) {
363+
// We check if the project file list has changed. If so, we just throw away the old program and start fresh.
364+
if (!arrayIsEqualTo(newFileNames && newFileNames.sort(), canonicalRootFileNames && canonicalRootFileNames.sort())) {
364365
setCachedProgram(undefined);
365366
startTimerForRecompilation();
366367
}

src/compiler/utilities.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ namespace ts {
8282
return node.end - node.pos;
8383
}
8484

85-
export function arrayIsEqualTo<T>(arr1: T[], arr2: T[], comparer?: (a: T, b: T) => boolean): boolean {
86-
if (!arr1 || !arr2) {
87-
return arr1 === arr2;
85+
export function arrayIsEqualTo<T>(array1: T[], array2: T[], equaler?: (a: T, b: T) => boolean): boolean {
86+
if (!array1 || !array2) {
87+
return array1 === array2;
8888
}
8989

90-
if (arr1.length !== arr2.length) {
90+
if (array1.length !== array2.length) {
9191
return false;
9292
}
9393

94-
for (let i = 0; i < arr1.length; ++i) {
95-
let equals = comparer ? comparer(arr1[i], arr2[i]) : arr1[i] === arr2[i];
94+
for (let i = 0; i < array1.length; ++i) {
95+
let equals = equaler ? equaler(array1[i], array2[i]) : array1[i] === array2[i];
9696
if (!equals) {
9797
return false;
9898
}
@@ -2414,16 +2414,4 @@ namespace ts {
24142414
}
24152415
}
24162416
}
2417-
2418-
export function arrayStructurallyIsEqualTo<T>(array1: Array<T>, array2: Array<T>): boolean {
2419-
if (!array1 || !array2) {
2420-
return false;
2421-
}
2422-
2423-
if (array1.length !== array2.length) {
2424-
return false;
2425-
}
2426-
2427-
return arrayIsEqualTo(array1.sort(), array2.sort());
2428-
}
24292417
}

src/server/editorServices.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,8 @@ namespace ts.server {
576576
let newRootFiles = projectOptions.files.map((f => this.getCanonicalFileName(f)));
577577
let currentRootFiles = project.getRootFiles().map((f => this.getCanonicalFileName(f)));
578578

579-
if (!arrayStructurallyIsEqualTo(currentRootFiles, newRootFiles)) {
579+
// We check if the project file list has changed. If so, we update the project.
580+
if (!arrayIsEqualTo(currentRootFiles && currentRootFiles.sort(), newRootFiles && newRootFiles.sort())) {
580581
// For configured projects, the change is made outside the tsconfig file, and
581582
// it is not likely to affect the project for other files opened by the client. We can
582583
// just update the current project.

0 commit comments

Comments
 (0)