Skip to content

Commit a1eb45d

Browse files
authored
Infer class augments tag with MemberExpression superClass. Fixes #458 (#616)
1 parent d96aa47 commit a1eb45d

File tree

6 files changed

+191
-1
lines changed

6 files changed

+191
-1
lines changed

lib/infer/augments.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var shouldSkipInference = require('./should_skip_inference'),
4+
generate = require('babel-generator').default,
45
findClass = require('./finders').findClass;
56

67
/**
@@ -17,10 +18,16 @@ function inferAugments() {
1718

1819
var path = findClass(comment.context.ast);
1920

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+
*/
2027
if (path && path.node.superClass) {
2128
comment.augments = [{
2229
title: 'augments',
23-
name: path.node.superClass.name
30+
name: generate(path.node.superClass).code
2431
}];
2532
}
2633

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"dependencies": {
1010
"ansi-html": "0.0.5",
1111
"babel-core": "^6.17.0",
12+
"babel-generator": "6.19.0",
1213
"babel-plugin-system-import-transformer": "2.4.0",
1314
"babel-plugin-transform-decorators-legacy": "^1.3.4",
1415
"babel-preset-es2015": "^6.16.0",

test/fixture/es6-class.input.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* This will fail.
3+
*/
4+
class Foo extends React.Component {}

test/fixture/es6-class.output.json

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
[
2+
{
3+
"description": {
4+
"type": "root",
5+
"children": [
6+
{
7+
"type": "paragraph",
8+
"children": [
9+
{
10+
"type": "text",
11+
"value": "This will fail.",
12+
"position": {
13+
"start": {
14+
"line": 1,
15+
"column": 1,
16+
"offset": 0
17+
},
18+
"end": {
19+
"line": 1,
20+
"column": 16,
21+
"offset": 15
22+
},
23+
"indent": []
24+
}
25+
}
26+
],
27+
"position": {
28+
"start": {
29+
"line": 1,
30+
"column": 1,
31+
"offset": 0
32+
},
33+
"end": {
34+
"line": 1,
35+
"column": 16,
36+
"offset": 15
37+
},
38+
"indent": []
39+
}
40+
}
41+
],
42+
"position": {
43+
"start": {
44+
"line": 1,
45+
"column": 1,
46+
"offset": 0
47+
},
48+
"end": {
49+
"line": 1,
50+
"column": 16,
51+
"offset": 15
52+
}
53+
}
54+
},
55+
"tags": [],
56+
"loc": {
57+
"start": {
58+
"line": 1,
59+
"column": 0
60+
},
61+
"end": {
62+
"line": 3,
63+
"column": 3
64+
}
65+
},
66+
"context": {
67+
"loc": {
68+
"start": {
69+
"line": 4,
70+
"column": 0
71+
},
72+
"end": {
73+
"line": 4,
74+
"column": 36
75+
}
76+
}
77+
},
78+
"errors": [],
79+
"name": "Foo",
80+
"augments": [
81+
{
82+
"title": "augments",
83+
"name": "React.Component"
84+
}
85+
],
86+
"kind": "class",
87+
"members": {
88+
"instance": [],
89+
"static": []
90+
},
91+
"path": [
92+
{
93+
"name": "Foo",
94+
"kind": "class"
95+
}
96+
],
97+
"namespace": "Foo"
98+
}
99+
]

test/fixture/es6-class.output.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
2+
3+
# Foo
4+
5+
**Extends React.Component**
6+
7+
This will fail.

test/fixture/es6-class.output.md.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"type": "root",
3+
"children": [
4+
{
5+
"type": "html",
6+
"value": "<!-- Generated by documentation.js. Update this documentation by updating the source code. -->"
7+
},
8+
{
9+
"depth": 1,
10+
"type": "heading",
11+
"children": [
12+
{
13+
"type": "text",
14+
"value": "Foo"
15+
}
16+
]
17+
},
18+
{
19+
"type": "paragraph",
20+
"children": [
21+
{
22+
"type": "strong",
23+
"children": [
24+
{
25+
"type": "text",
26+
"value": "Extends "
27+
},
28+
{
29+
"type": "text",
30+
"value": "React.Component"
31+
}
32+
]
33+
}
34+
]
35+
},
36+
{
37+
"type": "paragraph",
38+
"children": [
39+
{
40+
"type": "text",
41+
"value": "This will fail.",
42+
"position": {
43+
"start": {
44+
"line": 1,
45+
"column": 1,
46+
"offset": 0
47+
},
48+
"end": {
49+
"line": 1,
50+
"column": 16,
51+
"offset": 15
52+
},
53+
"indent": []
54+
}
55+
}
56+
],
57+
"position": {
58+
"start": {
59+
"line": 1,
60+
"column": 1,
61+
"offset": 0
62+
},
63+
"end": {
64+
"line": 1,
65+
"column": 16,
66+
"offset": 15
67+
},
68+
"indent": []
69+
}
70+
}
71+
]
72+
}

0 commit comments

Comments
 (0)