Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Aug 6, 2022
1 parent 65dfba3 commit 1be726c
Show file tree
Hide file tree
Showing 20 changed files with 770 additions and 270 deletions.
13 changes: 4 additions & 9 deletions src/lib/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ export class ReferenceType extends Type {
name ?? symbol.name,
symbol,
context.project,
getQualifiedName(context.checker, symbol)
getQualifiedName(symbol, name ?? symbol.name)
);

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

override toObject(serializer: Serializer): JSONOutput.ReferenceType {
const result: JSONOutput.ReferenceType = {
return {
type: this.type,
id: this.reflection?.id,
typeArguments: serializer.toObjectsOptional(this.typeArguments),
name: this.name,
qualifiedName: this.qualifiedName,
package: this.package,
};

if (this.package) {
result.qualifiedName = this.qualifiedName;
result.package = this.package;
}

return result;
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/lib/serialization/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,11 @@ export interface QueryType extends Type, S<M.QueryType, "type" | "queryType"> {}

export interface ReferenceType
extends Type,
S<M.ReferenceType, "type" | "name" | "typeArguments" | "package"> {
S<
M.ReferenceType,
"type" | "name" | "typeArguments" | "package" | "qualifiedName"
> {
id?: number;
qualifiedName?: string;
}

export interface ReflectionType extends Type, S<M.ReflectionType, "type"> {
Expand Down
4 changes: 4 additions & 0 deletions src/lib/types/ts-internal/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ declare module "typescript" {
interface Symbol {
// https://github.com/microsoft/TypeScript/blob/v4.1.5/src/compiler/types.ts#L4734-L4737
checkFlags?: CheckFlags;

// https://github.com/microsoft/TypeScript/blob/v4.7.4/src/compiler/types.ts#L4941
// https://github.com/microsoft/TypeScript/issues/38344
parent?: ts.Symbol;
}

interface TypeChecker {
Expand Down
25 changes: 14 additions & 11 deletions src/lib/utils/tsutils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import type * as ts from "typescript";
import * as ts from "typescript";

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

return parts.join(".") || defaultName;
}
24 changes: 18 additions & 6 deletions src/test/converter/alias/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
"checkType": {
"type": "reference",
"id": 9,
"name": "T"
"name": "T",
"qualifiedName": "T",
"package": "typedoc"
},
"extendsType": {
"type": "intrinsic",
Expand Down Expand Up @@ -93,7 +95,9 @@
"checkType": {
"type": "reference",
"id": 11,
"name": "T"
"name": "T",
"qualifiedName": "T",
"package": "typedoc"
},
"extendsType": {
"type": "reference",
Expand All @@ -109,12 +113,16 @@
},
"trueType": {
"type": "reference",
"name": "U"
"name": "U",
"qualifiedName": "U",
"package": "typedoc"
},
"falseType": {
"type": "reference",
"id": 11,
"name": "T"
"name": "T",
"qualifiedName": "T",
"package": "typedoc"
}
}
},
Expand Down Expand Up @@ -182,7 +190,9 @@
"type": {
"type": "reference",
"id": 6,
"name": "T"
"name": "T",
"qualifiedName": "T",
"package": "typedoc"
}
},
{
Expand All @@ -194,7 +204,9 @@
"type": {
"type": "reference",
"id": 6,
"name": "T"
"name": "T",
"qualifiedName": "T",
"package": "typedoc"
}
}
],
Expand Down

0 comments on commit 1be726c

Please sign in to comment.