Skip to content

Commit

Permalink
feat: add class generic type param in manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideMininni-Fincons committed Dec 12, 2024
1 parent 9944872 commit 552cbd2
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tools/manifest/custom-elements-manifest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const overrideTypeKey = 'overrideType';
const classGenericsTypeKey = 'classGenerics';

/**
* Docs: https://custom-elements-manifest.open-wc.org/analyzer/getting-started/
Expand Down Expand Up @@ -96,6 +97,19 @@ export function createManifestConfig(library = '') {
}

if (ts.isClassDeclaration(node)) {
const classDeclaration = moduleDoc.declarations.find(
(declaration) => declaration.name === node.name.getText(),
);

/**
* If the class uses a generic type parameter, add it to the class declaration.
* It will be used in the Angular wrapper to correctly generate classes.
* Mainly used for datepicker and calendar components.
*/
if (node.typeParameters && node.typeParameters.length > 0) {
classDeclaration[classGenericsTypeKey] = node.typeParameters[0].getText();
}

/**
* When a generic T type is used in a superclass declaration, it overrides the type defined in derived class
* during the doc generation (as the `value` property in the `SbbFormAssociatedMixinType`).
Expand All @@ -109,9 +123,6 @@ export function createManifestConfig(library = '') {
// eslint-disable-next-line lyne/local-name-rule
if (tag.tagName.getText() === overrideTypeKey) {
const [memberName, memberOverrideType] = tag.comment.split(' - ');
const classDeclaration = moduleDoc.declarations.find(
(declaration) => declaration.name === node.name.getText(),
);
if (!classDeclaration[overrideTypeKey]) {
classDeclaration[overrideTypeKey] = [{ memberName, memberOverrideType }];
} else {
Expand Down

0 comments on commit 552cbd2

Please sign in to comment.