@@ -1538,6 +1538,34 @@ namespace ts {
15381538 return getJSDocCommentsAndTags ( node ) ;
15391539 }
15401540
1541+ export function getSourceOfAssignment ( node : Node ) : Node {
1542+ return isExpressionStatement ( node ) &&
1543+ node . expression && isBinaryExpression ( node . expression ) &&
1544+ node . expression . operatorToken . kind === SyntaxKind . EqualsToken &&
1545+ node . expression . right ;
1546+ }
1547+
1548+ export function getSingleInitializerOfVariableStatement ( node : Node , child ?: Node ) : Node {
1549+ return isVariableStatement ( node ) &&
1550+ node . declarationList . declarations . length > 0 &&
1551+ ( ! child || node . declarationList . declarations [ 0 ] . initializer === child ) &&
1552+ node . declarationList . declarations [ 0 ] . initializer ;
1553+ }
1554+
1555+ export function getSingleVariableOfVariableStatement ( node : Node , child ?: Node ) : Node {
1556+ return isVariableStatement ( node ) &&
1557+ node . declarationList . declarations . length > 0 &&
1558+ ( ! child || node . declarationList . declarations [ 0 ] === child ) &&
1559+ node . declarationList . declarations [ 0 ] ;
1560+ }
1561+
1562+ export function getNestedModuleDeclaration ( node : Node ) : Node {
1563+ return node . kind === SyntaxKind . ModuleDeclaration &&
1564+ ( node as ModuleDeclaration ) . body &&
1565+ ( node as ModuleDeclaration ) . body . kind === SyntaxKind . ModuleDeclaration &&
1566+ ( node as ModuleDeclaration ) . body ;
1567+ }
1568+
15411569 export function getJSDocCommentsAndTags ( node : Node ) : ( JSDoc | JSDocTag ) [ ] {
15421570 let result : ( JSDoc | JSDocTag ) [ ] | undefined ;
15431571 getJSDocCommentsAndTagsWorker ( node ) ;
@@ -1551,35 +1579,15 @@ namespace ts {
15511579 // * @returns {number }
15521580 // */
15531581 // var x = function(name) { return name.length; }
1554- const isInitializerOfVariableDeclarationInStatement =
1555- isVariableLike ( parent ) &&
1556- parent . initializer === node &&
1557- parent . parent . parent . kind === SyntaxKind . VariableStatement ;
1558- const isVariableOfVariableDeclarationStatement = isVariableLike ( node ) &&
1559- parent . parent . kind === SyntaxKind . VariableStatement ;
1560- const variableStatementNode =
1561- isInitializerOfVariableDeclarationInStatement ? parent . parent . parent :
1562- isVariableOfVariableDeclarationStatement ? parent . parent :
1563- undefined ;
1564- if ( variableStatementNode ) {
1565- getJSDocCommentsAndTagsWorker ( variableStatementNode ) ;
1582+ if ( parent && ( parent . kind === SyntaxKind . PropertyAssignment || getNestedModuleDeclaration ( parent ) ) ) {
1583+ getJSDocCommentsAndTagsWorker ( parent ) ;
15661584 }
1567-
1568- // Also recognize when the node is the RHS of an assignment expression
1569- const isSourceOfAssignmentExpressionStatement =
1570- parent && parent . parent &&
1571- parent . kind === SyntaxKind . BinaryExpression &&
1572- ( parent as BinaryExpression ) . operatorToken . kind === SyntaxKind . EqualsToken &&
1573- parent . parent . kind === SyntaxKind . ExpressionStatement ;
1574- if ( isSourceOfAssignmentExpressionStatement ) {
1585+ if ( parent && parent . parent &&
1586+ ( getSingleVariableOfVariableStatement ( parent . parent , node ) || getSourceOfAssignment ( parent . parent ) ) ) {
15751587 getJSDocCommentsAndTagsWorker ( parent . parent ) ;
15761588 }
1577-
1578- const isModuleDeclaration = node . kind === SyntaxKind . ModuleDeclaration &&
1579- parent && parent . kind === SyntaxKind . ModuleDeclaration ;
1580- const isPropertyAssignmentExpression = parent && parent . kind === SyntaxKind . PropertyAssignment ;
1581- if ( isModuleDeclaration || isPropertyAssignmentExpression ) {
1582- getJSDocCommentsAndTagsWorker ( parent ) ;
1589+ if ( parent && parent . parent && parent . parent . parent && getSingleInitializerOfVariableStatement ( parent . parent . parent , node ) ) {
1590+ getJSDocCommentsAndTagsWorker ( parent . parent . parent ) ;
15831591 }
15841592
15851593 // Pull parameter comments from declaring function as well
@@ -1606,13 +1614,16 @@ namespace ts {
16061614 return undefined ;
16071615 }
16081616 const name = node . name . escapedText ;
1609- const func = getJSDocHost ( node ) ;
1610- if ( ! isFunctionLike ( func ) ) {
1611- return undefined ;
1617+ const host = getJSDocHost ( node ) ;
1618+ const decl = getSourceOfAssignment ( host ) ||
1619+ getSingleInitializerOfVariableStatement ( host ) ||
1620+ getSingleVariableOfVariableStatement ( host ) ||
1621+ getNestedModuleDeclaration ( host ) ||
1622+ host ;
1623+ if ( decl && isFunctionLike ( decl ) ) {
1624+ const parameter = find ( decl . parameters , p => p . name . kind === SyntaxKind . Identifier && p . name . escapedText === name ) ;
1625+ return parameter && parameter . symbol ;
16121626 }
1613- const parameter = find ( func . parameters , p =>
1614- p . name . kind === SyntaxKind . Identifier && p . name . escapedText === name ) ;
1615- return parameter && parameter . symbol ;
16161627 }
16171628
16181629 export function getJSDocHost ( node : JSDocTag ) : HasJSDoc {
0 commit comments