Skip to content

Support JSDoc on class / obj. literal getters #7309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2958,12 +2958,22 @@ namespace ts {
function getTypeOfAccessors(symbol: Symbol): Type {
const links = getSymbolLinks(symbol);
if (!links.type) {
const getter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.GetAccessor);
const setter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.SetAccessor);

if (getter && getter.flags & NodeFlags.JavaScriptFile) {
const jsDocType = getTypeForVariableLikeDeclarationFromJSDocComment(getter);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the param type of the setter function, we do this in TS..

if (jsDocType) {
return links.type = jsDocType;
}
}

if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
return unknownType;
}
const getter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.GetAccessor);
const setter = <AccessorDeclaration>getDeclarationOfKind(symbol, SyntaxKind.SetAccessor);

let type: Type;

// First try to see if the user specified a return type on the get-accessor.
const getterReturnType = getAnnotatedAccessorType(getter);
if (getterReturnType) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3954,7 +3954,7 @@ namespace ts {

function tryParseAccessorDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray): AccessorDeclaration {
if (parseContextualModifier(SyntaxKind.GetKeyword)) {
return parseAccessorDeclaration(SyntaxKind.GetAccessor, fullStart, decorators, modifiers);
return addJSDocComment(parseAccessorDeclaration(SyntaxKind.GetAccessor, fullStart, decorators, modifiers));
}
else if (parseContextualModifier(SyntaxKind.SetKeyword)) {
return parseAccessorDeclaration(SyntaxKind.SetAccessor, fullStart, decorators, modifiers);
Expand Down
29 changes: 29 additions & 0 deletions tests/cases/fourslash/getJavaScriptQuickInfo8.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/// <reference path="fourslash.ts" />

// @allowNonTsExtensions: true
// @Filename: file.js
//// let x = {
//// /** @type {number} */
//// get m() {
//// return undefined;
//// }
//// }
//// x.m/*1*/;
////
//// class Foo {
//// /** @type {string} */
//// get b() {
//// return undefined;
//// }
//// }
//// var y = new Foo();
//// y.b/*2*/;

goTo.marker('1');
edit.insert('.');
verify.memberListContains('toFixed', undefined, undefined, 'method');
edit.backspace();

goTo.marker('2');
edit.insert('.');
verify.memberListContains('substr', undefined, undefined, 'method');