|
5 | 5 |
|
6 | 6 | import * as ts from 'typescript'; |
7 | 7 | 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'; |
9 | 9 |
|
10 | 10 | import { ExtractorContext } from '../../ExtractorContext'; |
11 | 11 | import { IndentedWriter } from '../../utils/IndentedWriter'; |
@@ -62,14 +62,14 @@ export class DtsRollupGenerator { |
62 | 62 | * |
63 | 63 | * /// <reference types="example-library" /> |
64 | 64 | */ |
65 | | - private _dtsTypeReferenceDirectives: string[] = []; |
| 65 | + private _dtsTypeReferenceDirectives: Set<string> = new Set<string>(); |
66 | 66 |
|
67 | 67 | /** |
68 | 68 | * A list of names (e.g. "runtime-library") that should appear in a reference like this: |
69 | 69 | * |
70 | 70 | * /// <reference lib="runtime-library" /> |
71 | 71 | */ |
72 | | - private _dtsLibReferenceDirectives: string[] = []; |
| 72 | + private _dtsLibReferenceDirectives: Set<string> = new Set<string>(); |
73 | 73 |
|
74 | 74 | public constructor(context: ExtractorContext) { |
75 | 75 | this._context = context; |
@@ -111,9 +111,9 @@ export class DtsRollupGenerator { |
111 | 111 |
|
112 | 112 | this._makeUniqueNames(); |
113 | 113 |
|
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); |
117 | 117 | } |
118 | 118 |
|
119 | 119 | /** |
@@ -565,16 +565,12 @@ export class DtsRollupGenerator { |
565 | 565 |
|
566 | 566 | for (const typeReferenceDirective of sourceFile.typeReferenceDirectives) { |
567 | 567 | 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); |
571 | 569 | } |
572 | 570 |
|
573 | 571 | for (const libReferenceDirective of sourceFile.libReferenceDirectives) { |
574 | 572 | 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); |
578 | 574 | } |
579 | 575 |
|
580 | 576 | } |
|
0 commit comments