File tree Expand file tree Collapse file tree 5 files changed +236
-0
lines changed Expand file tree Collapse file tree 5 files changed +236
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,10 @@ module.exports = function () {
31
31
comment . name = node . name ;
32
32
return true ;
33
33
}
34
+ if ( node && node . type === 'StringLiteral' && node . value ) {
35
+ comment . name = node . value ;
36
+ return true ;
37
+ }
34
38
}
35
39
36
40
if ( comment . context . ast ) {
@@ -57,6 +61,21 @@ module.exports = function () {
57
61
path . stop ( ) ;
58
62
}
59
63
} ,
64
+ /**
65
+ * Attempt to extract the name from a string literal that is the `key`
66
+ * part of an ObjectProperty node. If the name can be resolved, it
67
+ * will stop traversing.
68
+ * @param {Object } path ast path
69
+ * @returns {undefined } has side-effects
70
+ * @private
71
+ */
72
+ StringLiteral : function ( path ) {
73
+ if ( path . parent . type === 'ObjectProperty' && path . node === path . parent . key ) {
74
+ if ( inferName ( path , path . node ) ) {
75
+ path . stop ( ) ;
76
+ }
77
+ }
78
+ } ,
60
79
/**
61
80
* Attempt to extract the name from an Identifier node.
62
81
* If the name can be resolved, it will stop traversing.
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @alias MyContainerObject
3
+ */
4
+ const obj = {
5
+ /**
6
+ * The foo property
7
+ */
8
+ 'foo' : {
9
+ bar : 0
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+ [
2
+ {
3
+ "description" : " " ,
4
+ "tags" : [
5
+ {
6
+ "title" : " alias" ,
7
+ "description" : null ,
8
+ "lineNumber" : 1 ,
9
+ "name" : " MyContainerObject"
10
+ }
11
+ ],
12
+ "loc" : {
13
+ "start" : {
14
+ "line" : 1 ,
15
+ "column" : 0
16
+ },
17
+ "end" : {
18
+ "line" : 3 ,
19
+ "column" : 3
20
+ }
21
+ },
22
+ "context" : {
23
+ "loc" : {
24
+ "start" : {
25
+ "line" : 4 ,
26
+ "column" : 0
27
+ },
28
+ "end" : {
29
+ "line" : 11 ,
30
+ "column" : 1
31
+ }
32
+ },
33
+ "code" : " /**\n * @alias MyContainerObject\n */\n const obj = {\n /**\n * The foo property\n */\n 'foo': {\n bar: 0\n }\n }\n "
34
+ },
35
+ "errors" : [],
36
+ "alias" : " MyContainerObject" ,
37
+ "name" : " MyContainerObject" ,
38
+ "kind" : " constant" ,
39
+ "members" : {
40
+ "instance" : [],
41
+ "static" : []
42
+ },
43
+ "path" : [
44
+ {
45
+ "name" : " MyContainerObject" ,
46
+ "kind" : " constant"
47
+ }
48
+ ],
49
+ "namespace" : " MyContainerObject"
50
+ },
51
+ {
52
+ "description" : {
53
+ "type" : " root" ,
54
+ "children" : [
55
+ {
56
+ "type" : " paragraph" ,
57
+ "children" : [
58
+ {
59
+ "type" : " text" ,
60
+ "value" : " The foo property" ,
61
+ "position" : {
62
+ "start" : {
63
+ "line" : 1 ,
64
+ "column" : 1 ,
65
+ "offset" : 0
66
+ },
67
+ "end" : {
68
+ "line" : 1 ,
69
+ "column" : 17 ,
70
+ "offset" : 16
71
+ },
72
+ "indent" : []
73
+ }
74
+ }
75
+ ],
76
+ "position" : {
77
+ "start" : {
78
+ "line" : 1 ,
79
+ "column" : 1 ,
80
+ "offset" : 0
81
+ },
82
+ "end" : {
83
+ "line" : 1 ,
84
+ "column" : 17 ,
85
+ "offset" : 16
86
+ },
87
+ "indent" : []
88
+ }
89
+ }
90
+ ],
91
+ "position" : {
92
+ "start" : {
93
+ "line" : 1 ,
94
+ "column" : 1 ,
95
+ "offset" : 0
96
+ },
97
+ "end" : {
98
+ "line" : 1 ,
99
+ "column" : 17 ,
100
+ "offset" : 16
101
+ }
102
+ }
103
+ },
104
+ "tags" : [],
105
+ "loc" : {
106
+ "start" : {
107
+ "line" : 5 ,
108
+ "column" : 2
109
+ },
110
+ "end" : {
111
+ "line" : 7 ,
112
+ "column" : 5
113
+ }
114
+ },
115
+ "context" : {
116
+ "loc" : {
117
+ "start" : {
118
+ "line" : 8 ,
119
+ "column" : 2
120
+ },
121
+ "end" : {
122
+ "line" : 10 ,
123
+ "column" : 3
124
+ }
125
+ },
126
+ "code" : " /**\n * @alias MyContainerObject\n */\n const obj = {\n /**\n * The foo property\n */\n 'foo': {\n bar: 0\n }\n }\n "
127
+ },
128
+ "errors" : [],
129
+ "name" : " foo" ,
130
+ "members" : {
131
+ "instance" : [],
132
+ "static" : []
133
+ },
134
+ "path" : [
135
+ {
136
+ "name" : " foo"
137
+ }
138
+ ],
139
+ "namespace" : " foo"
140
+ }
141
+ ]
Original file line number Diff line number Diff line change
1
+ # MyContainerObject
2
+
3
+ # foo
4
+
5
+ The foo property
Original file line number Diff line number Diff line change
1
+ {
2
+ "type" : " root" ,
3
+ "children" : [
4
+ {
5
+ "depth" : 1 ,
6
+ "type" : " heading" ,
7
+ "children" : [
8
+ {
9
+ "type" : " text" ,
10
+ "value" : " MyContainerObject"
11
+ }
12
+ ]
13
+ },
14
+ {
15
+ "depth" : 1 ,
16
+ "type" : " heading" ,
17
+ "children" : [
18
+ {
19
+ "type" : " text" ,
20
+ "value" : " foo"
21
+ }
22
+ ]
23
+ },
24
+ {
25
+ "type" : " paragraph" ,
26
+ "children" : [
27
+ {
28
+ "type" : " text" ,
29
+ "value" : " The foo property" ,
30
+ "position" : {
31
+ "start" : {
32
+ "line" : 1 ,
33
+ "column" : 1 ,
34
+ "offset" : 0
35
+ },
36
+ "end" : {
37
+ "line" : 1 ,
38
+ "column" : 17 ,
39
+ "offset" : 16
40
+ },
41
+ "indent" : []
42
+ }
43
+ }
44
+ ],
45
+ "position" : {
46
+ "start" : {
47
+ "line" : 1 ,
48
+ "column" : 1 ,
49
+ "offset" : 0
50
+ },
51
+ "end" : {
52
+ "line" : 1 ,
53
+ "column" : 17 ,
54
+ "offset" : 16
55
+ },
56
+ "indent" : []
57
+ }
58
+ }
59
+ ]
60
+ }
You can’t perform that action at this time.
0 commit comments