Skip to content

Commit cee910f

Browse files
committed
Improve sort order
1 parent d0abb82 commit cee910f

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

‎apps/api-extractor/src/generators/DtsGenerator.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ class Entry {
1616
public localName: string;
1717
public followedSymbol: ts.Symbol;
1818
public dtsDeclarations: dts.TopLevelDeclaration[] = [];
19+
private _sortKey: string|undefined = undefined;
20+
21+
public getSortKey(): string {
22+
if (!this._sortKey) {
23+
if (this.localName.substr(0, 1) === '_') {
24+
// Removes the leading underscore, for example: "_example" --> "example*"
25+
// This causes internal definitions to sort alphabetically with regular definitions.
26+
// The star is appended to preserve uniqueness, since "*" is not a legal identifier character.
27+
this._sortKey = this.localName.substr(1) + ' ';
28+
} else {
29+
this._sortKey = this.localName;
30+
}
31+
}
32+
return this._sortKey;
33+
}
1934
}
2035

2136
export default class DtsGenerator {
@@ -111,7 +126,7 @@ export default class DtsGenerator {
111126
}
112127
}
113128

114-
this._entries.sort((a, b) => a.localName.localeCompare(b.localName));
129+
this._entries.sort((a, b) => a.getSortKey().localeCompare(b.getSortKey()));
115130

116131
let content: string = '';
117132
for (const entry of this._entries) {

0 commit comments

Comments
 (0)