From 7c730fe5b39edd8aabdf6aea89d91a4d1f36917e Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Tue, 23 Oct 2018 11:48:49 +0100 Subject: [PATCH] build(docs-infra): include inherited members in search index (#26676) Closes #23800 PR Close #26676 --- .../processors/generateKeywords.js | 12 +++++- .../processors/generateKeywords.spec.js | 40 +++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/aio/tools/transforms/angular-base-package/processors/generateKeywords.js b/aio/tools/transforms/angular-base-package/processors/generateKeywords.js index 485b44d803..07db2914ad 100644 --- a/aio/tools/transforms/angular-base-package/processors/generateKeywords.js +++ b/aio/tools/transforms/angular-base-package/processors/generateKeywords.js @@ -164,10 +164,18 @@ function extractWords(text, words, keywordMap) { } function extractMemberWords(doc, members, membersMap) { + if (!doc) return; + if (doc.members) { - doc.members.forEach(function(member) { extractWords(member.name, members, membersMap); }); + doc.members.forEach(member => extractWords(member.name, members, membersMap)); } if (doc.statics) { - doc.statics.forEach(function(member) { extractWords(member.name, members, membersMap); }); + doc.statics.forEach(member => extractWords(member.name, members, membersMap)); + } + if (doc.extendsClauses) { + doc.extendsClauses.forEach(clause => extractMemberWords(clause.doc, members, membersMap)); + } + if (doc.implementsClauses) { + doc.implementsClauses.forEach(clause => extractMemberWords(clause.doc, members, membersMap)); } } \ No newline at end of file diff --git a/aio/tools/transforms/angular-base-package/processors/generateKeywords.spec.js b/aio/tools/transforms/angular-base-package/processors/generateKeywords.spec.js index 2bf490da9a..e482ee4a1b 100644 --- a/aio/tools/transforms/angular-base-package/processors/generateKeywords.spec.js +++ b/aio/tools/transforms/angular-base-package/processors/generateKeywords.spec.js @@ -128,6 +128,46 @@ describe('generateKeywords processor', () => { ); }); + it('should add inherited member doc properties to the search terms', () => { + const processor = processorFactory(mockLogger, mockReadFilesProcessor); + const parentClass = { + docType: 'class', + name: 'ParentClass', + members: [ + { name: 'parentMember1' }, + ], + statics: [ + { name: 'parentMember2' }, + ], + }; + const parentInterface = { + docType: 'interface', + name: 'ParentInterface', + members: [ + { name: 'parentMember3' }, + ] + }; + + const childClass = { + docType: 'class', + name: 'Child', + members: [ + { name: 'childMember1' } + ], + statics: [ + { name: 'childMember2' } + ], + extendsClauses: [{ doc: parentClass }], + implementsClauses: [{ doc: parentInterface }] + }; + const docs = [childClass, parentClass, parentInterface]; + processor.$process(docs); + const keywordsDoc = docs[docs.length - 1]; + expect(keywordsDoc.data[0].members.split(' ').sort().join(' ')).toEqual( + 'childmember1 childmember2 parentmember1 parentmember2 parentmember3' + ); + }); + it('should process terms prefixed with "ng" to include the term stripped of "ng"', () => { const processor = processorFactory(mockLogger, mockReadFilesProcessor); const docs = [