build(aio): refactor the decorator doc processing (#24000)
PR Close #24000
This commit is contained in:
parent
62443b04a0
commit
d4d8125b2d
|
@ -48,64 +48,62 @@ const {mergeProperties} = require('../../helpers/utils');
|
||||||
module.exports = function mergeDecoratorDocs(log) {
|
module.exports = function mergeDecoratorDocs(log) {
|
||||||
return {
|
return {
|
||||||
$runAfter: ['processing-docs'],
|
$runAfter: ['processing-docs'],
|
||||||
$runBefore: ['docs-processed'],
|
$runBefore: ['docs-processed', 'checkContentRules'],
|
||||||
propertiesToMerge: [],
|
propertiesToMerge: [],
|
||||||
makeDecoratorCalls: [
|
makeDecoratorCalls: [
|
||||||
{type: '', description: 'toplevel', functionName: 'makeDecorator'},
|
{type: '', description: 'toplevel', functionName: 'makeDecorator'},
|
||||||
{type: 'Prop', description: 'property', functionName: 'makePropDecorator'},
|
{type: 'Prop', description: 'property', functionName: 'makePropDecorator'},
|
||||||
{type: 'Param', description: 'parameter', functionName: 'makeParamDecorator'},
|
{type: 'Param', description: 'parameter', functionName: 'makeParamDecorator'},
|
||||||
],
|
],
|
||||||
$process: function(docs) {
|
$process(docs) {
|
||||||
|
|
||||||
var makeDecoratorCalls = this.makeDecoratorCalls;
|
const decoratorDocs = Object.create(null);
|
||||||
var propertiesToMerge = this.propertiesToMerge;
|
|
||||||
var docsToMerge = Object.create(null);
|
|
||||||
|
|
||||||
docs.forEach(function(doc) {
|
// find all the decorators, signified by a call to `make...Decorator<Decorator>(metadata)`
|
||||||
|
docs.forEach(doc => {
|
||||||
const initializer = getInitializer(doc);
|
const initializer = getInitializer(doc);
|
||||||
if (initializer) {
|
if (initializer) {
|
||||||
makeDecoratorCalls.forEach(function(call) {
|
this.makeDecoratorCalls.forEach(function(call) {
|
||||||
// find all the decorators, signified by a call to `make...Decorator<Decorator>(metadata)`
|
|
||||||
if (initializer.expression && initializer.expression.text === call.functionName) {
|
if (initializer.expression && initializer.expression.text === call.functionName) {
|
||||||
log.debug('mergeDecoratorDocs: found decorator', doc.docType, doc.name);
|
|
||||||
doc.docType = 'decorator';
|
|
||||||
doc.decoratorLocation = call.description;
|
|
||||||
// Get the type of the decorator metadata from the first "type" argument of the call.
|
// Get the type of the decorator metadata from the first "type" argument of the call.
|
||||||
// For example the `X` of `createDecorator<X>(...)`.
|
// For example the `X` of `createDecorator<X>(...)`.
|
||||||
doc.decoratorType = initializer.arguments[0].text;
|
const decoratorType = initializer.arguments[0].text;
|
||||||
// clear the symbol type named since it is not needed
|
|
||||||
doc.symbolTypeName = undefined;
|
|
||||||
|
|
||||||
// keep track of the names of the metadata interface that will need to be merged into this decorator doc
|
log.debug('mergeDecoratorDocs: found decorator', doc.docType, doc.name, decoratorType);
|
||||||
docsToMerge[doc.name + 'Decorator'] = doc;
|
|
||||||
|
doc.docType = 'decorator';
|
||||||
|
doc.decoratorLocation = call.description;
|
||||||
|
doc.decoratorType = decoratorType;
|
||||||
|
|
||||||
|
decoratorDocs[doc.name + 'Decorator'] = doc;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// merge the metadata docs into the decorator docs
|
// merge the info from the associated metadata interfaces into the decorator docs
|
||||||
docs = docs.filter(function(doc) {
|
docs = docs.filter(doc => {
|
||||||
if (docsToMerge[doc.name]) {
|
if (decoratorDocs[doc.name]) {
|
||||||
|
|
||||||
// We have found an `XxxDecorator` document that will hold the call signature of the decorator
|
// We have found an `XxxDecorator` document that will hold the call signature of the decorator
|
||||||
var decoratorDoc = docsToMerge[doc.name];
|
var decoratorDoc = decoratorDocs[doc.name];
|
||||||
var callMember = doc.members.filter(function(member) { return member.isCallMember; })[0];
|
var callMember = doc.members.find(member => member.isCallMember);
|
||||||
|
|
||||||
log.debug(
|
log.debug(
|
||||||
'mergeDecoratorDocs: merging', doc.name, 'into', decoratorDoc.name,
|
'mergeDecoratorDocs: merging', doc.name, 'into', decoratorDoc.name,
|
||||||
callMember.description.substring(0, 50));
|
callMember.description.substring(0, 50));
|
||||||
|
|
||||||
// Merge the documentation found in this call signature into the original decorator
|
// Merge the documentation found in this call signature into the original decorator
|
||||||
mergeProperties(decoratorDoc, callMember, propertiesToMerge);
|
mergeProperties(decoratorDoc, callMember, this.propertiesToMerge);
|
||||||
|
|
||||||
// remove doc from its module doc's exports
|
// remove doc from its module doc's exports
|
||||||
doc.moduleDoc.exports =
|
doc.moduleDoc.exports = doc.moduleDoc.exports.filter(exportDoc => exportDoc !== doc);
|
||||||
doc.moduleDoc.exports.filter(function(exportDoc) { return exportDoc !== doc; });
|
|
||||||
|
|
||||||
|
|
||||||
// remove from the overall list of docs to be rendered
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
return !decoratorDocs[doc.name];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return docs;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue