Skip to content

Commit 37441e1

Browse files
committed
Recognize object literal method JSDoc comments
Fixes microsoft#6825 (cherry picked from commit 8aad976)
1 parent 569f0b2 commit 37441e1

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

src/compiler/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3995,7 +3995,7 @@ namespace ts {
39953995
shorthandDeclaration.equalsToken = equalsToken;
39963996
shorthandDeclaration.objectAssignmentInitializer = allowInAnd(parseAssignmentExpressionOrHigher);
39973997
}
3998-
return finishNode(shorthandDeclaration);
3998+
return addJSDocComment(finishNode(shorthandDeclaration));
39993999
}
40004000
else {
40014001
const propertyAssignment = <PropertyAssignment>createNode(SyntaxKind.PropertyAssignment, fullStart);
@@ -4004,7 +4004,7 @@ namespace ts {
40044004
propertyAssignment.questionToken = questionToken;
40054005
parseExpected(SyntaxKind.ColonToken);
40064006
propertyAssignment.initializer = allowInAnd(parseAssignmentExpressionOrHigher);
4007-
return finishNode(propertyAssignment);
4007+
return addJSDocComment(finishNode(propertyAssignment));
40084008
}
40094009
}
40104010

src/compiler/utilities.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,11 @@ namespace ts {
12241224
if (isSourceOfAssignmentExpressionStatement) {
12251225
return node.parent.parent.jsDocComment;
12261226
}
1227+
1228+
const isPropertyAssignmentExpression = node.parent && node.parent.kind === SyntaxKind.PropertyAssignment;
1229+
if (isPropertyAssignmentExpression) {
1230+
return node.parent.jsDocComment;
1231+
}
12271232
}
12281233

12291234
return undefined;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
///<reference path="fourslash.ts" />
2+
3+
// @allowNonTsExtensions: true
4+
// @Filename: Foo.js
5+
6+
//// var someObject = {
7+
//// /**
8+
//// * @param {string} param1 Some string param.
9+
//// * @param {number} parm2 Some number param.
10+
//// */
11+
//// someMethod: function(param1, param2) {
12+
//// console.log(param1/*1*/);
13+
//// return false;
14+
//// },
15+
//// /**
16+
//// * @param {number} p1 Some number param.
17+
//// */
18+
//// otherMethod(p1) {
19+
//// p1/*2*/
20+
//// }
21+
////
22+
//// };
23+
24+
goTo.marker('1');
25+
edit.insert('.');
26+
verify.memberListContains('substr', undefined, undefined, 'method');
27+
edit.backspace();
28+
29+
goTo.marker('2');
30+
edit.insert('.');
31+
verify.memberListContains('toFixed', undefined, undefined, 'method');
32+
edit.backspace();

0 commit comments

Comments
 (0)