From 6e57c2630f147cde2ad92a8782d94c0e0287edf9 Mon Sep 17 00:00:00 2001 From: Andy Date: Tue, 21 Nov 2017 14:29:52 -0500 Subject: [PATCH] Support getJSDocCommentsAndTags for special property assignments (#20193) --- src/compiler/utilities.ts | 11 +++++++---- .../fourslash/quickInfoSpecialPropertyAssignment.ts | 10 ++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 tests/cases/fourslash/quickInfoSpecialPropertyAssignment.ts diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 46835bd94d..28520919e1 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1463,7 +1463,7 @@ namespace ts { /// Given a BinaryExpression, returns SpecialPropertyAssignmentKind for the various kinds of property /// assignments we treat as special in the binder - export function getSpecialPropertyAssignmentKind(expr: ts.BinaryExpression): SpecialPropertyAssignmentKind { + export function getSpecialPropertyAssignmentKind(expr: BinaryExpression): SpecialPropertyAssignmentKind { if (!isInJavaScriptFile(expr)) { return SpecialPropertyAssignmentKind.None; } @@ -1609,15 +1609,15 @@ namespace ts { function getJSDocCommentsAndTagsWorker(node: Node): void { const parent = node.parent; + if (parent && (parent.kind === SyntaxKind.PropertyAssignment || getNestedModuleDeclaration(parent))) { + getJSDocCommentsAndTagsWorker(parent); + } // Try to recognize this pattern when node is initializer of variable declaration and JSDoc comments are on containing variable statement. // /** // * @param {number} name // * @returns {number} // */ // var x = function(name) { return name.length; } - if (parent && (parent.kind === SyntaxKind.PropertyAssignment || getNestedModuleDeclaration(parent))) { - getJSDocCommentsAndTagsWorker(parent); - } if (parent && parent.parent && (getSingleVariableOfVariableStatement(parent.parent, node) || getSourceOfAssignment(parent.parent))) { getJSDocCommentsAndTagsWorker(parent.parent); @@ -1625,6 +1625,9 @@ namespace ts { if (parent && parent.parent && parent.parent.parent && getSingleInitializerOfVariableStatement(parent.parent.parent, node)) { getJSDocCommentsAndTagsWorker(parent.parent.parent); } + if (isBinaryExpression(node) && getSpecialPropertyAssignmentKind(node) !== SpecialPropertyAssignmentKind.None) { + getJSDocCommentsAndTagsWorker(parent); + } // Pull parameter comments from declaring function as well if (node.kind === SyntaxKind.Parameter) { diff --git a/tests/cases/fourslash/quickInfoSpecialPropertyAssignment.ts b/tests/cases/fourslash/quickInfoSpecialPropertyAssignment.ts new file mode 100644 index 0000000000..817e68f678 --- /dev/null +++ b/tests/cases/fourslash/quickInfoSpecialPropertyAssignment.ts @@ -0,0 +1,10 @@ +// @allowJs: true +// @Filename: /a.js +////class C { +//// constructor() { +//// /** Doc */ +//// this./**/x = 0; +//// } +////} + +verify.quickInfoAt("", "(property) C.x: number", "Doc ");