Skip to content

Commit 7bd045b

Browse files
committed
fix(class-helper): detect @internal tags for overridden @input via parsed JSDoc cache
closes #1441
1 parent df0ebdd commit 7bd045b

2 files changed

Lines changed: 91 additions & 41 deletions

File tree

‎src/app/compiler/angular/deps/helpers/class-helper.ts‎

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,38 @@ export class ClassHelper {
9797
sourceFile: ts.SourceFile,
9898
result: any,
9999
): void {
100-
if (node.jsDoc) {
101-
const comment = this.jsdocParserUtil.getMainCommentOfNode(
102-
node,
103-
sourceFile,
104-
);
105-
if (typeof comment !== "undefined") {
106-
const cleanedDescription =
107-
this.jsdocParserUtil.parseComment(comment);
108-
result.rawdescription = cleanedDescription;
109-
result.description = markedAcl(cleanedDescription);
100+
const comment = this.jsdocParserUtil.getMainCommentOfNode(
101+
node,
102+
sourceFile,
103+
);
104+
if (typeof comment === "string") {
105+
const cleanedDescription = this.jsdocParserUtil.parseComment(comment);
106+
result.rawdescription = cleanedDescription;
107+
result.description = markedAcl(cleanedDescription);
108+
}
109+
}
110+
111+
private hasJSDocTag(member: ts.Node, tagName: string): boolean {
112+
const jsdocs = this.jsdocParserUtil.getJSDocs(member) as any[] | undefined;
113+
if (!jsdocs || jsdocs.length === 0) {
114+
return false;
115+
}
116+
117+
for (const doc of jsdocs) {
118+
if (doc?.tagName?.text === tagName) {
119+
return true;
120+
}
121+
122+
if (doc?.tags) {
123+
for (const tag of doc.tags) {
124+
if (tag?.tagName?.text === tagName) {
125+
return true;
126+
}
127+
}
110128
}
111129
}
130+
131+
return false;
112132
}
113133

114134
/**
@@ -623,19 +643,7 @@ export class ClassHelper {
623643
/**
624644
* Copyright https://github.com/ng-bootstrap/ng-bootstrap
625645
*/
626-
const internalTags: string[] = ["internal"];
627-
if (member.jsDoc) {
628-
for (const doc of member.jsDoc) {
629-
if (doc.tags) {
630-
for (const tag of doc.tags) {
631-
if (internalTags.indexOf(tag.tagName.text) > -1) {
632-
return true;
633-
}
634-
}
635-
}
636-
}
637-
}
638-
return false;
646+
return this.hasJSDocTag(member, "internal");
639647
}
640648

641649
private isPublic(member): boolean {
@@ -654,19 +662,7 @@ export class ClassHelper {
654662
/**
655663
* Copyright https://github.com/ng-bootstrap/ng-bootstrap
656664
*/
657-
const internalTags: string[] = ["hidden"];
658-
if (member.jsDoc) {
659-
for (const doc of member.jsDoc) {
660-
if (doc.tags) {
661-
for (const tag of doc.tags) {
662-
if (internalTags.indexOf(tag.tagName.text) > -1) {
663-
return true;
664-
}
665-
}
666-
}
667-
}
668-
}
669-
return false;
665+
return this.hasJSDocTag(member, "hidden");
670666
}
671667

672668
private isPipeDecorator(decorator) {
@@ -2037,11 +2033,7 @@ export class ClassHelper {
20372033
getRequiredField().initializer.kind !== SyntaxKind.TrueKeyword;
20382034
}
20392035

2040-
if (
2041-
!_return.description &&
2042-
property.jsDoc &&
2043-
property.jsDoc.length > 0
2044-
) {
2036+
if (!_return.description) {
20452037
const jsdoctags = this.jsdocParserUtil.getJSDocs(property);
20462038
this.processJSDocTags(jsdoctags, _return);
20472039
this.extractAndProcessJSDocComment(property, sourceFile, _return);

‎test/src/app/compiler/angular/deps/helpers/class-helper.spec.ts‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,64 @@ describe('ClassHelper', () => {
886886
expect(result.required).to.be.true;
887887
expect(result.optional).to.be.false;
888888
});
889+
890+
it('should extract jsdoc tags and description even when property.jsDoc is missing (issue #1441)', () => {
891+
const property = {
892+
name: { text: 'internalOverrideInput', kind: SyntaxKind.Identifier },
893+
type: { kind: SyntaxKind.StringKeyword },
894+
initializer: undefined,
895+
kind: SyntaxKind.PropertyDeclaration,
896+
pos: 10,
897+
end: 20
898+
} as any;
899+
900+
const mockJSDoc = [
901+
{
902+
tags: [
903+
{ tagName: { text: 'internal' }, comment: '' }
904+
]
905+
}
906+
] as any;
907+
908+
jsdocParserStub.getJSDocs.withArgs(property).returns(mockJSDoc);
909+
jsdocParserStub.getMainCommentOfNode
910+
.withArgs(property, mockSourceFile)
911+
.returns('/** Internal override input */');
912+
jsdocParserStub.parseComment
913+
.withArgs('/** Internal override input */')
914+
.returns('Internal override input');
915+
916+
const decorator = {
917+
expression: {
918+
arguments: []
919+
}
920+
} as any;
921+
922+
const result = (classHelper as any).visitInputAndHostBinding(property, decorator, mockSourceFile);
923+
924+
expect(result.jsdoctags).to.be.an('array').with.length(1);
925+
expect(result.description).to.contain('Internal override input');
926+
});
927+
});
928+
929+
describe('isInternal', () => {
930+
it('should detect @internal tag from parsed JSDoc cache even when member.jsDoc is missing (issue #1441)', () => {
931+
const member = {
932+
kind: SyntaxKind.PropertyDeclaration
933+
} as any;
934+
935+
jsdocParserStub.getJSDocs.withArgs(member).returns([
936+
{
937+
tags: [
938+
{ tagName: { text: 'internal' }, comment: '' }
939+
]
940+
}
941+
] as any);
942+
943+
const result = (classHelper as any).isInternal(member);
944+
945+
expect(result).to.be.true;
946+
});
889947
});
890948

891949
describe('visitOutput', () => {

0 commit comments

Comments
 (0)