3
3
/* @flow */
4
4
5
5
var generate = require ( 'babel-generator' ) . default ,
6
- findClass = require ( './finders' ) . findClass ;
6
+ findTarget = require ( './finders' ) . findTarget ;
7
7
8
8
/**
9
9
* Infers an `augments` tag from an ES6 class declaration
@@ -16,18 +16,37 @@ function inferAugments(comment/*: Comment */) {
16
16
return comment ;
17
17
}
18
18
19
- var path = findClass ( comment . context . ast ) ;
20
-
21
- /*
22
- * A superclass can be a single name, like React,
23
- * or a MemberExpression like React.Component,
24
- * so we generate code from the AST rather than assuming
25
- * we can access a name like `path.node.superClass.name`
26
- */
27
- if ( path && path . node . superClass ) {
28
- comment . augments . push ( {
29
- title : 'augments' ,
30
- name : generate ( path . node . superClass ) . code
19
+ var path = findTarget ( comment . context . ast ) ;
20
+
21
+ if ( ! path ) {
22
+ return comment ;
23
+ }
24
+
25
+ if ( path . isClass ( ) ) {
26
+ /*
27
+ * A superclass can be a single name, like React,
28
+ * or a MemberExpression like React.Component,
29
+ * so we generate code from the AST rather than assuming
30
+ * we can access a name like `path.node.superClass.name`
31
+ */
32
+ if ( path . node . superClass ) {
33
+ comment . augments . push ( {
34
+ title : 'augments' ,
35
+ name : generate ( path . node . superClass ) . code
36
+ } ) ;
37
+ }
38
+ } else if ( path . isInterfaceDeclaration ( ) ) {
39
+ /*
40
+ * extends is an array of interface identifiers or
41
+ * qualified type identifiers, so we generate code
42
+ * from the AST rather than assuming we can acces
43
+ * a name.
44
+ */
45
+ path . node . extends . forEach ( node => {
46
+ comment . augments . push ( {
47
+ title : 'extends' ,
48
+ name : generate ( node ) . code
49
+ } ) ;
31
50
} ) ;
32
51
}
33
52
0 commit comments