mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-10 06:41:59 -06:00
Recognize the RHS of assignments as the JSDoc target expression
Fixes #6552 (cherry picked from commit 364b08854bc1face5c9b38301bb83c7346f1ccce)
This commit is contained in:
parent
176baf904a
commit
96ec9be665
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
21
tests/cases/fourslash/getJavaScriptCompletions18.ts
Normal file
21
tests/cases/fourslash/getJavaScriptCompletions18.ts
Normal 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');
|
||||
Loading…
x
Reference in New Issue
Block a user