diff --git a/tools/dgeni/processors/categorizer.js b/tools/dgeni/processors/categorizer.js index e5139c3020e6..d10a92f9d00d 100644 --- a/tools/dgeni/processors/categorizer.js +++ b/tools/dgeni/processors/categorizer.js @@ -43,6 +43,10 @@ module.exports = function categorizer() { decoratePublicDoc(classDoc); + // Sort members + classDoc.methods.sort(sortMembers); + classDoc.properties.sort(sortMembers); + // Categorize the current visited classDoc into its Angular type. if (isDirective(classDoc)) { classDoc.isDirective = true; @@ -95,6 +99,40 @@ function filterDuplicateMembers(item, _index, array) { return array.filter((memberDoc, i) => memberDoc.name === item.name)[0] === item; } +/** Sorts members by deprecated status, member decorator, and name. */ +function sortMembers(docA, docB) { + // Sort deprecated docs to the end + if (!docA.isDeprecated && docB.isDeprecated) { + return -1; + } + + if (docA.isDeprecated && !docB.isDeprecated) { + return 1; + } + + // Sort in the order of: Inputs, Outputs, neither + if ((isDirectiveInput(docA) && !isDirectiveInput(docB)) || + (isDirectiveOutput(docA) && !isDirectiveInput(docB) && !isDirectiveOutput(docB))) { + return -1; + } + + if ((isDirectiveInput(docB) && !isDirectiveInput(docA)) || + (isDirectiveOutput(docB) && !isDirectiveInput(docA) && !isDirectiveOutput(docA))) { + return 1; + } + + // Break ties by sorting alphabetically on the name + if (docA.name < docB.name) { + return -1; + } + + if (docA.name > docB.name) { + return 1; + } + + return 0; +} + /** * The `parameters` property are the parameters extracted from TypeScript and are strings * of the form "propertyName: propertyType" (literally what's written in the source).