JSDoc externals: Parse complex types
Change-Id: Ie4166de491df0512790c2d741c873801270aea01
这个提交包含在:
父节点
511dba52e4
当前提交
9d641c0f43
|
@ -9,12 +9,24 @@ const prefixMap = wmfConf.prefixMap || {};
|
|||
const prefixMapIgnore = wmfConf.prefixMapIgnore || [];
|
||||
const linkMap = wmfConf.linkMap || {};
|
||||
|
||||
// eslint-disable-next-line n/no-missing-require
|
||||
const parseType = require( 'jsdoc/tag/type' ).parse;
|
||||
|
||||
function extractNames( parsedType, names = [] ) {
|
||||
if ( parsedType.type === 'NameExpression' ) {
|
||||
names.push( parsedType.name );
|
||||
} else if ( parsedType.type === 'TypeApplication' ) {
|
||||
parsedType.applications.forEach( ( p ) => extractNames( p, names ) );
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically register links to known external types when they are encountered
|
||||
*/
|
||||
exports.handlers = {
|
||||
newDoclet: function ( e ) {
|
||||
const types = [];
|
||||
let types = [];
|
||||
|
||||
if ( e.doclet.kind === 'class' ) {
|
||||
if ( e.doclet.augments ) {
|
||||
|
@ -65,6 +77,20 @@ exports.handlers = {
|
|||
}
|
||||
}
|
||||
|
||||
types = types.reduce( ( acc, val ) => {
|
||||
if ( /^[a-z0-9.]+$/i.test( val ) ) {
|
||||
// Optimisation: If the type is (namespaced) alphanumeric, then
|
||||
// the value itself is the type, e.g. 'foo.bar.Baz1'
|
||||
acc.push( val );
|
||||
} else {
|
||||
// A more complex type, parse and extract types recursively,
|
||||
// e.g. 'Object.<string,Foo[]>'
|
||||
const parsedType = parseType( '{' + val + '}', false, true ).parsedType;
|
||||
acc.push.apply( acc, extractNames( parsedType ) );
|
||||
}
|
||||
return acc;
|
||||
}, [] );
|
||||
|
||||
types.forEach( ( type ) => {
|
||||
Object.keys( prefixMap ).some( ( prefix ) => {
|
||||
if (
|
||||
|
|
正在加载...
在新工单中引用