Skip to content

Commit 6e57c26

Browse files
author
Andy
authored
Support getJSDocCommentsAndTags for special property assignments (#20193)
1 parent 7c5a0ec commit 6e57c26

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/compiler/utilities.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ namespace ts {
14631463

14641464
/// Given a BinaryExpression, returns SpecialPropertyAssignmentKind for the various kinds of property
14651465
/// assignments we treat as special in the binder
1466-
export function getSpecialPropertyAssignmentKind(expr: ts.BinaryExpression): SpecialPropertyAssignmentKind {
1466+
export function getSpecialPropertyAssignmentKind(expr: BinaryExpression): SpecialPropertyAssignmentKind {
14671467
if (!isInJavaScriptFile(expr)) {
14681468
return SpecialPropertyAssignmentKind.None;
14691469
}
@@ -1609,22 +1609,25 @@ namespace ts {
16091609

16101610
function getJSDocCommentsAndTagsWorker(node: Node): void {
16111611
const parent = node.parent;
1612+
if (parent && (parent.kind === SyntaxKind.PropertyAssignment || getNestedModuleDeclaration(parent))) {
1613+
getJSDocCommentsAndTagsWorker(parent);
1614+
}
16121615
// Try to recognize this pattern when node is initializer of variable declaration and JSDoc comments are on containing variable statement.
16131616
// /**
16141617
// * @param {number} name
16151618
// * @returns {number}
16161619
// */
16171620
// var x = function(name) { return name.length; }
1618-
if (parent && (parent.kind === SyntaxKind.PropertyAssignment || getNestedModuleDeclaration(parent))) {
1619-
getJSDocCommentsAndTagsWorker(parent);
1620-
}
16211621
if (parent && parent.parent &&
16221622
(getSingleVariableOfVariableStatement(parent.parent, node) || getSourceOfAssignment(parent.parent))) {
16231623
getJSDocCommentsAndTagsWorker(parent.parent);
16241624
}
16251625
if (parent && parent.parent && parent.parent.parent && getSingleInitializerOfVariableStatement(parent.parent.parent, node)) {
16261626
getJSDocCommentsAndTagsWorker(parent.parent.parent);
16271627
}
1628+
if (isBinaryExpression(node) && getSpecialPropertyAssignmentKind(node) !== SpecialPropertyAssignmentKind.None) {
1629+
getJSDocCommentsAndTagsWorker(parent);
1630+
}
16281631

16291632
// Pull parameter comments from declaring function as well
16301633
if (node.kind === SyntaxKind.Parameter) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @allowJs: true
2+
// @Filename: /a.js
3+
////class C {
4+
//// constructor() {
5+
//// /** Doc */
6+
//// this./**/x = 0;
7+
//// }
8+
////}
9+
10+
verify.quickInfoAt("", "(property) C.x: number", "Doc ");

0 commit comments

Comments
 (0)