Skip to content

Commit 380fbd2

Browse files
committed
Attach generic type parameters to the declaring type
1 parent f3591e2 commit 380fbd2

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

compiler/src/model/build-model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ function compileClassOrInterfaceDeclaration (declaration: ClassDeclaration | Int
444444
for (const typeParameter of declaration.getTypeParameters()) {
445445
type.generics = (type.generics ?? []).concat({
446446
name: modelGenerics(typeParameter),
447-
namespace: type.name.namespace
447+
namespace: type.name.namespace + '.' + type.name.name
448448
})
449449
}
450450

@@ -532,7 +532,7 @@ function compileClassOrInterfaceDeclaration (declaration: ClassDeclaration | Int
532532
for (const typeParameter of declaration.getTypeParameters()) {
533533
type.generics = (type.generics ?? []).concat({
534534
name: modelGenerics(typeParameter),
535-
namespace: type.name.namespace
535+
namespace: type.name.namespace + '.' + type.name.name
536536
})
537537
}
538538

compiler/src/model/utils.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,20 @@ export function modelType (node: Node): model.ValueOf {
343343
namespace: getNameSpace(node)
344344
}
345345
}
346+
347+
if (Node.isTypeParameterDeclaration(declaration)) {
348+
const parent = declaration.getParent();
349+
assert(
350+
parent,
351+
Node.isClassDeclaration(parent) ||
352+
Node.isInterfaceDeclaration(parent) ||
353+
Node.isTypeAliasDeclaration(parent),
354+
'It should be a class, interface, enum, type alias, or type parameter declaration'
355+
)
356+
357+
type.type.namespace += '.' + parent.getName() as string;
358+
}
359+
346360
return type
347361
}
348362
}
@@ -475,9 +489,10 @@ export function modelEnumDeclaration (declaration: EnumDeclaration): model.Enum
475489
export function modelTypeAlias (declaration: TypeAliasDeclaration): model.TypeAlias {
476490
const type = declaration.getTypeNode()
477491
assert(declaration, type != null, 'Type alias without a referenced type')
492+
478493
const generics = declaration.getTypeParameters().map(typeParameter => ({
479494
name: modelGenerics(typeParameter),
480-
namespace: getNameSpace(typeParameter)
495+
namespace: getNameSpace(typeParameter) + '.' + declaration.getName() as string
481496
}))
482497

483498
const alias = modelType(type)

0 commit comments

Comments
 (0)