Skip to content

Commit 352d538

Browse files
committed
jsdoc - added namealias
The namealias plugin gets jsdoc to detect lots of documentation it was not correctly picking up due to the application of the `name` property. This can be read about in jsdoc/jsdoc#804 (comment) - this results in _much_ more complete documentation generation, especially when properties are defined in constructors.
1 parent 6203ae0 commit 352d538

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

tasks/jsdoc-conf.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"includePattern": ".+\\.js(doc)?$",
3030
"excludePattern": "(^|\\/|\\\\)_"
3131
},
32-
"plugins" : [
32+
"plugins": [
33+
"./tasks/jsdoc-plugins/namealias",
3334
"./tasks/jsdoc-plugins/filterpixi",
3435
"./tasks/jsdoc-plugins/proptomember",
3536
"./tasks/jsdoc-plugins/sourceproxy",

tasks/jsdoc-plugins/namealias.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* When JSdoc encounters names it disables the automatic code inspection ability;
3+
* this is especially problematic for cases like
4+
*
5+
* > @class MyClass
6+
* > @constructor
7+
*
8+
* because the properties without an explicit @memberof or fullname are not being included in
9+
* in the newer JSDoc output.
10+
*
11+
* This is a simple plugin, as discussed https://github.com/jsdoc3/jsdoc/issues/804#event-195287680
12+
* to rewrite the @class [@constructor] to @alias @class which enables JSDoc to collect better data.
13+
*/
14+
15+
exports.handlers = {};
16+
exports.handlers.jsdocCommentFound = function (e) {
17+
18+
var raw = e.comment;
19+
20+
if (/^(\s*[*])\s*@class\b/m.exec(raw))
21+
{
22+
// @class X / @constructor -> @alias X / @class
23+
raw = raw.replace(/^(\s*[*])\s*@class\s+(\S+).*?$/mg, "$1 @alias $2\n$1 @class");
24+
raw = raw.replace(/^(\s*[*])\s*@constructor\b.*?$/mg, "$1");
25+
26+
e.comment = raw;
27+
}
28+
29+
};

0 commit comments

Comments
 (0)