Skip to content

Commit 1be726c

Browse files
committed
Fix failing tests
1 parent 65dfba3 commit 1be726c

File tree

20 files changed

+770
-270
lines changed

20 files changed

+770
-270
lines changed

src/lib/models/types.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ export class ReferenceType extends Type {
842842
name ?? symbol.name,
843843
symbol,
844844
context.project,
845-
getQualifiedName(context.checker, symbol)
845+
getQualifiedName(symbol, name ?? symbol.name)
846846
);
847847

848848
const symbolPath = symbol?.declarations?.[0]
@@ -894,19 +894,14 @@ export class ReferenceType extends Type {
894894
}
895895

896896
override toObject(serializer: Serializer): JSONOutput.ReferenceType {
897-
const result: JSONOutput.ReferenceType = {
897+
return {
898898
type: this.type,
899899
id: this.reflection?.id,
900900
typeArguments: serializer.toObjectsOptional(this.typeArguments),
901901
name: this.name,
902+
qualifiedName: this.qualifiedName,
903+
package: this.package,
902904
};
903-
904-
if (this.package) {
905-
result.qualifiedName = this.qualifiedName;
906-
result.package = this.package;
907-
}
908-
909-
return result;
910905
}
911906
}
912907

src/lib/serialization/schema.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,11 @@ export interface QueryType extends Type, S<M.QueryType, "type" | "queryType"> {}
243243

244244
export interface ReferenceType
245245
extends Type,
246-
S<M.ReferenceType, "type" | "name" | "typeArguments" | "package"> {
246+
S<
247+
M.ReferenceType,
248+
"type" | "name" | "typeArguments" | "package" | "qualifiedName"
249+
> {
247250
id?: number;
248-
qualifiedName?: string;
249251
}
250252

251253
export interface ReflectionType extends Type, S<M.ReflectionType, "type"> {

src/lib/types/ts-internal/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ declare module "typescript" {
1212
interface Symbol {
1313
// https://github.com/microsoft/TypeScript/blob/v4.1.5/src/compiler/types.ts#L4734-L4737
1414
checkFlags?: CheckFlags;
15+
16+
// https://github.com/microsoft/TypeScript/blob/v4.7.4/src/compiler/types.ts#L4941
17+
// https://github.com/microsoft/TypeScript/issues/38344
18+
parent?: ts.Symbol;
1519
}
1620

1721
interface TypeChecker {

src/lib/utils/tsutils.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
import type * as ts from "typescript";
1+
import * as ts from "typescript";
22

3-
export function getQualifiedName(checker: ts.TypeChecker, symbol: ts.Symbol) {
4-
const qualifiedName = checker.getFullyQualifiedName(symbol);
5-
// I think this is less bad than depending on symbol.parent...
6-
// https://github.com/microsoft/TypeScript/issues/38344
7-
// It will break if someone names a directory with a quote in it, but so will lots
8-
// of other things including other parts of TypeDoc. Until it *actually* breaks someone...
9-
if (qualifiedName.startsWith('"') && qualifiedName.includes('".')) {
10-
return qualifiedName.substring(qualifiedName.indexOf('".', 1) + 2);
11-
} else {
12-
return qualifiedName;
3+
export function getQualifiedName(symbol: ts.Symbol, defaultName: string) {
4+
// Two implementation options for this one:
5+
// 1. Use the internal symbol.parent, to walk up until we hit a source file symbol (if in a module)
6+
// or undefined (if in a global file)
7+
// 2. Use checker.getFullyQualifiedName and parse out the name from the returned string.
8+
// The symbol.parent method is easier to check for now.
9+
let sym: ts.Symbol | undefined = symbol;
10+
const parts: string[] = [];
11+
while (sym && !sym.declarations?.some(ts.isSourceFile)) {
12+
parts.unshift(sym.name);
13+
sym = sym.parent;
1314
}
15+
16+
return parts.join(".") || defaultName;
1417
}

src/test/converter/alias/specs.json

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
"checkType": {
4242
"type": "reference",
4343
"id": 9,
44-
"name": "T"
44+
"name": "T",
45+
"qualifiedName": "T",
46+
"package": "typedoc"
4547
},
4648
"extendsType": {
4749
"type": "intrinsic",
@@ -93,7 +95,9 @@
9395
"checkType": {
9496
"type": "reference",
9597
"id": 11,
96-
"name": "T"
98+
"name": "T",
99+
"qualifiedName": "T",
100+
"package": "typedoc"
97101
},
98102
"extendsType": {
99103
"type": "reference",
@@ -109,12 +113,16 @@
109113
},
110114
"trueType": {
111115
"type": "reference",
112-
"name": "U"
116+
"name": "U",
117+
"qualifiedName": "U",
118+
"package": "typedoc"
113119
},
114120
"falseType": {
115121
"type": "reference",
116122
"id": 11,
117-
"name": "T"
123+
"name": "T",
124+
"qualifiedName": "T",
125+
"package": "typedoc"
118126
}
119127
}
120128
},
@@ -182,7 +190,9 @@
182190
"type": {
183191
"type": "reference",
184192
"id": 6,
185-
"name": "T"
193+
"name": "T",
194+
"qualifiedName": "T",
195+
"package": "typedoc"
186196
}
187197
},
188198
{
@@ -194,7 +204,9 @@
194204
"type": {
195205
"type": "reference",
196206
"id": 6,
197-
"name": "T"
207+
"name": "T",
208+
"qualifiedName": "T",
209+
"package": "typedoc"
198210
}
199211
}
200212
],

0 commit comments

Comments
 (0)