From fa6aa1be5561597e43bbde8ee14d5dbdcd910137 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Wed, 6 Oct 2021 13:52:33 +0100 Subject: [PATCH] build(docs-infra): ensure all overloads are shown in interfaces (#43734) In the API docs, concrete classes do not list the "implementation" overload on a method, since this is not strictly part of its API. We recently fixed the rendering of interfaces to display all the overloads, since there is no "implementation" overload. This commit also fixes the rendering of "pseudo-classes", which are a combination of an interface and a constant. Fixes #43001 PR Close #43734 --- aio/tests/e2e/src/api-pages.e2e-spec.ts | 5 +++++ .../processors/processPseudoClasses.js | 20 +++++++++++++++++-- .../processors/processPseudoClasses.spec.js | 2 +- .../templates/api/lib/memberHelpers.html | 2 +- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/aio/tests/e2e/src/api-pages.e2e-spec.ts b/aio/tests/e2e/src/api-pages.e2e-spec.ts index e6130860a37..07d68a9d969 100644 --- a/aio/tests/e2e/src/api-pages.e2e-spec.ts +++ b/aio/tests/e2e/src/api-pages.e2e-spec.ts @@ -81,4 +81,9 @@ describe('Api pages', () => { await page.navigateTo('api/core/testing/TestBedStatic'); expect(await (await page.getInstanceMethodOverloads('initTestEnvironment')).length).toEqual(2); }); + + it('should show all overloads of pseudo-class methods', async () => { + await page.navigateTo('api/core/testing/TestBed'); + expect(await (await page.getInstanceMethodOverloads('initTestEnvironment')).length).toEqual(2); + }); }); diff --git a/aio/tools/transforms/angular-api-package/processors/processPseudoClasses.js b/aio/tools/transforms/angular-api-package/processors/processPseudoClasses.js index 9a51ce842e5..8d8c2e9a9be 100644 --- a/aio/tools/transforms/angular-api-package/processors/processPseudoClasses.js +++ b/aio/tools/transforms/angular-api-package/processors/processPseudoClasses.js @@ -1,12 +1,28 @@ +/** + * @dgProcessor processPseudoClasses + * @description + * If an API element is declared both as a `const` and an `interface` then these are both merged + * into a single `interface` document. + * + * We can identify such cases because the interface doc has one or more items in the + * `additionalDeclarations` property. + * + * This processor will convert such interface docs to class docs and ensure that the content and + * members are fixed up appropriately. + * + * Such pseudo classes should have overloaded members rendered similar to interfaces (i.e. all + * overloads are rendered whereas in classes the "implementation overload" is not rendered) we + * also mark the doc with the `isPseudoClass` property to be used in templates when rendering. + */ module.exports = function processPseudoClasses(tsHost) { return { $runAfter: ['readTypeScriptModules'], $runBefore: ['parsing-tags'], $process(docs) { docs.forEach(doc => { - if (doc.docType === 'interface' && doc.additionalDeclarations && - doc.additionalDeclarations.length > 0) { + if (doc.docType === 'interface' && doc.additionalDeclarations?.length > 0) { doc.docType = 'class'; + doc.isPseudoClass = true; const additionalContent = tsHost.getContent(doc.additionalDeclarations[0]); if (!doc.content || doc.content === '@publicApi' && additionalContent) { doc.content = additionalContent; diff --git a/aio/tools/transforms/angular-api-package/processors/processPseudoClasses.spec.js b/aio/tools/transforms/angular-api-package/processors/processPseudoClasses.spec.js index 3913f6448bf..572ee52c97f 100644 --- a/aio/tools/transforms/angular-api-package/processors/processPseudoClasses.spec.js +++ b/aio/tools/transforms/angular-api-package/processors/processPseudoClasses.spec.js @@ -32,7 +32,7 @@ describe('processPseudoClasses processor', () => { jasmine.objectContaining({docType: 'interface', id: 'd'}), // This is the only one that changes - jasmine.objectContaining({docType: 'class', id: 'e'}), + jasmine.objectContaining({docType: 'class', id: 'e', isPseudoClass: true}), jasmine.objectContaining({docType: 'const', id: 'f'}), jasmine.objectContaining({docType: 'const', id: 'g'}), diff --git a/aio/tools/transforms/templates/api/lib/memberHelpers.html b/aio/tools/transforms/templates/api/lib/memberHelpers.html index 17e7694ff84..1f21eda6354 100644 --- a/aio/tools/transforms/templates/api/lib/memberHelpers.html +++ b/aio/tools/transforms/templates/api/lib/memberHelpers.html @@ -123,7 +123,7 @@ {%- elseif method.overloads.length < 3 -%} - {%- if method.isAbstract or method.containerDoc.docType === 'interface' %} + {%- if method.isAbstract or method.containerDoc.docType === 'interface' or method.containerDoc.isPseudoClass %} {$ renderOverloadInfo(method, cssClass + '-overload', method) $}