Skip to content

Recognize the RHS of assignments as the JSDoc target expression #6698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4051,7 +4051,7 @@ namespace ts {
setDecoratorContext(/*val*/ true);
}

return finishNode(node);
return addJSDocComment(finishNode(node));
}

function parseOptionalIdentifier() {
Expand Down Expand Up @@ -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));
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,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;
Expand Down
21 changes: 21 additions & 0 deletions tests/cases/fourslash/getJavaScriptCompletions18.ts
Original file line number Diff line number Diff line change
@@ -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');