@@ -83,82 +83,82 @@ function inferMembershipFromIdentifiers(comment, identifiers) {
83
83
* @param {Object } comment parsed comment
84
84
* @returns {Object } comment with membership inferred
85
85
*/
86
- function inferMembership ( comment ) {
87
- if ( comment . memberof ) {
88
- return comment ;
89
- }
90
-
91
- if ( comment . lends ) {
92
- return comment ;
93
- }
86
+ module . exports = function ( ) {
87
+ return function inferMembership ( comment ) {
88
+ if ( comment . memberof ) {
89
+ return comment ;
90
+ }
94
91
95
- var path = comment . context . ast ;
96
- var identifiers ;
97
-
98
- /*
99
- * Deal with an oddity of espree: the jsdoc comment is attached to a different
100
- * node in the two expressions `a.b = c` vs `a.b = function () {}`.
101
- */
102
- if ( n . ExpressionStatement . check ( path . node ) &&
103
- n . AssignmentExpression . check ( path . node . expression ) &&
104
- n . MemberExpression . check ( path . node . expression . left ) ) {
105
- path = path . get ( 'expression' ) . get ( 'left' ) ;
106
- }
92
+ if ( comment . lends ) {
93
+ return comment ;
94
+ }
107
95
108
- /*
109
- * Same as above but for `b: c` vs `b: function () {}`.
110
- */
111
- if ( n . Property . check ( path . node ) &&
112
- n . Identifier . check ( path . node . key ) ) {
113
- path = path . get ( 'key' ) ;
114
- }
96
+ var path = comment . context . ast ;
97
+ var identifiers ;
98
+
99
+ /*
100
+ * Deal with an oddity of espree: the jsdoc comment is attached to a different
101
+ * node in the two expressions `a.b = c` vs `a.b = function () {}`.
102
+ */
103
+ if ( n . ExpressionStatement . check ( path . node ) &&
104
+ n . AssignmentExpression . check ( path . node . expression ) &&
105
+ n . MemberExpression . check ( path . node . expression . left ) ) {
106
+ path = path . get ( 'expression' ) . get ( 'left' ) ;
107
+ }
115
108
116
- // Foo.bar = ...;
117
- // Foo.prototype.bar = ...;
118
- // Foo.bar.baz = ...;
119
- if ( n . MemberExpression . check ( path . node ) ) {
120
- identifiers = extractIdentifiers ( path ) ;
121
- if ( identifiers . length >= 2 ) {
122
- inferMembershipFromIdentifiers ( comment , identifiers . slice ( 0 , - 1 ) ) ;
109
+ /*
110
+ * Same as above but for `b: c` vs `b: function () {}`.
111
+ */
112
+ if ( n . Property . check ( path . node ) &&
113
+ n . Identifier . check ( path . node . key ) ) {
114
+ path = path . get ( 'key' ) ;
123
115
}
124
- }
125
116
126
- // /** @lends Foo */{ bar: ... }
127
- if ( n . Identifier . check ( path . node ) &&
128
- n . Property . check ( path . parent . node ) &&
129
- n . ObjectExpression . check ( path . parent . parent . node ) ) {
130
- // The @lends comment is sometimes attached to the first property rather than
131
- // the object expression itself.
132
- identifiers = findLendsIdentifiers ( path . parent . parent . node ) ||
133
- findLendsIdentifiers ( path . parent . parent . node . properties [ 0 ] ) ;
134
- if ( identifiers ) {
135
- inferMembershipFromIdentifiers ( comment , identifiers ) ;
117
+ // Foo.bar = ...;
118
+ // Foo.prototype.bar = ...;
119
+ // Foo.bar.baz = ...;
120
+ if ( n . MemberExpression . check ( path . node ) ) {
121
+ identifiers = extractIdentifiers ( path ) ;
122
+ if ( identifiers . length >= 2 ) {
123
+ inferMembershipFromIdentifiers ( comment , identifiers . slice ( 0 , - 1 ) ) ;
124
+ }
136
125
}
137
- }
138
126
139
- // Foo = { bar: ... };
140
- // Foo.prototype = { bar: ... };
141
- // Foo.bar = { baz: ... };
142
- if ( n . Identifier . check ( path . node ) &&
127
+ // /** @lends Foo */{ bar: ... }
128
+ if ( n . Identifier . check ( path . node ) &&
143
129
n . Property . check ( path . parent . node ) &&
144
- n . ObjectExpression . check ( path . parent . parent . node ) &&
145
- n . AssignmentExpression . check ( path . parent . parent . parent . node ) ) {
146
- identifiers = extractIdentifiers ( path . parent . parent . parent ) ;
147
- if ( identifiers . length >= 1 ) {
148
- inferMembershipFromIdentifiers ( comment , identifiers ) ;
130
+ n . ObjectExpression . check ( path . parent . parent . node ) ) {
131
+ // The @lends comment is sometimes attached to the first property rather than
132
+ // the object expression itself.
133
+ identifiers = findLendsIdentifiers ( path . parent . parent . node ) ||
134
+ findLendsIdentifiers ( path . parent . parent . node . properties [ 0 ] ) ;
135
+ if ( identifiers ) {
136
+ inferMembershipFromIdentifiers ( comment , identifiers ) ;
137
+ }
149
138
}
150
- }
151
139
152
- // var Foo = { bar: ... }
153
- if ( n . Identifier . check ( path . node ) &&
154
- n . Property . check ( path . parent . node ) &&
155
- n . ObjectExpression . check ( path . parent . parent . node ) &&
156
- n . VariableDeclarator . check ( path . parent . parent . parent . node ) ) {
157
- identifiers = [ path . parent . parent . parent . node . id . name ] ;
158
- inferMembershipFromIdentifiers ( comment , identifiers ) ;
159
- }
140
+ // Foo = { bar: ... };
141
+ // Foo.prototype = { bar: ... };
142
+ // Foo.bar = { baz: ... };
143
+ if ( n . Identifier . check ( path . node ) &&
144
+ n . Property . check ( path . parent . node ) &&
145
+ n . ObjectExpression . check ( path . parent . parent . node ) &&
146
+ n . AssignmentExpression . check ( path . parent . parent . parent . node ) ) {
147
+ identifiers = extractIdentifiers ( path . parent . parent . parent ) ;
148
+ if ( identifiers . length >= 1 ) {
149
+ inferMembershipFromIdentifiers ( comment , identifiers ) ;
150
+ }
151
+ }
160
152
161
- return comment ;
162
- }
153
+ // var Foo = { bar: ... }
154
+ if ( n . Identifier . check ( path . node ) &&
155
+ n . Property . check ( path . parent . node ) &&
156
+ n . ObjectExpression . check ( path . parent . parent . node ) &&
157
+ n . VariableDeclarator . check ( path . parent . parent . parent . node ) ) {
158
+ identifiers = [ path . parent . parent . parent . node . id . name ] ;
159
+ inferMembershipFromIdentifiers ( comment , identifiers ) ;
160
+ }
163
161
164
- module . exports = inferMembership ;
162
+ return comment ;
163
+ } ;
164
+ }
0 commit comments