From 08a57d82cd4395ec3528f4adcd73c7d5258f7504 Mon Sep 17 00:00:00 2001 From: Andy Date: Tue, 18 Jul 2017 11:08:44 -0700 Subject: [PATCH] Add 'clear' helper (#17209) --- src/compiler/checker.ts | 8 ++++---- src/compiler/core.ts | 4 ++++ src/harness/unittests/tsserverProjectSystem.ts | 2 +- src/server/builder.ts | 2 +- src/server/scriptInfo.ts | 2 +- src/services/shims.ts | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5d01000f23b..83f2fa179e4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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; diff --git a/src/compiler/core.ts b/src/compiler/core.ts index fa54abd4038..cecf88f42ce 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -384,6 +384,10 @@ namespace ts { array.length = outIndex; } + export function clear(array: {}[]): void { + array.length = 0; + } + export function map(array: ReadonlyArray, f: (x: T, i: number) => U): U[] { let result: U[]; if (array) { diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 3dde03a092b..f11900aea11 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -561,7 +561,7 @@ namespace ts.projectSystem { } clearOutput() { - this.output.length = 0; + clear(this.output); } readonly readFile = (s: string) => (this.fs.get(this.toPath(s))).content; diff --git a/src/server/builder.ts b/src/server/builder.ts index bc86780fbbe..8a10682b4cc 100644 --- a/src/server/builder.ts +++ b/src/server/builder.ts @@ -223,7 +223,7 @@ namespace ts.server { for (const reference of this.references) { reference.removeReferencedBy(this); } - this.references = createSortedArray(); + clear(this.references); } } diff --git a/src/server/scriptInfo.ts b/src/server/scriptInfo.ts index 52107359a32..b611bcb70e0 100644 --- a/src/server/scriptInfo.ts +++ b/src/server/scriptInfo.ts @@ -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() { diff --git a/src/services/shims.ts b/src/services/shims.ts index 03965cb5d48..e86e9053e57 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -1176,7 +1176,7 @@ namespace ts { public close(): void { // Forget all the registered shims - this._shims = []; + clear(this._shims); this.documentRegistry = undefined; }