wiki.techinc.nl/jsdoc-plugin-allow-dots-in-modules.js
Bartosz Dziewoński ef6df58855 jsdoc: Support dots in '@module <name>' and '@exports <name>'
JSDoc mangles dots in '@module <name>' and '@exports <name>'
annotations: https://github.com/jsdoc/jsdoc/issues/1157
Work around this bug with a small plugin.

Update '@link', '@memberof' etc. annotations that had to be written
using incorrect names to work. (Those annotations are not affected by
the bug, so we had to mangle them by hand.)

Bug: T356913
Change-Id: I68bfb7be0f7d1d49901a1d5ceebc618771380b35
2024-02-07 20:41:54 +00:00

28 lines
927 B
JavaScript

'use strict';
// We can use .replaceAll since Node.js 15
/* eslint-disable es-x/no-string-prototype-replaceall */
/**
* JSDoc incorrectly handles dots in 'module' annotations. When the module name includes any dots,
* it removes everything up to the last dot. This makes no sense because file names (and MediaWiki
* module names) can contain dots. https://github.com/jsdoc/jsdoc/issues/1157
*
* To work around this bug, replace dots with special markers before JSDoc parses the code,
* and then replace them back after it has parsed the code.
*/
exports.handlers = {
beforeParse: function ( e ) {
e.source = e.source.replaceAll( /@(module|exports) .+/g, function ( m ) {
return m.replaceAll( '.', '(DOT)' );
} );
},
newDoclet: function ( e ) {
for ( const key in e.doclet ) {
if ( typeof e.doclet[ key ] === 'string' ) {
e.doclet[ key ] = e.doclet[ key ].replaceAll( '(DOT)', '.' );
}
}
}
};