Skip to content

Commit 96ec9be

Browse files
RyanCavanaughbillti
authored andcommitted
Recognize the RHS of assignments as the JSDoc target expression
Fixes #6552 (cherry picked from commit 364b088)
1 parent 176baf9 commit 96ec9be

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

src/compiler/parser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4051,7 +4051,7 @@ namespace ts {
40514051
setDecoratorContext(/*val*/ true);
40524052
}
40534053

4054-
return finishNode(node);
4054+
return addJSDocComment(finishNode(node));
40554055
}
40564056

40574057
function parseOptionalIdentifier() {
@@ -4335,13 +4335,13 @@ namespace ts {
43354335
const labeledStatement = <LabeledStatement>createNode(SyntaxKind.LabeledStatement, fullStart);
43364336
labeledStatement.label = <Identifier>expression;
43374337
labeledStatement.statement = parseStatement();
4338-
return finishNode(labeledStatement);
4338+
return addJSDocComment(finishNode(labeledStatement));
43394339
}
43404340
else {
43414341
const expressionStatement = <ExpressionStatement>createNode(SyntaxKind.ExpressionStatement, fullStart);
43424342
expressionStatement.expression = expression;
43434343
parseSemicolon();
4344-
return finishNode(expressionStatement);
4344+
return addJSDocComment(finishNode(expressionStatement));
43454345
}
43464346
}
43474347

src/compiler/utilities.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,19 @@ namespace ts {
12071207
node.parent.parent.parent.kind === SyntaxKind.VariableStatement;
12081208

12091209
const variableStatementNode = isInitializerOfVariableDeclarationInStatement ? node.parent.parent.parent : undefined;
1210-
return variableStatementNode && variableStatementNode.jsDocComment;
1210+
if (variableStatementNode) {
1211+
return variableStatementNode.jsDocComment;
1212+
}
1213+
1214+
// Also recognize when the node is the RHS of an assignment expression
1215+
const isSourceOfAssignmentExpressionStatement =
1216+
node.parent && node.parent.parent &&
1217+
node.parent.kind === SyntaxKind.BinaryExpression &&
1218+
(node.parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken &&
1219+
node.parent.parent.kind === SyntaxKind.ExpressionStatement;
1220+
if (isSourceOfAssignmentExpressionStatement) {
1221+
return node.parent.parent.jsDocComment;
1222+
}
12111223
}
12121224

12131225
return undefined;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @allowNonTsExtensions: true
4+
// @Filename: file.js
5+
//// /**
6+
//// * @param {number} a
7+
//// * @param {string} b
8+
//// */
9+
//// exports.foo = function(a, b) {
10+
//// a/*a*/;
11+
//// b/*b*/
12+
//// };
13+
14+
goTo.marker('a');
15+
edit.insert('.');
16+
verify.completionListContains('toFixed', undefined, undefined, 'method');
17+
18+
19+
goTo.marker('b');
20+
edit.insert('.');
21+
verify.completionListContains('substr', undefined, undefined, 'method');

0 commit comments

Comments
 (0)