@ckeditor/typedoc-plugins
Version:
Various TypeDoc plugins developed by the CKEditor 5 team.
49 lines (39 loc) • 1.17 kB
JavaScript
/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/
;
const { Converter } = require( 'typedoc' );
/**
* The `typedoc-plugin-symbol-fixer` plugin renames `Symbol.*` definitions with the JSDoc style.
*
* * Typedoc: `[iterator]() → Iterator`
* * JSDoc: `Symbol.iterator() → Iterator`
*/
module.exports = {
load( app ) {
app.converter.on( Converter.EVENT_CREATE_DECLARATION, onEventCreateDeclaration() );
}
};
function onEventCreateDeclaration() {
return ( context, reflection ) => {
if ( !isWrappedInSquareBrackets( reflection.name ) ) {
return;
}
const symbolName = reflection.name.slice( 1, -1 );
if ( Symbol[ symbolName ] ) {
reflection.name = `Symbol.${ symbolName }`;
} else {
const symbol = context.project.getSymbolFromReflection( reflection );
const node = symbol.declarations[ 0 ];
context.logger.warn( 'Non-symbol wrapped in square brackets', node );
}
};
}
/**
* @param {String} value
* @returns {Boolean}
*/
function isWrappedInSquareBrackets( value ) {
return value.startsWith( '[' ) && value.endsWith( ']' );
}