File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -293,10 +293,22 @@ class ClassExtractor {
293
293
) ;
294
294
}
295
295
296
+ /** Check if the parameter is a constructor parameter with a public modifier */
297
+ private isPublicConstructorParameterProperty ( node : ts . Node ) : boolean {
298
+ if ( ts . isParameterPropertyDeclaration ( node , node . parent ) && node . modifiers ) {
299
+ return node . modifiers . some ( ( modifier ) => modifier . kind === ts . SyntaxKind . PublicKeyword ) ;
300
+ }
301
+ return false ;
302
+ }
303
+
296
304
/** Gets whether a member is a property. */
297
305
private isProperty ( member : ts . Node ) : member is PropertyLike {
298
306
// Classes have declarations, interface have signatures
299
- return ts . isPropertyDeclaration ( member ) || ts . isPropertySignature ( member ) ;
307
+ return (
308
+ ts . isPropertyDeclaration ( member ) ||
309
+ ts . isPropertySignature ( member ) ||
310
+ this . isPublicConstructorParameterProperty ( member )
311
+ ) ;
300
312
}
301
313
302
314
/** Gets whether a member is a method. */
Original file line number Diff line number Diff line change @@ -573,5 +573,33 @@ runInEachFileSystem(() => {
573
573
expect ( ageSetterEntry . type ) . toBe ( 'number' ) ;
574
574
expect ( ageSetterEntry . memberTags ) . toContain ( MemberTags . Inherited ) ;
575
575
} ) ;
576
+
577
+ it ( 'should extract public constructor parameters' , ( ) => {
578
+ env . write (
579
+ 'index.ts' ,
580
+ `
581
+ export class MyClass {
582
+ myProp: string;
583
+
584
+ constructor(public foo: string, private: bar: string, protected: baz: string) {}
585
+ }` ,
586
+ ) ;
587
+
588
+ const docs : DocEntry [ ] = env . driveDocsExtraction ( 'index.ts' ) ;
589
+ expect ( docs . length ) . toBe ( 1 ) ;
590
+
591
+ const classEntry = docs [ 0 ] as ClassEntry ;
592
+ expect ( classEntry . members . length ) . toBe ( 2 ) ;
593
+
594
+ const [ myPropEntry , fooEntry ] = classEntry . members as PropertyEntry [ ] ;
595
+
596
+ expect ( myPropEntry . name ) . toBe ( 'myProp' ) ;
597
+ expect ( myPropEntry . memberType ) . toBe ( MemberType . Property ) ;
598
+ expect ( ( myPropEntry as PropertyEntry ) . type ) . toBe ( 'string' ) ;
599
+
600
+ expect ( fooEntry . name ) . toBe ( 'foo' ) ;
601
+ expect ( fooEntry . memberType ) . toBe ( MemberType . Property ) ;
602
+ expect ( ( fooEntry as PropertyEntry ) . type ) . toBe ( 'string' ) ;
603
+ } ) ;
576
604
} ) ;
577
605
} ) ;
You can’t perform that action at this time.
0 commit comments