@@ -64,7 +64,15 @@ export function parseWithComments(
6464 let match ;
6565 while ( ( match = propertyRe . exec ( docblock ) ) ) {
6666 // strip linecomments from pragmas
67- result [ match [ 1 ] ] = match [ 2 ] . replace ( lineCommentRe , '' ) ;
67+ const nextPragma = match [ 2 ] . replace ( lineCommentRe , '' ) ;
68+ if (
69+ typeof result [ match [ 1 ] ] === 'string' ||
70+ Array . isArray ( result [ match [ 1 ] ] )
71+ ) {
72+ result [ match [ 1 ] ] = [ ] . concat ( result [ match [ 1 ] ] , nextPragma ) ;
73+ } else {
74+ result [ match [ 1 ] ] = nextPragma ;
75+ }
6876 }
6977 return { comments, pragmas : result } ;
7078}
@@ -85,15 +93,17 @@ export function print({
8593 const keys = Object . keys ( pragmas ) ;
8694
8795 const printedObject = keys
88- . map ( key => start + ' ' + printKeyValue ( key , pragmas [ key ] ) + line )
96+ . map ( key => printKeyValues ( key , pragmas [ key ] ) )
97+ . reduce ( ( arr , next ) => arr . concat ( next ) , [ ] )
98+ . map ( keyValue => start + ' ' + keyValue + line )
8999 . join ( '' ) ;
90100
91101 if ( ! comments ) {
92102 if ( keys . length === 0 ) {
93103 return '' ;
94104 }
95- if ( keys . length === 1 ) {
96- return `${ head } ${ printKeyValue ( keys [ 0 ] , pragmas [ keys [ 0 ] ] ) } ${ tail } ` ;
105+ if ( keys . length === 1 && ! Array . isArray ( pragmas [ keys [ 0 ] ] ) ) {
106+ return `${ head } ${ printKeyValues ( keys [ 0 ] , pragmas [ keys [ 0 ] ] ) } ${ tail } ` ;
97107 }
98108 }
99109
@@ -113,6 +123,6 @@ export function print({
113123 ) ;
114124}
115125
116- function printKeyValue ( key , value ) {
117- return `@${ key } ${ value } ` . trim ( ) ;
126+ function printKeyValues ( key , valueOrArray ) {
127+ return [ ] . concat ( valueOrArray ) . map ( value => `@${ key } ${ value } ` . trim ( ) ) ;
118128}
0 commit comments