@@ -160,11 +160,11 @@ export default (options = {}) => {
160
160
161
161
/**
162
162
* @param {Context } context
163
- * @param {TSESTree.Node } node
164
163
* @param {TSESTree.Node[] } nodes
164
+ * @param {{ line: number, column: number } } until
165
165
* @param {boolean } pad
166
166
*/
167
- function sequence ( context , node , nodes , pad , separator = ',' ) {
167
+ function sequence ( context , nodes , until , pad , separator = ',' ) {
168
168
let multiline = false ;
169
169
let length = - 1 ;
170
170
@@ -181,7 +181,7 @@ export default (options = {}) => {
181
181
child_context . write ( separator ) ;
182
182
}
183
183
184
- const next = i === nodes . length - 1 ? node . loc . end : nodes [ i + 1 ] ?. loc . start || null ;
184
+ const next = i === nodes . length - 1 ? until : nodes [ i + 1 ] ?. loc . start || null ;
185
185
if ( child && flush_trailing_comments ( child_context , child . loc . end , next ) ) {
186
186
multiline = true ;
187
187
}
@@ -226,6 +226,8 @@ export default (options = {}) => {
226
226
prev = child ;
227
227
}
228
228
229
+ flush_comments_until ( context , until ) ;
230
+
229
231
if ( multiline ) {
230
232
context . dedent ( ) ;
231
233
context . newline ( ) ;
@@ -278,7 +280,7 @@ export default (options = {}) => {
278
280
*/
279
281
'ArrayExpression|ArrayPattern' : ( node , context ) => {
280
282
context . write ( '[' ) ;
281
- sequence ( context , node , /** @type {TSESTree.Node[] } */ ( node . elements ) , false ) ;
283
+ sequence ( context , /** @type {TSESTree.Node[] } */ ( node . elements ) , node . loc . end , false ) ;
282
284
context . write ( ']' ) ;
283
285
} ,
284
286
@@ -457,7 +459,7 @@ export default (options = {}) => {
457
459
458
460
if ( node . implements ) {
459
461
context . write ( 'implements ' ) ;
460
- sequence ( context , node , node . implements , false ) ;
462
+ sequence ( context , node . implements , node . body . loc . start , false ) ;
461
463
}
462
464
463
465
context . visit ( node . body ) ;
@@ -498,7 +500,7 @@ export default (options = {}) => {
498
500
}
499
501
500
502
context . write ( '(' ) ;
501
- sequence ( context , node , node . params , false ) ;
503
+ sequence ( context , node . params , ( node . returnType ?? node . body ) . loc . start , false ) ;
502
504
context . write ( ')' ) ;
503
505
504
506
if ( node . returnType ) context . visit ( node . returnType ) ;
@@ -544,7 +546,7 @@ export default (options = {}) => {
544
546
if ( node . async ) context . write ( 'async ' ) ;
545
547
546
548
context . write ( '(' ) ;
547
- sequence ( context , node , node . params , false ) ;
549
+ sequence ( context , node . params , node . body . loc . start , false ) ;
548
550
context . write ( ') => ' ) ;
549
551
550
552
if (
@@ -717,7 +719,7 @@ export default (options = {}) => {
717
719
}
718
720
719
721
context . write ( '{' ) ;
720
- sequence ( context , node , node . specifiers , true ) ;
722
+ sequence ( context , node . specifiers , node . source ?. loc . start ?? node . loc . end , true ) ;
721
723
context . write ( '}' ) ;
722
724
723
725
if ( node . source ) {
@@ -843,7 +845,7 @@ export default (options = {}) => {
843
845
844
846
if ( named_specifiers . length > 0 ) {
845
847
context . write ( '{' ) ;
846
- sequence ( context , node , named_specifiers , true ) ;
848
+ sequence ( context , named_specifiers , node . source . loc . start , true ) ;
847
849
context . write ( '}' ) ;
848
850
}
849
851
@@ -966,7 +968,12 @@ export default (options = {}) => {
966
968
if ( node . computed ) context . write ( ']' ) ;
967
969
968
970
context . write ( '(' ) ;
969
- sequence ( context , node , node . value . params , false ) ;
971
+ sequence (
972
+ context ,
973
+ node . value . params ,
974
+ ( node . value . returnType ?? node . value . body ) ?. loc . start ?? node . loc . end ,
975
+ false
976
+ ) ;
970
977
context . write ( ')' ) ;
971
978
972
979
if ( node . value . returnType ) context . visit ( node . value . returnType ) ;
@@ -980,13 +987,13 @@ export default (options = {}) => {
980
987
981
988
ObjectExpression ( node , context ) {
982
989
context . write ( '{' ) ;
983
- sequence ( context , node , node . properties , true ) ;
990
+ sequence ( context , node . properties , node . loc . end , true ) ;
984
991
context . write ( '}' ) ;
985
992
} ,
986
993
987
994
ObjectPattern ( node , context ) {
988
995
context . write ( '{' ) ;
989
- sequence ( context , node , node . properties , true ) ;
996
+ sequence ( context , node . properties , node . loc . end , true ) ;
990
997
context . write ( '}' ) ;
991
998
992
999
if ( node . typeAnnotation ) context . visit ( node . typeAnnotation ) ;
@@ -1030,7 +1037,12 @@ export default (options = {}) => {
1030
1037
context . visit ( node . key ) ;
1031
1038
if ( node . computed ) context . write ( ']' ) ;
1032
1039
context . write ( '(' ) ;
1033
- sequence ( context , node , node . value . params , false ) ;
1040
+ sequence (
1041
+ context ,
1042
+ node . value . params ,
1043
+ ( node . value . returnType ?? node . value . body ) . loc . start ,
1044
+ false
1045
+ ) ;
1034
1046
context . write ( ')' ) ;
1035
1047
1036
1048
if ( node . value . returnType ) context . visit ( node . value . returnType ) ;
@@ -1100,7 +1112,7 @@ export default (options = {}) => {
1100
1112
1101
1113
SequenceExpression ( node , context ) {
1102
1114
context . write ( '(' ) ;
1103
- sequence ( context , node , node . expressions , false ) ;
1115
+ sequence ( context , node . expressions , node . loc . end , false ) ;
1104
1116
context . write ( ')' ) ;
1105
1117
} ,
1106
1118
@@ -1335,7 +1347,7 @@ export default (options = {}) => {
1335
1347
1336
1348
TSTypeLiteral ( node , context ) {
1337
1349
context . write ( '{ ' ) ;
1338
- sequence ( context , node , node . members , false , ';' ) ;
1350
+ sequence ( context , node . members , node . loc . end , false , ';' ) ;
1339
1351
context . write ( ' }' ) ;
1340
1352
} ,
1341
1353
@@ -1402,10 +1414,10 @@ export default (options = {}) => {
1402
1414
TSFunctionType ( node , context ) {
1403
1415
if ( node . typeParameters ) context . visit ( node . typeParameters ) ;
1404
1416
1405
- // @ts -expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions
1406
- const parameters = node . parameters ;
1407
1417
context . write ( '(' ) ;
1408
- sequence ( context , node , parameters , false ) ;
1418
+
1419
+ // @ts -expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions
1420
+ sequence ( context , node . parameters , node . typeAnnotation . typeAnnotation . loc . start , false ) ;
1409
1421
1410
1422
context . write ( ') => ' ) ;
1411
1423
@@ -1414,9 +1426,10 @@ export default (options = {}) => {
1414
1426
} ,
1415
1427
1416
1428
TSIndexSignature ( node , context ) {
1417
- const indexParameters = node . parameters ;
1418
1429
context . write ( '[' ) ;
1419
- sequence ( context , node , indexParameters , false ) ;
1430
+
1431
+ // @ts -expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions
1432
+ sequence ( context , node . parameters , node . typeAnnotation ?. loc . start , false ) ;
1420
1433
context . write ( ']' ) ;
1421
1434
1422
1435
// @ts -expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions
@@ -1426,10 +1439,10 @@ export default (options = {}) => {
1426
1439
TSMethodSignature ( node , context ) {
1427
1440
context . visit ( node . key ) ;
1428
1441
1429
- // @ts -expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions
1430
- const parametersSignature = node . parameters ;
1431
1442
context . write ( '(' ) ;
1432
- sequence ( context , node , parametersSignature , false ) ;
1443
+
1444
+ // @ts -expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions
1445
+ sequence ( context , node . parameters , node . typeAnnotation . loc . start , false ) ;
1433
1446
context . write ( ')' ) ;
1434
1447
1435
1448
// @ts -expect-error `acorn-typescript` and `@typescript-eslint/types` have slightly different type definitions
@@ -1438,7 +1451,7 @@ export default (options = {}) => {
1438
1451
1439
1452
TSTupleType ( node , context ) {
1440
1453
context . write ( '[' ) ;
1441
- sequence ( context , node , node . elementTypes , false ) ;
1454
+ sequence ( context , node . elementTypes , node . loc . end , false ) ;
1442
1455
context . write ( ']' ) ;
1443
1456
} ,
1444
1457
@@ -1449,11 +1462,11 @@ export default (options = {}) => {
1449
1462
} ,
1450
1463
1451
1464
TSUnionType ( node , context ) {
1452
- sequence ( context , node , node . types , false , ' |' ) ;
1465
+ sequence ( context , node . types , node . loc . end , false , ' |' ) ;
1453
1466
} ,
1454
1467
1455
1468
TSIntersectionType ( node , context ) {
1456
- sequence ( context , node , node . types , false , ' &' ) ;
1469
+ sequence ( context , node . types , node . loc . end , false , ' &' ) ;
1457
1470
} ,
1458
1471
1459
1472
TSLiteralType ( node , context ) {
@@ -1511,7 +1524,7 @@ export default (options = {}) => {
1511
1524
context . write ( ' {' ) ;
1512
1525
context . indent ( ) ;
1513
1526
context . newline ( ) ;
1514
- sequence ( context , node , node . members , false ) ;
1527
+ sequence ( context , node . members , node . loc . end , false ) ;
1515
1528
context . dedent ( ) ;
1516
1529
context . newline ( ) ;
1517
1530
context . write ( '}' ) ;
@@ -1543,7 +1556,7 @@ export default (options = {}) => {
1543
1556
} ,
1544
1557
1545
1558
TSInterfaceBody ( node , context ) {
1546
- sequence ( context , node , node . body , true , ';' ) ;
1559
+ sequence ( context , node . body , node . loc . end , true , ';' ) ;
1547
1560
} ,
1548
1561
1549
1562
TSInterfaceDeclaration ( node , context ) {
@@ -1552,7 +1565,7 @@ export default (options = {}) => {
1552
1565
if ( node . typeParameters ) context . visit ( node . typeParameters ) ;
1553
1566
if ( node . extends ) {
1554
1567
context . write ( ' extends ' ) ;
1555
- sequence ( context , node , node . extends , false ) ;
1568
+ sequence ( context , node . extends , node . body . loc . start , false ) ;
1556
1569
}
1557
1570
context . write ( ' {' ) ;
1558
1571
context . visit ( node . body ) ;
0 commit comments