Skip to content

Commit ea13e64

Browse files
committed
PR feedback to use sets instead of arrays
1 parent 3168374 commit ea13e64

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

apps/api-extractor/src/generators/dtsRollup/DtsRollupGenerator.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as ts from 'typescript';
77
import * as tsdoc from '@microsoft/tsdoc';
8-
import { FileSystem, NewlineKind } from '@microsoft/node-core-library';
8+
import { FileSystem, NewlineKind, Sort } from '@microsoft/node-core-library';
99

1010
import { ExtractorContext } from '../../ExtractorContext';
1111
import { IndentedWriter } from '../../utils/IndentedWriter';
@@ -62,14 +62,14 @@ export class DtsRollupGenerator {
6262
*
6363
* /// <reference types="example-library" />
6464
*/
65-
private _dtsTypeReferenceDirectives: string[] = [];
65+
private _dtsTypeReferenceDirectives: Set<string> = new Set<string>();
6666

6767
/**
6868
* A list of names (e.g. "runtime-library") that should appear in a reference like this:
6969
*
7070
* /// <reference lib="runtime-library" />
7171
*/
72-
private _dtsLibReferenceDirectives: string[] = [];
72+
private _dtsLibReferenceDirectives: Set<string> = new Set<string>();
7373

7474
public constructor(context: ExtractorContext) {
7575
this._context = context;
@@ -111,9 +111,9 @@ export class DtsRollupGenerator {
111111

112112
this._makeUniqueNames();
113113

114-
this._dtsEntries.sort((a, b) => a.getSortKey().localeCompare(b.getSortKey()));
115-
this._dtsTypeReferenceDirectives.sort();
116-
this._dtsLibReferenceDirectives.sort();
114+
Sort.sortBy(this._dtsEntries, x => x.getSortKey());
115+
Sort.sortSet(this._dtsTypeReferenceDirectives);
116+
Sort.sortSet(this._dtsLibReferenceDirectives);
117117
}
118118

119119
/**
@@ -565,16 +565,12 @@ export class DtsRollupGenerator {
565565

566566
for (const typeReferenceDirective of sourceFile.typeReferenceDirectives) {
567567
const name: string = sourceFile.text.substring(typeReferenceDirective.pos, typeReferenceDirective.end);
568-
if (this._dtsTypeReferenceDirectives.indexOf(name) < 0) {
569-
this._dtsTypeReferenceDirectives.push(name);
570-
}
568+
this._dtsTypeReferenceDirectives.add(name);
571569
}
572570

573571
for (const libReferenceDirective of sourceFile.libReferenceDirectives) {
574572
const name: string = sourceFile.text.substring(libReferenceDirective.pos, libReferenceDirective.end);
575-
if (this._dtsLibReferenceDirectives.indexOf(name) < 0) {
576-
this._dtsLibReferenceDirectives.push(name);
577-
}
573+
this._dtsLibReferenceDirectives.add(name);
578574
}
579575

580576
}

0 commit comments

Comments
 (0)