Skip to content

Commit f88c747

Browse files
JeanMechepkozlowski-opensource
authored andcommitted
refactor(compiler-cli): Don't extract constructors with no parameters (angular#60928)
This will prevent usesless paramters in the docs, ex: https://angular.dev/api/core/ApplicationInitStatus#constructor This improves angular#60302 PR Close angular#60928
1 parent 0be5412 commit f88c747

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/compiler-cli/src/ngtsc/docs/src/class_extractor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ class ClassExtractor {
117117
return this.extractClassProperty(memberDeclaration);
118118
} else if (ts.isAccessor(memberDeclaration)) {
119119
return this.extractGetterSetter(memberDeclaration);
120-
} else if (ts.isConstructorDeclaration(memberDeclaration)) {
120+
} else if (
121+
ts.isConstructorDeclaration(memberDeclaration) &&
122+
memberDeclaration.parameters.length > 0
123+
) {
121124
return this.extractConstructor(memberDeclaration);
122125
}
123126

packages/compiler-cli/test/ngtsc/doc_extraction/class_doc_extraction_spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,25 @@ runInEachFileSystem(() => {
723723
expect((fooEntry as PropertyEntry).type).toBe('string');
724724
});
725725

726+
it('should not extract a constructor without parameters', () => {
727+
env.write(
728+
'index.ts',
729+
`
730+
export class MyClass {
731+
constructor() {}
732+
733+
foo: string;
734+
}`,
735+
);
736+
737+
const docs: DocEntry[] = env.driveDocsExtraction('index.ts');
738+
expect(docs.length).toBe(1);
739+
const classEntry = docs[0] as ClassEntry;
740+
expect(classEntry.members.length).toBe(1); // only foo, no constructor
741+
const [fooEntry] = classEntry.members as PropertyEntry[];
742+
expect(fooEntry.name).toBe('foo');
743+
});
744+
726745
it('should extract members of a class from .d.ts', () => {
727746
env.write(
728747
'index.d.ts',

0 commit comments

Comments
 (0)