Skip to content

Commit 311f8dd

Browse files
committed
Merge pull request #7309 from RyanCavanaugh/fix6878
Support JSDoc on class / obj. literal getters
2 parents fcfc411 + 65f09d6 commit 311f8dd

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,12 +2958,22 @@ namespace ts {
29582958
function getTypeOfAccessors(symbol: Symbol): Type {
29592959
const links = getSymbolLinks(symbol);
29602960
if (!links.type) {
2961+
const getter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.GetAccessor);
2962+
const setter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.SetAccessor);
2963+
2964+
if (getter && getter.flags & NodeFlags.JavaScriptFile) {
2965+
const jsDocType = getTypeForVariableLikeDeclarationFromJSDocComment(getter);
2966+
if (jsDocType) {
2967+
return links.type = jsDocType;
2968+
}
2969+
}
2970+
29612971
if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
29622972
return unknownType;
29632973
}
2964-
const getter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.GetAccessor);
2965-
const setter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.SetAccessor);
2974+
29662975
let type: Type;
2976+
29672977
// First try to see if the user specified a return type on the get-accessor.
29682978
const getterReturnType = getAnnotatedAccessorType(getter);
29692979
if (getterReturnType) {

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3932,7 +3932,7 @@ namespace ts {
39323932

39333933
function tryParseAccessorDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray): AccessorDeclaration {
39343934
if (parseContextualModifier(SyntaxKind.GetKeyword)) {
3935-
return parseAccessorDeclaration(SyntaxKind.GetAccessor, fullStart, decorators, modifiers);
3935+
return addJSDocComment(parseAccessorDeclaration(SyntaxKind.GetAccessor, fullStart, decorators, modifiers));
39363936
}
39373937
else if (parseContextualModifier(SyntaxKind.SetKeyword)) {
39383938
return parseAccessorDeclaration(SyntaxKind.SetAccessor, fullStart, decorators, modifiers);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @allowNonTsExtensions: true
4+
// @Filename: file.js
5+
//// let x = {
6+
//// /** @type {number} */
7+
//// get m() {
8+
//// return undefined;
9+
//// }
10+
//// }
11+
//// x.m/*1*/;
12+
////
13+
//// class Foo {
14+
//// /** @type {string} */
15+
//// get b() {
16+
//// return undefined;
17+
//// }
18+
//// }
19+
//// var y = new Foo();
20+
//// y.b/*2*/;
21+
22+
goTo.marker('1');
23+
edit.insert('.');
24+
verify.memberListContains('toFixed', undefined, undefined, 'method');
25+
edit.backspace();
26+
27+
goTo.marker('2');
28+
edit.insert('.');
29+
verify.memberListContains('substr', undefined, undefined, 'method');

0 commit comments

Comments
 (0)