1010import detectNewline from 'detect-newline' ;
1111import { EOL } from 'os' ;
1212
13+ type Pragmas = { [ key : string ] : string | string [ ] , __proto__ : null } ;
14+
1315const commentEndRe = / \* \/ $ / ;
1416const commentStartRe = / ^ \/ \* \* / ;
1517const docblockRe = / ^ \s * ( \/ \* \* ? ( .| \r ? \n ) * ?\* \/ ) / ;
@@ -31,15 +33,13 @@ export function strip(contents: string) {
3133 return match && match [ 0 ] ? contents . substring ( match [ 0 ] . length ) : contents ;
3234}
3335
34- export function parse (
35- docblock : string ,
36- ) : { [ key : string ] : string , __proto__ : null } {
36+ export function parse ( docblock : string ) : Pragmas {
3737 return parseWithComments ( docblock ) . pragmas ;
3838}
3939
4040export function parseWithComments (
4141 docblock : string ,
42- ) : { comments: string , pragmas : { [ key : string ] : string , __proto__ : null } } {
42+ ) : { comments: string , pragmas : Pragmas } {
4343 const line = detectNewline ( docblock ) || EOL ;
4444
4545 docblock = docblock
@@ -82,7 +82,7 @@ export function print({
8282 pragmas = { } ,
8383} : {
8484 comments ?: string ,
85- pragmas ?: { [ key : string ] : string , __proto__ : null } ,
85+ pragmas ?: Pragmas ,
8686 __proto__ : null ,
8787} ) : string {
8888 const line = detectNewline ( comments ) || EOL ;
@@ -103,7 +103,8 @@ export function print({
103103 return '' ;
104104 }
105105 if ( keys . length === 1 && ! Array . isArray ( pragmas [ keys [ 0 ] ] ) ) {
106- return `${ head } ${ printKeyValues ( keys [ 0 ] , pragmas [ keys [ 0 ] ] ) } ${ tail } ` ;
106+ const value = pragmas [ keys [ 0 ] ] ;
107+ return `${ head } ${ printKeyValues ( keys [ 0 ] , value ) [ 0 ] } ${ tail } ` ;
107108 }
108109 }
109110
0 commit comments