Skip to content

Commit

Permalink
Attach generic type parameters to the declaring type
Browse files Browse the repository at this point in the history
  • Loading branch information
flobernd committed Jun 18, 2024
1 parent f3591e2 commit 380fbd2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions compiler/src/model/build-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}

Expand Down Expand Up @@ -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
})
}

Expand Down
17 changes: 16 additions & 1 deletion compiler/src/model/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 380fbd2

Please sign in to comment.