Add 'clear' helper (#17209)

This commit is contained in:
Andy 2017-07-18 11:08:44 -07:00 committed by GitHub
parent 194c2bc2ca
commit 08a57d82cd
6 changed files with 12 additions and 8 deletions

View File

@ -22266,8 +22266,8 @@ namespace ts {
// Grammar checking
checkGrammarSourceFile(node);
potentialThisCollisions.length = 0;
potentialNewTargetCollisions.length = 0;
clear(potentialThisCollisions);
clear(potentialNewTargetCollisions);
deferredNodes = [];
deferredUnusedIdentifierNodes = produceDiagnostics && noUnusedIdentifiers ? [] : undefined;
@ -22293,12 +22293,12 @@ namespace ts {
if (potentialThisCollisions.length) {
forEach(potentialThisCollisions, checkIfThisIsCapturedInEnclosingScope);
potentialThisCollisions.length = 0;
clear(potentialThisCollisions);
}
if (potentialNewTargetCollisions.length) {
forEach(potentialNewTargetCollisions, checkIfNewTargetIsCapturedInEnclosingScope);
potentialNewTargetCollisions.length = 0;
clear(potentialNewTargetCollisions);
}
links.flags |= NodeCheckFlags.TypeChecked;

View File

@ -384,6 +384,10 @@ namespace ts {
array.length = outIndex;
}
export function clear(array: {}[]): void {
array.length = 0;
}
export function map<T, U>(array: ReadonlyArray<T>, f: (x: T, i: number) => U): U[] {
let result: U[];
if (array) {

View File

@ -561,7 +561,7 @@ namespace ts.projectSystem {
}
clearOutput() {
this.output.length = 0;
clear(this.output);
}
readonly readFile = (s: string) => (<File>this.fs.get(this.toPath(s))).content;

View File

@ -223,7 +223,7 @@ namespace ts.server {
for (const reference of this.references) {
reference.removeReferencedBy(this);
}
this.references = createSortedArray<ModuleBuilderFileInfo>();
clear(this.references);
}
}

View File

@ -242,7 +242,7 @@ namespace ts.server {
// detach is unnecessary since we'll clean the list of containing projects anyways
p.removeFile(this, /*detachFromProjects*/ false);
}
this.containingProjects.length = 0;
clear(this.containingProjects);
}
getDefaultProject() {

View File

@ -1176,7 +1176,7 @@ namespace ts {
public close(): void {
// Forget all the registered shims
this._shims = [];
clear(this._shims);
this.documentRegistry = undefined;
}