Address code review at 5127

This commit is contained in:
zhengbli 2015-10-14 21:36:35 -07:00
parent d703e09227
commit 3e37b3158b
5 changed files with 12 additions and 19 deletions

View file

@ -844,9 +844,9 @@ namespace ts {
export function copyListRemovingItem<T>(item: T, list: T[]) {
let copiedList: T[] = [];
for (var i = 0, len = list.length; i < len; i++) {
if (list[i] !== item) {
copiedList.push(list[i]);
for (let e of list) {
if (e !== item) {
copiedList.push(e);
}
}
return copiedList;

View file

@ -407,7 +407,7 @@ namespace ts {
// (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643)
return _fs.watch(
path,
{ persisten: true, recursive: !!recursive },
{ persistent: true, recursive: !!recursive },
(eventName: string, relativeFileName: string) => {
// In watchDirectory we only care about adding and removing files (when event name is
// "rename"); changes made within files are handled by corresponding fileWatchers (when

View file

@ -360,7 +360,7 @@ namespace ts {
let newFileNames = ts.map(parsedCommandLine.fileNames, compilerHost.getCanonicalFileName);
let canonicalRootFileNames = ts.map(rootFileNames, compilerHost.getCanonicalFileName);
if (!arrayStructurallyIsEqualTo(newFileNames, canonicalRootFileNames)) {
if (!arrayIsEqualTo(newFileNames, canonicalRootFileNames, /*comparer*/ undefined, /*sortBeforeComparison*/ true)) {
setCachedProgram(undefined);
startTimerForRecompilation();
}

View file

@ -82,7 +82,7 @@ namespace ts {
return node.end - node.pos;
}
export function arrayIsEqualTo<T>(arr1: T[], arr2: T[], comparer?: (a: T, b: T) => boolean): boolean {
export function arrayIsEqualTo<T>(arr1: T[], arr2: T[], comparer?: (a: T, b: T) => boolean, sortBeforeComparison = false): boolean {
if (!arr1 || !arr2) {
return arr1 === arr2;
}
@ -91,6 +91,11 @@ namespace ts {
return false;
}
if (sortBeforeComparison) {
arr1.sort();
arr2.sort();
}
for (let i = 0; i < arr1.length; ++i) {
let equals = comparer ? comparer(arr1[i], arr2[i]) : arr1[i] === arr2[i];
if (!equals) {
@ -2414,16 +2419,4 @@ namespace ts {
}
}
}
export function arrayStructurallyIsEqualTo<T>(array1: Array<T>, array2: Array<T>): boolean {
if (!array1 || !array2) {
return false;
}
if (array1.length !== array2.length) {
return false;
}
return arrayIsEqualTo(array1.sort(), array2.sort());
}
}

View file

@ -576,7 +576,7 @@ namespace ts.server {
let newRootFiles = projectOptions.files.map((f => this.getCanonicalFileName(f)));
let currentRootFiles = project.getRootFiles().map((f => this.getCanonicalFileName(f)));
if (!arrayStructurallyIsEqualTo(currentRootFiles, newRootFiles)) {
if (!arrayIsEqualTo(currentRootFiles, newRootFiles, /*comparer*/ 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.