File tree 2 files changed +47
-13
lines changed 2 files changed +47
-13
lines changed Original file line number Diff line number Diff line change @@ -21,20 +21,21 @@ module.exports = function () {
21
21
return ;
22
22
}
23
23
24
- // If this comment has a @class tag with a name, use it
25
- // as a title
26
- if ( comment . tags [ i ] . title === 'class' && comment . tags [ i ] . name ) {
27
- comment . tags . push ( { title : 'name' , name : comment . tags [ i ] . name } ) ;
28
- this . push ( comment ) ;
29
- return ;
30
- }
24
+ // If this comment has a @class , @event, or @typedef tag with a name,
25
+ // use it.
26
+ var explicitNameTags = {
27
+ 'class' : 'name' ,
28
+ 'event' : 'description' ,
29
+ 'typedef' : 'description'
30
+ } ;
31
31
32
- // If this comment has an @event tag with a name, use it
33
- // as a title
34
- if ( comment . tags [ i ] . title === 'event' && comment . tags [ i ] . description ) {
35
- comment . tags . push ( { title : 'name' , name : comment . tags [ i ] . description } ) ;
36
- this . push ( comment ) ;
37
- return ;
32
+ for ( var title in explicitNameTags ) {
33
+ var value = explicitNameTags [ title ] ;
34
+ if ( comment . tags [ i ] . title === title && comment . tags [ i ] [ value ] ) {
35
+ comment . tags . push ( { title : 'name' , name : comment . tags [ i ] [ value ] } ) ;
36
+ this . push ( comment ) ;
37
+ return ;
38
+ }
38
39
}
39
40
}
40
41
Original file line number Diff line number Diff line change @@ -121,3 +121,36 @@ test('inferName - explicit name', function (t) {
121
121
t . end ( ) ;
122
122
} ) ;
123
123
} ) ;
124
+
125
+ test ( 'inferName - class' , function ( t ) {
126
+ evaluate ( function ( ) {
127
+ /** @class ExplicitClass */
128
+ function ImplicitClass ( ) { }
129
+ return ImplicitClass ;
130
+ } , function ( result ) {
131
+ t . equal ( result [ 0 ] . name , 'ExplicitClass' ) ;
132
+ t . end ( ) ;
133
+ } ) ;
134
+ } ) ;
135
+
136
+ test ( 'inferName - event' , function ( t ) {
137
+ evaluate ( function ( ) {
138
+ /** @event explicitEvent */
139
+ function implicitName ( ) { }
140
+ return implicitName ;
141
+ } , function ( result ) {
142
+ t . equal ( result [ 0 ] . name , 'explicitEvent' ) ;
143
+ t . end ( ) ;
144
+ } ) ;
145
+ } ) ;
146
+
147
+ test ( 'inferName - typedef' , function ( t ) {
148
+ evaluate ( function ( ) {
149
+ /** @typedef {Object } ExplicitTypedef */
150
+ function implicitName ( ) { }
151
+ return implicitName ;
152
+ } , function ( result ) {
153
+ t . equal ( result [ 0 ] . name , 'ExplicitTypedef' ) ;
154
+ t . end ( ) ;
155
+ } ) ;
156
+ } ) ;
You can’t perform that action at this time.
0 commit comments