@@ -1501,7 +1501,8 @@ function extract_type_and_comment(declarator, state, path) {
1501
1501
const trailing_comment_node = /** @type {Node } */ ( parent ) ?. trailingComments ?. at ( 0 ) ;
1502
1502
const trailing_comment_start = /** @type {any } */ ( trailing_comment_node ) ?. start ;
1503
1503
const trailing_comment_end = /** @type {any } */ ( trailing_comment_node ) ?. end ;
1504
- let trailing_comment = trailing_comment_node && str . original . substring ( trailing_comment_start , trailing_comment_end ) ;
1504
+ let trailing_comment =
1505
+ trailing_comment_node && str . original . substring ( trailing_comment_start , trailing_comment_end ) ;
1505
1506
1506
1507
if ( trailing_comment_node ) {
1507
1508
str . update ( trailing_comment_start , trailing_comment_end , '' ) ;
@@ -1513,7 +1514,11 @@ function extract_type_and_comment(declarator, state, path) {
1513
1514
while ( str . original [ start ] === ' ' ) {
1514
1515
start ++ ;
1515
1516
}
1516
- return { type : str . original . substring ( start , declarator . id . typeAnnotation . end ) , comment, trailing_comment } ;
1517
+ return {
1518
+ type : str . original . substring ( start , declarator . id . typeAnnotation . end ) ,
1519
+ comment,
1520
+ trailing_comment
1521
+ } ;
1517
1522
}
1518
1523
1519
1524
let cleaned_comment_arr = comment
@@ -1535,7 +1540,7 @@ function extract_type_and_comment(declarator, state, path) {
1535
1540
let cleaned_comment = cleaned_comment_arr
1536
1541
?. slice ( 0 , first_at_comment !== - 1 ? first_at_comment : cleaned_comment_arr . length )
1537
1542
. join ( '\n' ) ;
1538
-
1543
+
1539
1544
let cleaned_comment_arr_trailing = trailing_comment
1540
1545
?. split ( '\n' )
1541
1546
. map ( ( line ) =>
@@ -1551,17 +1556,28 @@ function extract_type_and_comment(declarator, state, path) {
1551
1556
. replace ( / ^ \* \s * / g, '' )
1552
1557
)
1553
1558
. filter ( Boolean ) ;
1554
- const first_at_comment_trailing = cleaned_comment_arr_trailing ?. findIndex ( ( line ) => line . startsWith ( '@' ) ) ;
1559
+ const first_at_comment_trailing = cleaned_comment_arr_trailing ?. findIndex ( ( line ) =>
1560
+ line . startsWith ( '@' )
1561
+ ) ;
1555
1562
let cleaned_comment_trailing = cleaned_comment_arr_trailing
1556
- ?. slice ( 0 , first_at_comment_trailing !== - 1 ? first_at_comment_trailing : cleaned_comment_arr_trailing . length )
1563
+ ?. slice (
1564
+ 0 ,
1565
+ first_at_comment_trailing !== - 1
1566
+ ? first_at_comment_trailing
1567
+ : cleaned_comment_arr_trailing . length
1568
+ )
1557
1569
. join ( '\n' ) ;
1558
1570
1559
1571
// try to find a comment with a type annotation, hinting at jsdoc
1560
1572
if ( parent ?. type === 'ExportNamedDeclaration' && comment_node ) {
1561
1573
state . has_type_or_fallback = true ;
1562
1574
const match = / @ t y p e { ( .+ ) } / . exec ( comment_node . value ) ;
1563
1575
if ( match ) {
1564
- return { type : match [ 1 ] , comment : cleaned_comment , trailing_comment : cleaned_comment_trailing } ;
1576
+ return {
1577
+ type : match [ 1 ] ,
1578
+ comment : cleaned_comment ,
1579
+ trailing_comment : cleaned_comment_trailing
1580
+ } ;
1565
1581
}
1566
1582
}
1567
1583
@@ -1570,11 +1586,19 @@ function extract_type_and_comment(declarator, state, path) {
1570
1586
state . has_type_or_fallback = true ; // only assume type if it's trivial to infer - else someone would've added a type annotation
1571
1587
const type = typeof declarator . init . value ;
1572
1588
if ( type === 'string' || type === 'number' || type === 'boolean' ) {
1573
- return { type, comment : state . uses_ts ? comment : cleaned_comment , trailing_comment : state . uses_ts ? trailing_comment : cleaned_comment_trailing } ;
1589
+ return {
1590
+ type,
1591
+ comment : state . uses_ts ? comment : cleaned_comment ,
1592
+ trailing_comment : state . uses_ts ? trailing_comment : cleaned_comment_trailing
1593
+ } ;
1574
1594
}
1575
1595
}
1576
1596
1577
- return { type : 'any' , comment : state . uses_ts ? comment : cleaned_comment , trailing_comment : state . uses_ts ? trailing_comment : cleaned_comment_trailing } ;
1597
+ return {
1598
+ type : 'any' ,
1599
+ comment : state . uses_ts ? comment : cleaned_comment ,
1600
+ trailing_comment : state . uses_ts ? trailing_comment : cleaned_comment_trailing
1601
+ } ;
1578
1602
}
1579
1603
1580
1604
// Ensure modifiers are applied in the same order as Svelte 4
0 commit comments