@@ -10,14 +10,26 @@ import type {
1010 ComponentRegion ,
1111 EventHandler ,
1212} from './interfaces' ;
13- import type { ExpandedProp } from './extractor' ;
13+ import type { ExpandedProp , ExtractedDescription } from './extractor' ;
1414import { getObjectDefinition } from './object-definition' ;
1515
16- function getCommentTag ( property : ExpandedProp , name : string ) {
17- const tag = property . description . tags . find ( tag => tag . name === name ) ;
16+ function getCommentTag ( description : ExtractedDescription , name : string ) {
17+ const tag = description . tags . find ( tag => tag . name === name ) ;
1818 return tag ? tag . text ?? '' : undefined ;
1919}
2020
21+ function getMultipleCommentTag ( description : ExtractedDescription , name : string ) {
22+ const tags = description . tags
23+ . filter ( tag => tag . name === name )
24+ . map ( tag => {
25+ if ( ! tag . text ) {
26+ throw new Error ( `Tag ${ name } is missing text` ) ;
27+ }
28+ return tag . text ;
29+ } ) ;
30+ return tags . length > 0 ? tags : undefined ;
31+ }
32+
2133function castI18nTag ( tag : string | undefined ) {
2234 return tag === undefined ? undefined : true ;
2335}
@@ -27,6 +39,7 @@ export function buildComponentDefinition(
2739 props : Array < ExpandedProp > ,
2840 functions : Array < ExpandedProp > ,
2941 defaultValues : Record < string , string > ,
42+ componentDescription : ExtractedDescription ,
3043 checker : ts . TypeChecker
3144) : ComponentDefinition {
3245 const regions = props . filter ( prop => prop . type === 'React.ReactNode' ) ;
@@ -36,15 +49,18 @@ export function buildComponentDefinition(
3649 return {
3750 name,
3851 releaseStatus : 'stable' ,
52+ description : componentDescription . text ,
53+ systemTag : getMultipleCommentTag ( componentDescription , 'awsuiSystem' ) ,
3954 regions : regions . map (
4055 ( region ) : ComponentRegion => ( {
4156 name : region . name ,
42- displayName : getCommentTag ( region , 'displayname' ) ,
57+ displayName : getCommentTag ( region . description , 'displayname' ) ,
4358 description : region . description . text ,
4459 isDefault : region . name === 'children' ,
45- visualRefreshTag : getCommentTag ( region , 'visualrefresh' ) ,
46- deprecatedTag : getCommentTag ( region , 'deprecated' ) ,
47- i18nTag : castI18nTag ( getCommentTag ( region , 'i18n' ) ) ,
60+ systemTag : getMultipleCommentTag ( region . description , 'awsuiSystem' ) ,
61+ visualRefreshTag : getCommentTag ( region . description , 'visualrefresh' ) ,
62+ deprecatedTag : getCommentTag ( region . description , 'deprecated' ) ,
63+ i18nTag : castI18nTag ( getCommentTag ( region . description , 'i18n' ) ) ,
4864 } )
4965 ) ,
5066 functions : functions . map (
@@ -66,35 +82,41 @@ export function buildComponentDefinition(
6682 } )
6783 ) ,
6884 properties : onlyProps . map ( ( property ) : ComponentProperty => {
69- const { type, inlineType } = getObjectDefinition ( property . type , property . rawType , checker ) ;
85+ const { type, inlineType } = getObjectDefinition ( property . type , property . rawType , property . rawTypeNode , checker ) ;
7086 return {
7187 name : property . name ,
7288 type : type ,
7389 inlineType : inlineType ,
7490 optional : property . isOptional ,
7591 description : property . description . text ,
7692 defaultValue : defaultValues [ property . name ] ,
77- visualRefreshTag : getCommentTag ( property , 'visualrefresh' ) ,
78- deprecatedTag : getCommentTag ( property , 'deprecated' ) ,
79- analyticsTag : getCommentTag ( property , 'analytics' ) ,
80- i18nTag : castI18nTag ( getCommentTag ( property , 'i18n' ) ) ,
93+ systemTag : getMultipleCommentTag ( property . description , 'awsuiSystem' ) ,
94+ visualRefreshTag : getCommentTag ( property . description , 'visualrefresh' ) ,
95+ deprecatedTag : getCommentTag ( property . description , 'deprecated' ) ,
96+ analyticsTag : getCommentTag ( property . description , 'analytics' ) ,
97+ i18nTag : castI18nTag ( getCommentTag ( property . description , 'i18n' ) ) ,
8198 } ;
8299 } ) ,
83100 events : events . map ( ( event ) : EventHandler => {
84- const { detailType, detailInlineType, cancelable } = extractEventDetails ( event . rawType , checker ) ;
101+ const { detailType, detailInlineType, cancelable } = extractEventDetails (
102+ event . rawType ,
103+ event . rawTypeNode ,
104+ checker
105+ ) ;
85106 return {
86107 name : event . name ,
87108 description : event . description . text ,
88109 cancelable,
89110 detailType,
90111 detailInlineType,
91- deprecatedTag : getCommentTag ( event , 'deprecated' ) ,
112+ systemTag : getMultipleCommentTag ( event . description , 'awsuiSystem' ) ,
113+ deprecatedTag : getCommentTag ( event . description , 'deprecated' ) ,
92114 } ;
93115 } ) ,
94116 } ;
95117}
96118
97- function extractEventDetails ( type : ts . Type , checker : ts . TypeChecker ) {
119+ function extractEventDetails ( type : ts . Type , typeNode : ts . TypeNode | undefined , checker : ts . TypeChecker ) {
98120 const realType = type . getNonNullableType ( ) ;
99121 const handlerName = realType . aliasSymbol ?. getName ( ) ;
100122 if ( handlerName !== 'CancelableEventHandler' && handlerName !== 'NonCancelableEventHandler' ) {
@@ -103,7 +125,7 @@ function extractEventDetails(type: ts.Type, checker: ts.TypeChecker) {
103125 const cancelable = handlerName === 'CancelableEventHandler' ;
104126 const detailType = realType . aliasTypeArguments ?. [ 0 ] ;
105127 if ( detailType && detailType . getProperties ( ) . length > 0 ) {
106- const { type, inlineType } = getObjectDefinition ( stringifyType ( detailType , checker ) , detailType , checker ) ;
128+ const { type, inlineType } = getObjectDefinition ( stringifyType ( detailType , checker ) , detailType , typeNode , checker ) ;
107129 return {
108130 detailType : type ,
109131 detailInlineType : inlineType ,
0 commit comments