From 321c01d7232d2d6c845da24b4235bfa167481f0c Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Fri, 5 Oct 2018 20:09:50 +0200 Subject: [PATCH] build(docs): deprecated state of type alias not showing up (#13449) * Currently if a type alias is marked as `@deprecated`, we don't add an indication as for the constants. Now a similar indication will be added if a type alias is deprecated. * Similarly to the constants and `angular.io`, we will display the actual type of the `type-alias` in a better-looking & more clear way. * Also fixes that the constant code "overview" does not include the trailing semicolon (Angular.io also adds a trailing semicolon) --- tools/dgeni/common/dgeni-definitions.ts | 4 ++++ tools/dgeni/processors/categorizer.ts | 13 +++++++++++++ tools/dgeni/templates/constant.template.html | 2 +- tools/dgeni/templates/type-alias.template.html | 17 +++++++++++++---- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/tools/dgeni/common/dgeni-definitions.ts b/tools/dgeni/common/dgeni-definitions.ts index 57e66638e89..85d27b9b466 100644 --- a/tools/dgeni/common/dgeni-definitions.ts +++ b/tools/dgeni/common/dgeni-definitions.ts @@ -3,6 +3,7 @@ import {ClassExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassExpor import {ClassLikeExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassLikeExportDoc'; import {ConstExportDoc} from 'dgeni-packages/typescript/api-doc-types/ConstExportDoc'; import {PropertyMemberDoc} from 'dgeni-packages/typescript/api-doc-types/PropertyMemberDoc'; +import {TypeAliasExportDoc} from 'dgeni-packages/typescript/api-doc-types/TypeAliasExportDoc'; import {ParsedDecorator} from 'dgeni-packages/typescript/services/TsParser/getDecorators'; import {FunctionExportDoc} from 'dgeni-packages/typescript/api-doc-types/FunctionExportDoc'; import {MethodMemberDoc} from 'dgeni-packages/typescript/api-doc-types/MethodMemberDoc'; @@ -55,3 +56,6 @@ export interface CategorizedFunctionExportDoc /** Extended Dgeni const export document that simplifies logic for the Dgeni template. */ export interface CategorizedConstExportDoc extends ConstExportDoc, DeprecationDoc {} + +/** Extended Dgeni type alias document that includes more information when rendering. */ +export interface CategorizedTypeAliasExportDoc extends TypeAliasExportDoc, DeprecationDoc {} diff --git a/tools/dgeni/processors/categorizer.ts b/tools/dgeni/processors/categorizer.ts index 8926f4fa808..573f3758217 100644 --- a/tools/dgeni/processors/categorizer.ts +++ b/tools/dgeni/processors/categorizer.ts @@ -16,6 +16,7 @@ import { CategorizedFunctionExportDoc, CategorizedMethodMemberDoc, CategorizedPropertyMemberDoc, + CategorizedTypeAliasExportDoc, } from '../common/dgeni-definitions'; import {getDirectiveMetadata} from '../common/directive-metadata'; import {normalizeFunctionParameters} from '../common/normalize-function-parameters'; @@ -47,6 +48,10 @@ export class Categorizer implements Processor { docs .filter(doc => doc.docType === 'const') .forEach(doc => this.decorateConstExportDoc(doc)); + + docs + .filter(doc => doc.docType === 'type-alias') + .forEach(doc => this.decorateTypeAliasExportDoc(doc)); } /** @@ -130,6 +135,14 @@ export class Categorizer implements Processor { decorateDeprecatedDoc(doc); } + /** + * Method that will be called for each type-alias export document. We decorate the type-alias + * documents with a property that states whether the type-alias is deprecated or not. + */ + private decorateTypeAliasExportDoc(doc: CategorizedTypeAliasExportDoc) { + decorateDeprecatedDoc(doc); + } + /** * Method that will be called for each property doc. Properties that are Angular inputs or * outputs will be marked. Aliases for the inputs or outputs will be stored as well. diff --git a/tools/dgeni/templates/constant.template.html b/tools/dgeni/templates/constant.template.html index 67021c2c7f5..c54b29a0b38 100644 --- a/tools/dgeni/templates/constant.template.html +++ b/tools/dgeni/templates/constant.template.html @@ -18,7 +18,7 @@
 
 {%- highlight "typescript" -%}
-  const {$ constant.name | safe $}: {$ constant.type | safe $}
+  const {$ constant.name | safe $}: {$ constant.type | safe $};
 {%- end_highlight -%}
 
 
diff --git a/tools/dgeni/templates/type-alias.template.html b/tools/dgeni/templates/type-alias.template.html index 0a83a682acf..d1241c8ae91 100644 --- a/tools/dgeni/templates/type-alias.template.html +++ b/tools/dgeni/templates/type-alias.template.html @@ -5,11 +5,20 @@ {$ alias.name $} +{%- if alias.isDeprecated -%} +
+ Deprecated +
+{%- endif -%} + {%- if alias.description -%}

{$ alias.description | marked | safe $}

{%- endif -%} -

- Type: - {$ alias.typeDefinition $} -

+
+
+{%- highlight "typescript" -%}
+  type {$ alias.name | safe $} = {$ alias.typeDefinition | safe $};
+{%- end_highlight -%}
+
+