@@ -31,35 +31,27 @@ export default function componentDocblockHandler(
31
31
path : NodePath
32
32
) {
33
33
var description = null ;
34
- // Find parent statement (e.g. var Component = React.createClass(<path>);)
35
- var searchPath = path ;
36
- while ( searchPath && ! types . Statement . check ( searchPath . node ) ) {
37
- searchPath = searchPath . parent ;
38
- }
39
- if ( searchPath ) {
40
- // If the parent is an export statement, we have to traverse one more up
41
- if ( types . ExportNamedDeclaration . check ( searchPath . parentPath . node ) ||
42
- types . ExportDefaultDeclaration . check ( searchPath . parentPath . node ) ) {
43
- searchPath = searchPath . parentPath ;
44
- }
45
- description = getDocblock ( searchPath ) ;
46
- }
47
- if ( description == null && isClassDefinition ( path ) ) {
34
+
35
+ if ( isClassDefinition ( path ) ) {
48
36
// If we have a class declaration or expression, then the comment might be
49
- // attached to the first decorator instead.
37
+ // attached to the last decorator instead as trailing comment .
50
38
if ( path . node . decorators && path . node . decorators . length > 0 ) {
51
- description = getDocblock ( path . get ( 'decorators' , 0 ) ) ;
39
+ description = getDocblock ( path . get ( 'decorators' , path . node . decorators . length - 1 ) , true ) ;
52
40
}
53
41
}
54
42
if ( description == null ) {
55
- // If this is the first statement in the module body, the comment is attached
56
- // to the program node
57
- var programPath = searchPath ;
58
- while ( programPath && ! types . Program . check ( programPath . node ) ) {
59
- programPath = programPath . parent ;
43
+ // Find parent statement (e.g. var Component = React.createClass(<path>);)
44
+ var searchPath = path ;
45
+ while ( searchPath && ! types . Statement . check ( searchPath . node ) ) {
46
+ searchPath = searchPath . parent ;
60
47
}
61
- if ( programPath . get ( 'body' , 0 ) === searchPath ) {
62
- description = getDocblock ( programPath ) ;
48
+ if ( searchPath ) {
49
+ // If the parent is an export statement, we have to traverse one more up
50
+ if ( types . ExportNamedDeclaration . check ( searchPath . parentPath . node ) ||
51
+ types . ExportDefaultDeclaration . check ( searchPath . parentPath . node ) ) {
52
+ searchPath = searchPath . parentPath ;
53
+ }
54
+ description = getDocblock ( searchPath ) ;
63
55
}
64
56
}
65
57
documentation . set ( 'description' , description || '' ) ;
0 commit comments