@@ -515,7 +515,7 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
515
515
'{#each ' ,
516
516
printJS ( path , print , 'expression' ) ,
517
517
' as' ,
518
- expandNode ( node . context ) ,
518
+ expandNode ( node . context , options . originalText ) ,
519
519
] ;
520
520
521
521
if ( node . index ) {
@@ -549,7 +549,7 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
549
549
'{#await ' ,
550
550
printJS ( path , print , 'expression' ) ,
551
551
' then' ,
552
- expandNode ( node . value ) ,
552
+ expandNode ( node . value , options . originalText ) ,
553
553
'}' ,
554
554
] ) ,
555
555
path . call ( print , 'then' ) ,
@@ -560,7 +560,7 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
560
560
'{#await ' ,
561
561
printJS ( path , print , 'expression' ) ,
562
562
' catch' ,
563
- expandNode ( node . error ) ,
563
+ expandNode ( node . error , options . originalText ) ,
564
564
'}' ,
565
565
] ) ,
566
566
path . call ( print , 'catch' ) ,
@@ -574,15 +574,15 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
574
574
575
575
if ( hasThenBlock ) {
576
576
block . push (
577
- group ( [ '{:then' , expandNode ( node . value ) , '}' ] ) ,
577
+ group ( [ '{:then' , expandNode ( node . value , options . originalText ) , '}' ] ) ,
578
578
path . call ( print , 'then' ) ,
579
579
) ;
580
580
}
581
581
}
582
582
583
583
if ( ( hasPendingBlock || hasThenBlock ) && hasCatchBlock ) {
584
584
block . push (
585
- group ( [ '{:catch' , expandNode ( node . error ) , '}' ] ) ,
585
+ group ( [ '{:catch' , expandNode ( node . error , options . originalText ) , '}' ] ) ,
586
586
path . call ( print , 'catch' ) ,
587
587
) ;
588
588
}
@@ -1188,7 +1188,15 @@ function printJS(path: FastPath, print: PrintFn, name: string) {
1188
1188
return path . call ( print , name ) ;
1189
1189
}
1190
1190
1191
- function expandNode ( node : any , parent ?: any ) : string {
1191
+ function expandNode ( node : any , original : string ) : string {
1192
+ let str = _expandNode ( node ) ;
1193
+ if ( node ?. typeAnnotation ) {
1194
+ str += ': ' + original . slice ( node . typeAnnotation . start , node . typeAnnotation . end ) ;
1195
+ }
1196
+ return str ;
1197
+ }
1198
+
1199
+ function _expandNode ( node : any , parent ?: any ) : string {
1192
1200
if ( node === null ) {
1193
1201
return '' ;
1194
1202
}
@@ -1201,27 +1209,27 @@ function expandNode(node: any, parent?: any): string {
1201
1209
switch ( node . type ) {
1202
1210
case 'ArrayExpression' :
1203
1211
case 'ArrayPattern' :
1204
- return ' [' + node . elements . map ( expandNode ) . join ( ',' ) . slice ( 1 ) + ']' ;
1212
+ return ' [' + node . elements . map ( _expandNode ) . join ( ',' ) . slice ( 1 ) + ']' ;
1205
1213
case 'AssignmentPattern' :
1206
- return expandNode ( node . left ) + ' =' + expandNode ( node . right ) ;
1214
+ return _expandNode ( node . left ) + ' =' + _expandNode ( node . right ) ;
1207
1215
case 'Identifier' :
1208
1216
return ' ' + node . name ;
1209
1217
case 'Literal' :
1210
1218
return ' ' + node . raw ;
1211
1219
case 'ObjectExpression' :
1212
- return ' {' + node . properties . map ( ( p : any ) => expandNode ( p , node ) ) . join ( ',' ) + ' }' ;
1220
+ return ' {' + node . properties . map ( ( p : any ) => _expandNode ( p , node ) ) . join ( ',' ) + ' }' ;
1213
1221
case 'ObjectPattern' :
1214
- return ' {' + node . properties . map ( expandNode ) . join ( ',' ) + ' }' ;
1222
+ return ' {' + node . properties . map ( _expandNode ) . join ( ',' ) + ' }' ;
1215
1223
case 'Property' :
1216
1224
if ( node . value . type === 'ObjectPattern' || node . value . type === 'ArrayPattern' ) {
1217
- return ' ' + node . key . name + ':' + expandNode ( node . value ) ;
1225
+ return ' ' + node . key . name + ':' + _expandNode ( node . value ) ;
1218
1226
} else if (
1219
1227
( node . value . type === 'Identifier' && node . key . name !== node . value . name ) ||
1220
1228
( parent && parent . type === 'ObjectExpression' )
1221
1229
) {
1222
- return expandNode ( node . key ) + ':' + expandNode ( node . value ) ;
1230
+ return _expandNode ( node . key ) + ':' + _expandNode ( node . value ) ;
1223
1231
} else {
1224
- return expandNode ( node . value ) ;
1232
+ return _expandNode ( node . value ) ;
1225
1233
}
1226
1234
case 'RestElement' :
1227
1235
return ' ...' + node . argument . name ;
0 commit comments