Skip to content

Commit cc8c294

Browse files
committed
jsdoc - namealias fix
Corrected the namealias jsdoc plugin to not include PIXI-from-YUI docs. This is because they lack corresponding javascript code and need the 'name' property to remain intact.
1 parent 152b26a commit cc8c294

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

tasks/jsdoc-plugins/namealias.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,31 @@
1212
* to rewrite the @class [@constructor] to @alias @class which enables JSDoc to collect better data.
1313
*/
1414

15+
// Regular expression to match a line starting with what appears to be a doclet tag.
16+
// This only works for solo single-line doclet tags. The line start is captured in $1,
17+
// the doclet tag in $2 and everything else in $3.
18+
var extract = /^(\s*(?:\/\*{2,}|\*{1,})\s*)(@\w+)\s*?([^\r\n]*)/mg;
19+
1520
exports.handlers = {};
1621
exports.handlers.jsdocCommentFound = function (e) {
1722

1823
var raw = e.comment;
1924

20-
var m = /^(\s*[*])\s*@class\b/m.exec(raw);
21-
if (m)
25+
var classdoc = /@class\b/.exec(raw);
26+
var sourcefile = /@sourcefile\b/.exec(raw);
27+
28+
// PIXI docs generated from YUIDocs have @sourcefile (but no code) and need to be excluded
29+
if (classdoc && !sourcefile)
2230
{
23-
// @class X -> @alias X / @class
24-
raw = raw.replace(/^(\s*[*])\s*@class[ \t]+(\S+).*?((?=[\r\n]+))/mg, "$1 @alias $2$3$1 @class");
25-
// @constructor -> {removed}
26-
raw = raw.replace(/^(\s*[*])\s*@constructor\b.*?(?=[\r\n]+)/mg, "$1");
31+
raw = raw.replace(extract, function (m, pre, doclet, extra) {
32+
if (doclet === '@class' && extra.trim()) {
33+
return pre + '@alias ' + extra.trim() + '\n' + pre + '@class';
34+
} else if (doclet === '@constructor') {
35+
return '';
36+
} else {
37+
return m;
38+
}
39+
});
2740

2841
e.comment = raw;
2942
}

0 commit comments

Comments
 (0)