diff --git a/package.json b/package.json index 20b91043cee..0671cf18b86 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tools/dgeni/index.js b/tools/dgeni/index.js index 1cffe289dc0..ea2693c618a 100644 --- a/tools/dgeni/index.js +++ b/tools/dgeni/index.js @@ -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')) diff --git a/tools/dgeni/processors/categorizer.js b/tools/dgeni/processors/categorizer.js index 91238dbf9d6..e5139c3020e 100644 --- a/tools/dgeni/processors/categorizer.js +++ b/tools/dgeni/processors/categorizer.js @@ -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). diff --git a/tools/dgeni/processors/link-inherited-docs.js b/tools/dgeni/processors/link-inherited-docs.js deleted file mode 100644 index 73a6bc8e7c6..00000000000 --- a/tools/dgeni/processors/link-inherited-docs.js +++ /dev/null @@ -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; - } -};