Skip to content

Commit 08a57d8

Browse files
author
Andy
authored
Add 'clear' helper (#17209)
1 parent 194c2bc commit 08a57d8

File tree

6 files changed

+12
-8
lines changed

6 files changed

+12
-8
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22266,8 +22266,8 @@ namespace ts {
2226622266
// Grammar checking
2226722267
checkGrammarSourceFile(node);
2226822268

22269-
potentialThisCollisions.length = 0;
22270-
potentialNewTargetCollisions.length = 0;
22269+
clear(potentialThisCollisions);
22270+
clear(potentialNewTargetCollisions);
2227122271

2227222272
deferredNodes = [];
2227322273
deferredUnusedIdentifierNodes = produceDiagnostics && noUnusedIdentifiers ? [] : undefined;
@@ -22293,12 +22293,12 @@ namespace ts {
2229322293

2229422294
if (potentialThisCollisions.length) {
2229522295
forEach(potentialThisCollisions, checkIfThisIsCapturedInEnclosingScope);
22296-
potentialThisCollisions.length = 0;
22296+
clear(potentialThisCollisions);
2229722297
}
2229822298

2229922299
if (potentialNewTargetCollisions.length) {
2230022300
forEach(potentialNewTargetCollisions, checkIfNewTargetIsCapturedInEnclosingScope);
22301-
potentialNewTargetCollisions.length = 0;
22301+
clear(potentialNewTargetCollisions);
2230222302
}
2230322303

2230422304
links.flags |= NodeCheckFlags.TypeChecked;

src/compiler/core.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ namespace ts {
384384
array.length = outIndex;
385385
}
386386

387+
export function clear(array: {}[]): void {
388+
array.length = 0;
389+
}
390+
387391
export function map<T, U>(array: ReadonlyArray<T>, f: (x: T, i: number) => U): U[] {
388392
let result: U[];
389393
if (array) {

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ namespace ts.projectSystem {
561561
}
562562

563563
clearOutput() {
564-
this.output.length = 0;
564+
clear(this.output);
565565
}
566566

567567
readonly readFile = (s: string) => (<File>this.fs.get(this.toPath(s))).content;

src/server/builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ namespace ts.server {
223223
for (const reference of this.references) {
224224
reference.removeReferencedBy(this);
225225
}
226-
this.references = createSortedArray<ModuleBuilderFileInfo>();
226+
clear(this.references);
227227
}
228228
}
229229

src/server/scriptInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ namespace ts.server {
242242
// detach is unnecessary since we'll clean the list of containing projects anyways
243243
p.removeFile(this, /*detachFromProjects*/ false);
244244
}
245-
this.containingProjects.length = 0;
245+
clear(this.containingProjects);
246246
}
247247

248248
getDefaultProject() {

src/services/shims.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ namespace ts {
11761176

11771177
public close(): void {
11781178
// Forget all the registered shims
1179-
this._shims = [];
1179+
clear(this._shims);
11801180
this.documentRegistry = undefined;
11811181
}
11821182

0 commit comments

Comments
 (0)