-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: show inherited members in dgeni (#3599)
* build: show inherited members in dgeni * Introduced a new Dgeni processor that will take care of the inherited docs for TypeScript classes. * Cleaned up the categorizer processor and made it compatible with the `inherited-docs` processor. * Fixes that the `docs-private-filter` processor doesn't filter the referenced members in the class docs. This basically allows us to extend other classes in our components like in #3036 * Handle private-docs param for all docs. * Address comments * Address feedback
- Loading branch information
1 parent
91aafff
commit 5f3abae
Showing
4 changed files
with
145 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Processor that iterates through all class docs and determines if a class inherits | ||
* another class. Inherited class-docs will be linked to the original class-doc. | ||
*/ | ||
|
||
const ts = require('typescript'); | ||
|
||
module.exports = function linkInheritedDocs(readTypeScriptModules, tsParser) { | ||
|
||
let checker = null; | ||
|
||
return { | ||
$runAfter: ['readTypeScriptModules'], | ||
$runBefore: ['categorizer'], | ||
$process: processDocs, | ||
}; | ||
|
||
function processDocs(docs) { | ||
// Use the configuration from the `readTypeScriptModules` processor. | ||
let {sourceFiles, basePath} = readTypeScriptModules; | ||
|
||
// To be able to map the TypeScript Nodes to the according symbols we need to use the same | ||
// TypeScript configuration as in the `readTypeScriptModules` processor. | ||
checker = tsParser.parse(sourceFiles, basePath).typeChecker; | ||
|
||
// Iterate through all class docs and resolve the inherited docs. | ||
docs.filter(doc => doc.docType === 'class').forEach(classDoc => { | ||
resolveInheritedDoc(classDoc, docs); | ||
}); | ||
} | ||
|
||
function resolveInheritedDoc(classDoc, docs) { | ||
let inheritedType = resolveInheritedType(classDoc.exportSymbol); | ||
let inheritedSymbol = inheritedType && inheritedType.symbol; | ||
|
||
if (inheritedSymbol) { | ||
classDoc.inheritedSymbol = inheritedSymbol; | ||
classDoc.inheritedDoc = docs.find(doc => doc.exportSymbol === inheritedSymbol); | ||
} | ||
} | ||
|
||
function resolveInheritedType(classSymbol) { | ||
// Ensure that the symbol can be converted into a TypeScript ClassDeclaration. | ||
if (classSymbol.flags & ~ts.SymbolFlags.Class) { | ||
return; | ||
} | ||
|
||
let declaration = classSymbol.valueDeclaration || classSymbol.declarations[0]; | ||
let typeExpression = ts.getClassExtendsHeritageClauseElement(declaration); | ||
|
||
return typeExpression ? checker.getTypeAtLocation(typeExpression) : null; | ||
} | ||
}; |