Skip to content

Commit 976f31f

Browse files
committed
undocumented es6 classes no longer included in output.. fixes #19
1 parent 276565e commit 976f31f

6 files changed

Lines changed: 61 additions & 68 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ var parse = require("jsdoc-parse")
225225
* [.stats](#module_jsdoc-parse--jsdocParse..ParseOptions.ParseOptions+stats) : <code>boolean</code>
226226
* [.html](#module_jsdoc-parse--jsdocParse..ParseOptions.ParseOptions+html) : <code>boolean</code>
227227
* [.conf](#module_jsdoc-parse--jsdocParse..ParseOptions.ParseOptions+conf) : <code>boolean</code>
228-
* [.sort-by](#module_jsdoc-parse--jsdocParse..ParseOptions+sort-by) : <code>array</code>
228+
* [.sort-by](#module_jsdoc-parse--jsdocParse..ParseOptions.ParseOptions+sort-by) : <code>array</code>
229229

230230
<a name="exp_module_jsdoc-parse--jsdocParse"></a>
231231
### jsdocParse([options]) ⇒ <code>[TransformStream](http://nodejs.org/api/stream.html#stream_class_stream_transform)</code> ⏏
@@ -251,7 +251,7 @@ All options for jsdoc-parse, including defaults
251251
* [.stats](#module_jsdoc-parse--jsdocParse..ParseOptions.ParseOptions+stats) : <code>boolean</code>
252252
* [.html](#module_jsdoc-parse--jsdocParse..ParseOptions.ParseOptions+html) : <code>boolean</code>
253253
* [.conf](#module_jsdoc-parse--jsdocParse..ParseOptions.ParseOptions+conf) : <code>boolean</code>
254-
* [.sort-by](#module_jsdoc-parse--jsdocParse..ParseOptions+sort-by) : <code>array</code>
254+
* [.sort-by](#module_jsdoc-parse--jsdocParse..ParseOptions.ParseOptions+sort-by) : <code>array</code>
255255

256256
<a name="module_jsdoc-parse--jsdocParse..ParseOptions.ParseOptions+src"></a>
257257
##### parseOptions.src : <code>string</code> &#124; <code>Array.&lt;string&gt;</code>
@@ -292,11 +292,12 @@ Path to a jsdoc configuration file, passed directly to `jsdoc -c`.
292292

293293
**Kind**: instance property of <code>[ParseOptions](#module_jsdoc-parse--jsdocParse..ParseOptions)</code>
294294
**Default**: <code></code>
295-
<a name="module_jsdoc-parse--jsdocParse..ParseOptions+sort-by"></a>
295+
<a name="module_jsdoc-parse--jsdocParse..ParseOptions.ParseOptions+sort-by"></a>
296296
##### parseOptions.sort-by : <code>array</code>
297297
Sort by one of more fields, e.g. `--sort-by kind category`. Pass the special value `none` to remove the default sort order.
298298

299299
**Kind**: instance property of <code>[ParseOptions](#module_jsdoc-parse--jsdocParse..ParseOptions)</code>
300+
**Default**: <code>[&quot;scope&quot;,&quot;category&quot;,&quot;kind&quot;,&quot;order&quot;]</code>
300301

301302
* * *
302303

es5/publish.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ var a = require('array-tools');
44
var transform = require('./transform');
55

66
exports.publish = function (data) {
7-
var json = data().get().filter(function (i) {
8-
if (i.kind === 'class') {
9-
return true;
10-
} else {
11-
return !i.undocumented && !/package|file/.test(i.kind);
12-
}
7+
data = data().get();
8+
data = transform.fixConstructorMemberLongnames(data);
9+
10+
var json = data.filter(function (i) {
11+
return !i.undocumented && !/package|file/.test(i.kind);
1312
});
1413

1514
json = json.map(transform.setIsExportedFlag);

es5/transform.js

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var testValue = require('test-value');
77
var data;
88
exports.createConstructor = createConstructor;
99
exports.insertConstructors = insertConstructors;
10+
exports.fixConstructorMemberLongnames = fixConstructorMemberLongnames;
1011
exports.setIsExportedFlag = setIsExportedFlag;
1112
exports.setCodename = setCodename;
1213
exports.setID = setID;
@@ -94,27 +95,10 @@ function createConstructor(class_) {
9495

9596
function insertConstructors(data) {
9697
var replacements = [];
97-
var toDelete = [];
9898

9999
data.forEach(function (identifier, index) {
100-
if (isES5Class(identifier)) {
100+
if (identifier.kind === 'class') {
101101
replacements.push({ index: index, items: createConstructor(identifier) });
102-
} else if (isES6Class(identifier)) {
103-
var es6constructor = getEs6Constructor(data, identifier);
104-
if (es6constructor) {
105-
if (!(es6constructor.description || es6constructor.params && es6constructor.params.length)) {
106-
toDelete.push(es6constructor);
107-
}
108-
es6constructor.kind = 'constructor';
109-
es6constructor.memberof = identifier.longname;
110-
var constructorChildren = a.where(data, { memberof: es6constructor.longname });
111-
constructorChildren.forEach(function (i) {
112-
i.memberof = identifier.longname;
113-
});
114-
identifier.description = identifier.classdesc;
115-
delete identifier.classdesc;
116-
delete identifier.params;
117-
}
118102
}
119103
});
120104

@@ -123,15 +107,13 @@ function insertConstructors(data) {
123107
data.splice.apply(data, spliceArgs);
124108
});
125109

126-
toDelete.forEach(function (d) {
127-
data.splice(data.indexOf(d), 1);
128-
});
129-
130110
return data;
131111
}
132112

133-
function getEs6Constructor(data, identifier) {
134-
return a.findWhere(data, isES6Constructor);
113+
function getEs6Constructor(data, parent) {
114+
return a.findWhere(data, function (i) {
115+
return isES6Constructor(i) && i.memberof === parent.longname;
116+
});
135117
}
136118
function isES5Class(identifier) {
137119
return testValue(identifier, {
@@ -178,10 +160,11 @@ function updateIDReferences(identifier, newID) {
178160
}
179161

180162
function removeQuotes(identifier) {
181-
if (identifier.name) identifier.name = identifier.name.replace(/"/g, '');
182-
if (identifier.memberof) identifier.memberof = identifier.memberof.replace(/"/g, '');
183-
if (identifier.longname) identifier.longname = identifier.longname.replace(/"/g, '');
184-
if (identifier.id) identifier.id = identifier.id.replace(/"/g, '');
163+
var re = /["']/g;
164+
if (identifier.name) identifier.name = identifier.name.replace(re, '');
165+
if (identifier.memberof) identifier.memberof = identifier.memberof.replace(re, '');
166+
if (identifier.longname) identifier.longname = identifier.longname.replace(re, '');
167+
if (identifier.id) identifier.id = identifier.id.replace(re, '');
185168
return identifier;
186169
}
187170

@@ -329,4 +312,19 @@ function removeMemberofFromModule(identifier) {
329312
delete identifier.scope;
330313
}
331314
return identifier;
315+
}
316+
317+
function fixConstructorMemberLongnames(data) {
318+
data.forEach(function (i) {
319+
if (isES6Class(i)) {
320+
var es6constructor = getEs6Constructor(data, i);
321+
if (es6constructor) {
322+
var constructorChildren = a.where(data, { memberof: es6constructor.longname });
323+
constructorChildren.forEach(function (child) {
324+
child.memberof = i.longname;
325+
});
326+
}
327+
}
328+
});
329+
return data;
332330
}

lib/jsdoc-parse.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ class ParseOptions {
7575

7676
/**
7777
* Sort by one of more fields, e.g. `--sort-by kind category`. Pass the special value `none` to remove the default sort order.
78-
* @member module:jsdoc-parse~ParseOptions#sort-by
7978
* @type {array}
8079
* @default
8180
*/

lib/publish.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ This is a jsdoc plugin. It transforms jsdoc format data to the preferred jsdoc-p
88
@param {object} opts - An object with options information.
99
*/
1010
exports.publish = function (data) {
11-
let json = data().get().filter(i => {
12-
if (i.kind === 'class') {
13-
return true
14-
} else {
15-
return !i.undocumented && !/package|file/.test(i.kind)
16-
}
11+
data = data().get()
12+
data = transform.fixConstructorMemberLongnames(data)
13+
14+
let json = data.filter(i => {
15+
return !i.undocumented && !/package|file/.test(i.kind)
1716
})
1817

1918
json = json.map(transform.setIsExportedFlag)

lib/transform.js

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const testValue = require('test-value')
66
var data
77
exports.createConstructor = createConstructor
88
exports.insertConstructors = insertConstructors
9+
exports.fixConstructorMemberLongnames = fixConstructorMemberLongnames
910
exports.setIsExportedFlag = setIsExportedFlag
1011
exports.setCodename = setCodename
1112
exports.setID = setID
@@ -107,27 +108,10 @@ function createConstructor (class_) {
107108
/* split each class found into two new items, then re-insert them over the original class */
108109
function insertConstructors (data) {
109110
var replacements = []
110-
var toDelete = []
111111

112112
data.forEach(function (identifier, index) {
113-
if (isES5Class(identifier)) {
113+
if (identifier.kind === 'class') {
114114
replacements.push({ index: index, items: createConstructor(identifier) })
115-
} else if (isES6Class(identifier)) {
116-
const es6constructor = getEs6Constructor(data, identifier)
117-
if (es6constructor) {
118-
if (!(es6constructor.description || (es6constructor.params && es6constructor.params.length))) {
119-
toDelete.push(es6constructor)
120-
}
121-
es6constructor.kind = 'constructor'
122-
es6constructor.memberof = identifier.longname
123-
const constructorChildren = a.where(data, { memberof: es6constructor.longname })
124-
constructorChildren.forEach(i => {
125-
i.memberof = identifier.longname
126-
})
127-
identifier.description = identifier.classdesc
128-
delete identifier.classdesc
129-
delete identifier.params
130-
}
131115
}
132116
})
133117

@@ -136,16 +120,14 @@ function insertConstructors (data) {
136120
data.splice.apply(data, spliceArgs)
137121
})
138122

139-
toDelete.forEach(d => {
140-
data.splice(data.indexOf(d), 1)
141-
})
142-
143123
return data
144124
}
145125

146126
/* unfortunately the jsdoc data structure differs between es5 and es6 classes, hence the need for these four functions */
147-
function getEs6Constructor (data, identifier) {
148-
return a.findWhere(data, isES6Constructor)
127+
function getEs6Constructor (data, parent) {
128+
return a.findWhere(data, i => {
129+
return isES6Constructor(i) && i.memberof === parent.longname
130+
})
149131
}
150132
function isES5Class (identifier) {
151133
return testValue(identifier, {
@@ -353,3 +335,18 @@ function removeMemberofFromModule (identifier) {
353335
}
354336
return identifier
355337
}
338+
339+
function fixConstructorMemberLongnames (data) {
340+
data.forEach(i => {
341+
if (isES6Class(i)) {
342+
const es6constructor = getEs6Constructor(data, i)
343+
if (es6constructor) {
344+
const constructorChildren = a.where(data, { memberof: es6constructor.longname })
345+
constructorChildren.forEach(child => {
346+
child.memberof = i.longname
347+
})
348+
}
349+
}
350+
})
351+
return data
352+
}

0 commit comments

Comments
 (0)