mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
build: fix duplicate members in dgeni docs (#4956)
Recently Dgeni switch to a more recent version of TypeScript and now getters and setters are counting as individual members. This causes different properties to show up twice in the API docs. Fixes this temporary by filtering duplicate member docs. Also removes the inhertied docs processor since it doesn't work and needs some more work in the `dgeni-packages` repository. Fixes #4923
This commit is contained in:
committed by
Andrew Seguin
parent
98ce6357d3
commit
84c80ec0d6
+1
-1
@@ -61,7 +61,7 @@
|
||||
"chalk": "^1.1.3",
|
||||
"conventional-changelog": "^1.1.3",
|
||||
"dgeni": "^0.4.7",
|
||||
"dgeni-packages": "^0.19.0",
|
||||
"dgeni-packages": "^0.19.1",
|
||||
"firebase": "^4.0.0",
|
||||
"firebase-admin": "^5.0.0",
|
||||
"firebase-tools": "^3.9.0",
|
||||
|
||||
@@ -35,8 +35,6 @@ const dgeniPackageDeps = [
|
||||
|
||||
let apiDocsPackage = new DgeniPackage('material2-api-docs', dgeniPackageDeps)
|
||||
|
||||
.processor(require('./processors/link-inherited-docs'))
|
||||
|
||||
// Processor that filters out symbols that should not be shown in the docs.
|
||||
.processor(require('./processors/docs-private-filter'))
|
||||
|
||||
|
||||
@@ -33,9 +33,9 @@ module.exports = function categorizer() {
|
||||
* - Identifies directives, services or NgModules and marks them them in class-doc.
|
||||
*/
|
||||
function decorateClassDoc(classDoc) {
|
||||
// Resolve all methods and properties from the classDoc. Includes inherited docs.
|
||||
classDoc.methods = resolveMethods(classDoc);
|
||||
classDoc.properties = resolveProperties(classDoc);
|
||||
// Resolve all methods and properties from the classDoc.
|
||||
classDoc.methods = classDoc.members.filter(isMethod).filter(filterDuplicateMembers);
|
||||
classDoc.properties = classDoc.members.filter(isProperty).filter(filterDuplicateMembers);
|
||||
|
||||
// Call decorate hooks that can modify the method and property docs.
|
||||
classDoc.methods.forEach(doc => decorateMethodDoc(doc));
|
||||
@@ -64,7 +64,7 @@ module.exports = function categorizer() {
|
||||
decoratePublicDoc(methodDoc);
|
||||
|
||||
// Mark methods with a `void` return type so we can omit show the return type in the docs.
|
||||
methodDoc.showReturns = methodDoc.returnType && methodDoc.returnType != 'void';
|
||||
methodDoc.showReturns = methodDoc.returnType && methodDoc.returnType !== 'void';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,29 +90,11 @@ module.exports = function categorizer() {
|
||||
}
|
||||
};
|
||||
|
||||
/** Walks through all inherited docs and collects public methods. */
|
||||
function resolveMethods(classDoc) {
|
||||
let methods = classDoc.members.filter(isMethod);
|
||||
|
||||
if (classDoc.inheritedDoc) {
|
||||
methods = methods.concat(resolveMethods(classDoc.inheritedDoc));
|
||||
}
|
||||
|
||||
return methods;
|
||||
/** Filters any duplicate classDoc members from an array */
|
||||
function filterDuplicateMembers(item, _index, array) {
|
||||
return array.filter((memberDoc, i) => memberDoc.name === item.name)[0] === item;
|
||||
}
|
||||
|
||||
/** Walks through all inherited docs and collects public properties. */
|
||||
function resolveProperties(classDoc) {
|
||||
let properties = classDoc.members.filter(isProperty);
|
||||
|
||||
if (classDoc.inheritedDoc) {
|
||||
properties = properties.concat(resolveProperties(classDoc.inheritedDoc));
|
||||
}
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The `parameters` property are the parameters extracted from TypeScript and are strings
|
||||
* of the form "propertyName: propertyType" (literally what's written in the source).
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user