@@ -109,7 +109,7 @@ const emitGlobalTypeDefs = () => {
109109const emitDomain = ( domain : P . Domain ) => {
110110 const domainName = toTitleCase ( domain . domain )
111111 emitLine ( )
112- emitDescription ( domain . description )
112+ emitTsComment ( domain )
113113 emitOpenBlock ( `export namespace ${ domainName } ` )
114114 if ( domain . types ) domain . types . forEach ( emitDomainType )
115115 if ( domain . commands ) domain . commands . forEach ( emitCommand )
@@ -118,15 +118,30 @@ const emitDomain = (domain: P.Domain) => {
118118}
119119
120120const getCommentLines = ( description : string ) => {
121- const lines = description
121+ return description
122122 . split ( / \r ? \n / g)
123123 . filter ( line => ! line . startsWith ( 'LINT.' ) )
124- . map ( line => ` * ${ line } ` )
125- return [ `/**` , ...lines , ` */` ]
126124}
127125
128- const emitDescription = ( description ?: string ) => {
129- if ( description ) getCommentLines ( description ) . map ( l => emitLine ( l ) )
126+ const emitDescription = ( lines : string [ ] ) => {
127+ emitLine ( `/**` )
128+ lines . map ( l => emitLine ( ` * ${ l } ` ) )
129+ emitLine ( ` */` )
130+ }
131+
132+ const emitTsComment = ( object : P . Event | P . PropertyType | P . DomainType | P . Command | P . Domain ) => {
133+ const commentLines = object . description ? getCommentLines ( object . description ) : [ ] ;
134+ if ( 'deprecated' in object ) {
135+ commentLines . push ( '@deprecated' ) ;
136+ }
137+
138+ if ( 'experimental' in object ) {
139+ commentLines . push ( '@experimental' ) ;
140+ }
141+
142+ if ( commentLines . length ) {
143+ emitDescription ( commentLines )
144+ }
130145}
131146
132147const isPropertyInlineEnum = ( prop : P . ProtocolType ) : boolean => {
@@ -175,7 +190,7 @@ const emitProperty = (interfaceName: string, prop: P.PropertyType) => {
175190 description = `${ description || '' } (${ enumName } enum)` ;
176191 }
177192
178- emitDescription ( description )
193+ emitTsComment ( prop )
179194 emitLine ( `${ getPropertyDef ( interfaceName , prop ) } ;` )
180195}
181196
@@ -218,7 +233,7 @@ const emitInterface = (interfaceName: string, props?: P.PropertyType[]) => {
218233const emitDomainType = ( type : P . DomainType ) => {
219234 emitInlineEnumForDomainType ( type ) ;
220235 emitLine ( )
221- emitDescription ( type . description )
236+ emitTsComment ( type )
222237
223238 if ( type . type === 'object' ) {
224239 emitInterface ( type . id , type . properties )
@@ -256,7 +271,7 @@ const emitEvent = (event: P.Event) => {
256271
257272 emitInlineEnumsForEvents ( event ) ;
258273 emitLine ( )
259- emitDescription ( event . description )
274+ emitTsComment ( event )
260275 emitInterface ( toEventPayloadName ( event . name ) , event . parameters )
261276}
262277
@@ -309,7 +324,7 @@ const emitMapping = (moduleName: string, protocolModuleName: string, domains: P.
309324 emitHeaderComments ( )
310325 emitLine ( `import Protocol from './${ protocolModuleName } '` )
311326 emitLine ( )
312- emitDescription ( 'Mappings from protocol event and command names to the types required for them.' )
327+ emitDescription ( [ 'Mappings from protocol event and command names to the types required for them.' ] )
313328 emitOpenBlock ( `export namespace ${ moduleName } ` )
314329
315330 const protocolModulePrefix = toTitleCase ( protocolModuleName )
@@ -334,7 +349,7 @@ const emitMapping = (moduleName: string, protocolModuleName: string, domains: P.
334349
335350const emitApiCommand = ( command : P . Command , domainName : string , modulePrefix : string , eventStyle : EventStyleEnum ) => {
336351 const prefix = `${ modulePrefix } .${ domainName } .`
337- emitDescription ( command . description )
352+ emitTsComment ( command )
338353 const params = command . parameters ? `params: ${ prefix } ${ toCmdRequestName ( command . name ) } ` : ''
339354 const response = command . returns ? `${ prefix } ${ toCmdResponseName ( command . name ) } ` : 'void'
340355 switch ( eventStyle ) {
@@ -352,7 +367,7 @@ const emitApiCommand = (command: P.Command, domainName: string, modulePrefix: st
352367
353368const emitApiEvent = ( event : P . Event , domainName : string , modulePrefix : string , eventStyle : EventStyleEnum ) => {
354369 const prefix = `${ modulePrefix } .${ domainName } .`
355- emitDescription ( event . description )
370+ emitTsComment ( event )
356371 switch ( eventStyle ) {
357372 case EventStyle . REGULAR : {
358373 const params = event . parameters ? `params: ${ prefix } ${ toEventPayloadName ( event . name ) } ` : ''
@@ -385,7 +400,7 @@ const emitApi = (moduleName: string, protocolModuleName: string, domains: P.Doma
385400 emitHeaderComments ( )
386401 emitLine ( `import Protocol from './${ protocolModuleName } '` )
387402 emitLine ( )
388- emitDescription ( 'API generated from Protocol commands and events.' )
403+ emitDescription ( [ 'API generated from Protocol commands and events.' ] )
389404 emitOpenBlock ( `export namespace ${ moduleName } ` )
390405
391406 emitLine ( )
0 commit comments