-
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
* 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
- Loading branch information
1 parent
aa3360a
commit 4470b7d
Showing
4 changed files
with
122 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,45 @@ | ||
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 => visitClassDoc(classDoc, docs)); | ||
} | ||
|
||
function visitClassDoc(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) { | ||
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; | ||
} | ||
}; |