Recognize the RHS of assignments as the JSDoc target expression

Fixes #6552

(cherry picked from commit 364b08854bc1face5c9b38301bb83c7346f1ccce)
This commit is contained in:
Ryan Cavanaugh 2016-01-28 11:02:49 -08:00 committed by Bill Ticehurst
parent 176baf904a
commit 96ec9be665
3 changed files with 37 additions and 4 deletions

View File

@ -4051,7 +4051,7 @@ namespace ts {
setDecoratorContext(/*val*/ true);
}
return finishNode(node);
return addJSDocComment(finishNode(node));
}
function parseOptionalIdentifier() {
@ -4335,13 +4335,13 @@ namespace ts {
const labeledStatement = <LabeledStatement>createNode(SyntaxKind.LabeledStatement, fullStart);
labeledStatement.label = <Identifier>expression;
labeledStatement.statement = parseStatement();
return finishNode(labeledStatement);
return addJSDocComment(finishNode(labeledStatement));
}
else {
const expressionStatement = <ExpressionStatement>createNode(SyntaxKind.ExpressionStatement, fullStart);
expressionStatement.expression = expression;
parseSemicolon();
return finishNode(expressionStatement);
return addJSDocComment(finishNode(expressionStatement));
}
}

View File

@ -1207,7 +1207,19 @@ namespace ts {
node.parent.parent.parent.kind === SyntaxKind.VariableStatement;
const variableStatementNode = isInitializerOfVariableDeclarationInStatement ? node.parent.parent.parent : undefined;
return variableStatementNode && variableStatementNode.jsDocComment;
if (variableStatementNode) {
return variableStatementNode.jsDocComment;
}
// Also recognize when the node is the RHS of an assignment expression
const isSourceOfAssignmentExpressionStatement =
node.parent && node.parent.parent &&
node.parent.kind === SyntaxKind.BinaryExpression &&
(node.parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken &&
node.parent.parent.kind === SyntaxKind.ExpressionStatement;
if (isSourceOfAssignmentExpressionStatement) {
return node.parent.parent.jsDocComment;
}
}
return undefined;

View File

@ -0,0 +1,21 @@
/// <reference path="fourslash.ts" />
// @allowNonTsExtensions: true
// @Filename: file.js
//// /**
//// * @param {number} a
//// * @param {string} b
//// */
//// exports.foo = function(a, b) {
//// a/*a*/;
//// b/*b*/
//// };
goTo.marker('a');
edit.insert('.');
verify.completionListContains('toFixed', undefined, undefined, 'method');
goTo.marker('b');
edit.insert('.');
verify.completionListContains('substr', undefined, undefined, 'method');