@@ -1498,16 +1498,14 @@ namespace ts {
1498
1498
1499
1499
// Pull parameter comments from declaring function as well
1500
1500
if ( node . kind === SyntaxKind . Parameter ) {
1501
- result = concatenate ( result , getContentFromParam ( getJSDocParameterTag ( node as ParameterDeclaration ) ) ) ;
1501
+ result = concatenate ( result , getContentFromParam ( getJSDocParameterTag ( node ) ) ) ;
1502
1502
}
1503
1503
1504
1504
if ( isVariableLike ( node ) && node . initializer ) {
1505
1505
result = concatenate ( result , getOwnJSDocs ( node . initializer ) ) ;
1506
1506
}
1507
1507
1508
- result = concatenate ( result , getOwnJSDocs ( node ) ) ;
1509
-
1510
- return result ;
1508
+ return concatenate ( result , getOwnJSDocs ( node ) ) ;
1511
1509
}
1512
1510
1513
1511
function getOwnJSDocs ( node : Node ) {
@@ -1517,24 +1515,23 @@ namespace ts {
1517
1515
}
1518
1516
}
1519
1517
1520
- function getJSDocParameterTag ( param : ParameterDeclaration ) : JSDocTag [ ] {
1521
- // TODO: getCorrespondingJSDocParameterTag is basically the same as this, except worse. (and typed, singleton return)
1518
+ export function getJSDocParameterTag ( param : Node ) : JSDocParameterTag [ ] {
1519
+ if ( ! isParameter ( param ) ) {
1520
+ return undefined ;
1521
+ }
1522
1522
const func = param . parent as FunctionLikeDeclaration ;
1523
1523
const tags = getJSDocTags ( func ) ;
1524
1524
if ( ! param . name ) {
1525
1525
// this is an anonymous jsdoc param from a `function(type1, type2): type3` specification
1526
1526
const i = func . parameters . indexOf ( param ) ;
1527
- const paramTags = filter ( tags , tag => tag . kind === SyntaxKind . JSDocParameterTag ) ;
1527
+ const paramTags = filter ( tags , tag => tag . kind === SyntaxKind . JSDocParameterTag ) as JSDocParameterTag [ ] ;
1528
1528
if ( paramTags && 0 <= i && i < paramTags . length ) {
1529
1529
return [ paramTags [ i ] ] ;
1530
1530
}
1531
1531
}
1532
1532
else if ( param . name . kind === SyntaxKind . Identifier ) {
1533
1533
const name = ( param . name as Identifier ) . text ;
1534
- const paramTags = filter ( tags , tag => tag . kind === SyntaxKind . JSDocParameterTag && ( tag as JSDocParameterTag ) . parameterName . text === name ) ;
1535
- if ( paramTags ) {
1536
- return paramTags ;
1537
- }
1534
+ return filter ( tags as JSDocParameterTag [ ] , tag => tag . kind === SyntaxKind . JSDocParameterTag && tag . parameterName . text === name ) ;
1538
1535
}
1539
1536
else {
1540
1537
// TODO: it's a destructured parameter, so it should look up an "object type" series of multiple lines
@@ -1544,12 +1541,11 @@ namespace ts {
1544
1541
}
1545
1542
1546
1543
export function getJSDocType ( node : Node ) : JSDocType {
1547
- // TODO: If you have to call getparamtag, you really want the first with a typeExpression, not the first one.
1548
1544
let tag : JSDocTypeTag | JSDocParameterTag = getJSDocTag ( node , SyntaxKind . JSDocTypeTag ) as JSDocTypeTag ;
1549
1545
if ( ! tag && node . kind === SyntaxKind . Parameter ) {
1550
- const paramTags = getJSDocParameterTag ( node as ParameterDeclaration ) ;
1546
+ const paramTags = getJSDocParameterTag ( node ) ;
1551
1547
if ( paramTags ) {
1552
- tag = find ( paramTags , tag => ! ! ( tag as JSDocParameterTag ) . typeExpression ) as JSDocParameterTag ;
1548
+ tag = find ( paramTags , tag => ! ! tag . typeExpression ) ;
1553
1549
}
1554
1550
}
1555
1551
@@ -1564,29 +1560,6 @@ namespace ts {
1564
1560
return getJSDocTag ( node , SyntaxKind . JSDocTemplateTag ) as JSDocTemplateTag ;
1565
1561
}
1566
1562
1567
- export function getCorrespondingJSDocParameterTag ( parameter : ParameterDeclaration ) : JSDocParameterTag {
1568
- if ( parameter . name && parameter . name . kind === SyntaxKind . Identifier ) {
1569
- // If it's a parameter, see if the parent has a jsdoc comment with an @param
1570
- // annotation.
1571
- const parameterName = ( < Identifier > parameter . name ) . text ;
1572
-
1573
- const jsDocTags = getJSDocTags ( parameter . parent ) ;
1574
- if ( ! jsDocTags ) {
1575
- return undefined ;
1576
- }
1577
- for ( const tag of jsDocTags ) {
1578
- if ( tag . kind === SyntaxKind . JSDocParameterTag ) {
1579
- const parameterTag = < JSDocParameterTag > tag ;
1580
- if ( parameterTag . parameterName . text === parameterName ) {
1581
- return parameterTag ;
1582
- }
1583
- }
1584
- }
1585
- }
1586
-
1587
- return undefined ;
1588
- }
1589
-
1590
1563
export function hasRestParameter ( s : SignatureDeclaration ) : boolean {
1591
1564
return isRestParameter ( lastOrUndefined ( s . parameters ) ) ;
1592
1565
}
@@ -1597,14 +1570,11 @@ namespace ts {
1597
1570
1598
1571
export function isRestParameter ( node : ParameterDeclaration ) {
1599
1572
if ( node && ( node . flags & NodeFlags . JavaScriptFile ) ) {
1600
- if ( node . type && node . type . kind === SyntaxKind . JSDocVariadicType ) {
1573
+ if ( node . type && node . type . kind === SyntaxKind . JSDocVariadicType ||
1574
+ forEach ( getJSDocParameterTag ( node ) ,
1575
+ t => t . typeExpression && t . typeExpression . type . kind === SyntaxKind . JSDocVariadicType ) ) {
1601
1576
return true ;
1602
1577
}
1603
-
1604
- const paramTag = getCorrespondingJSDocParameterTag ( node ) ;
1605
- if ( paramTag && paramTag . typeExpression ) {
1606
- return paramTag . typeExpression . type . kind === SyntaxKind . JSDocVariadicType ;
1607
- }
1608
1578
}
1609
1579
return isDeclaredRestParam ( node ) ;
1610
1580
}
0 commit comments