From 380fbd2d3d6a135935f9147b0905b80be594b7be Mon Sep 17 00:00:00 2001 From: Florian Bernd Date: Tue, 18 Jun 2024 09:11:52 +0200 Subject: [PATCH] Attach generic type parameters to the declaring type --- compiler/src/model/build-model.ts | 4 ++-- compiler/src/model/utils.ts | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/compiler/src/model/build-model.ts b/compiler/src/model/build-model.ts index 3fb1cc07c6..812d4ac8ca 100644 --- a/compiler/src/model/build-model.ts +++ b/compiler/src/model/build-model.ts @@ -444,7 +444,7 @@ function compileClassOrInterfaceDeclaration (declaration: ClassDeclaration | Int for (const typeParameter of declaration.getTypeParameters()) { type.generics = (type.generics ?? []).concat({ name: modelGenerics(typeParameter), - namespace: type.name.namespace + namespace: type.name.namespace + '.' + type.name.name }) } @@ -532,7 +532,7 @@ function compileClassOrInterfaceDeclaration (declaration: ClassDeclaration | Int for (const typeParameter of declaration.getTypeParameters()) { type.generics = (type.generics ?? []).concat({ name: modelGenerics(typeParameter), - namespace: type.name.namespace + namespace: type.name.namespace + '.' + type.name.name }) } diff --git a/compiler/src/model/utils.ts b/compiler/src/model/utils.ts index 86d6f8d8c0..a11c2dafed 100644 --- a/compiler/src/model/utils.ts +++ b/compiler/src/model/utils.ts @@ -343,6 +343,20 @@ export function modelType (node: Node): model.ValueOf { namespace: getNameSpace(node) } } + + if (Node.isTypeParameterDeclaration(declaration)) { + const parent = declaration.getParent(); + assert( + parent, + Node.isClassDeclaration(parent) || + Node.isInterfaceDeclaration(parent) || + Node.isTypeAliasDeclaration(parent), + 'It should be a class, interface, enum, type alias, or type parameter declaration' + ) + + type.type.namespace += '.' + parent.getName() as string; + } + return type } } @@ -475,9 +489,10 @@ export function modelEnumDeclaration (declaration: EnumDeclaration): model.Enum export function modelTypeAlias (declaration: TypeAliasDeclaration): model.TypeAlias { const type = declaration.getTypeNode() assert(declaration, type != null, 'Type alias without a referenced type') + const generics = declaration.getTypeParameters().map(typeParameter => ({ name: modelGenerics(typeParameter), - namespace: getNameSpace(typeParameter) + namespace: getNameSpace(typeParameter) + '.' + declaration.getName() as string })) const alias = modelType(type)