-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplugin.js
25 lines (25 loc) · 1.2 KB
/
plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* Converts TypeScript intersection types (joined with an "&") to a JSDoc type union "|" allowing the file to be
* processed downstream. This allows you to use the amperstand "&" in your code.
*
* Specifically, this creates a compatibility between Visual Studio Code's TypeScript documentation and JSDoc, as
* Visual Studio Code's parser uses amperstands for type unions, and JSDoc uses pipes.
* @module intersection
*/
exports.handlers = {
jsdocCommentFound(jsdocComment, parser) {
let tags = ['augments', 'extends', 'type', 'mixes', 'property', 'prop', 'param', 'typedef', 'returns'];
for (let tag of tags) {
let r = new RegExp('^.+@' + tag + '\\s*\\{(?:.+&.+)\\s*\\}', 'gm');
let match = r.exec(jsdocComment.comment);
while (match && match.length) {
let len = match[0].length;
let before = jsdocComment.comment.substr(0, match.index);
let after = jsdocComment.comment.substr(match.index + len);
let replaced = match[0].replace(/&/g, '|');
jsdocComment.comment = before + replaced + after;
match = r.exec(jsdocComment.comment);
}
}
}
};