Skip to content
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
27 changes: 18 additions & 9 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3995,7 +3995,7 @@ namespace ts {
shorthandDeclaration.equalsToken = equalsToken;
shorthandDeclaration.objectAssignmentInitializer = allowInAnd(parseAssignmentExpressionOrHigher);
}
return finishNode(shorthandDeclaration);
return addJSDocComment(finishNode(shorthandDeclaration));
}
else {
const propertyAssignment = <PropertyAssignment>createNode(SyntaxKind.PropertyAssignment, fullStart);
Expand All @@ -4004,7 +4004,7 @@ namespace ts {
propertyAssignment.questionToken = questionToken;
parseExpected(SyntaxKind.ColonToken);
propertyAssignment.initializer = allowInAnd(parseAssignmentExpressionOrHigher);
return finishNode(propertyAssignment);
return addJSDocComment(finishNode(propertyAssignment));
}
}

Expand Down Expand Up @@ -5758,23 +5758,32 @@ namespace ts {
function parseJSDocParameter(): ParameterDeclaration {
const parameter = <ParameterDeclaration>createNode(SyntaxKind.Parameter);
parameter.type = parseJSDocType();
if (parseOptional(SyntaxKind.EqualsToken)) {
parameter.questionToken = createNode(SyntaxKind.EqualsToken);
}
return finishNode(parameter);
}

function parseJSDocTypeReference(): JSDocTypeReference {
const result = <JSDocTypeReference>createNode(SyntaxKind.JSDocTypeReference);
result.name = parseSimplePropertyName();

while (parseOptional(SyntaxKind.DotToken)) {
if (token === SyntaxKind.LessThanToken) {
result.typeArguments = parseTypeArguments();
break;
}
else {
result.name = parseQualifiedName(result.name);
if (token === SyntaxKind.LessThanToken) {
result.typeArguments = parseTypeArguments();
}
else {
while (parseOptional(SyntaxKind.DotToken)) {
if (token === SyntaxKind.LessThanToken) {
result.typeArguments = parseTypeArguments();
break;
}
else {
result.name = parseQualifiedName(result.name);
}
}
}


return finishNode(result);
}

Expand Down
16 changes: 11 additions & 5 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1216,13 +1216,19 @@ namespace ts {
}

// Also recognize when the node is the RHS of an assignment expression
const parent = node.parent;
const isSourceOfAssignmentExpressionStatement =
node.parent && node.parent.parent &&
node.parent.kind === SyntaxKind.BinaryExpression &&
(node.parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken &&
node.parent.parent.kind === SyntaxKind.ExpressionStatement;
parent && parent.parent &&
parent.kind === SyntaxKind.BinaryExpression &&
(parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken &&
parent.parent.kind === SyntaxKind.ExpressionStatement;
if (isSourceOfAssignmentExpressionStatement) {
return node.parent.parent.jsDocComment;
return parent.parent.jsDocComment;
}

const isPropertyAssignmentExpression = parent && parent.kind === SyntaxKind.PropertyAssignment;
if (isPropertyAssignmentExpression) {
return parent.jsDocComment;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3819,7 +3819,7 @@ namespace ts {
return undefined;
}

const { symbols, isMemberCompletion, isNewIdentifierLocation, location, isRightOfDot, isJsDocTagName } = completionData;
const { symbols, isMemberCompletion, isNewIdentifierLocation, location, isJsDocTagName } = completionData;

if (isJsDocTagName) {
// If the current position is a jsDoc tag name, only tag names should be provided for completion
Expand All @@ -3830,7 +3830,7 @@ namespace ts {

const entries: CompletionEntry[] = [];

if (isRightOfDot && isSourceFileJavaScript(sourceFile)) {
if (isSourceFileJavaScript(sourceFile)) {
const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries);
addRange(entries, getJavaScriptCompletionEntries(sourceFile, location.pos, uniqueNames));
}
Expand Down
15 changes: 15 additions & 0 deletions tests/cases/fourslash/getJavaScriptGlobalCompletions1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />

// @allowNonTsExtensions: true
// @Filename: Foo.js
//// function f() {
//// // helloWorld leaks from here into the global space?
//// if (helloWorld) {
//// return 3;
//// }
//// return 5;
//// }
////
//// hello/**/

verify.completionListContains('helloWorld');
12 changes: 12 additions & 0 deletions tests/cases/fourslash/jsDocFunctionSignatures2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
///<reference path="fourslash.ts" />

// @allowNonTsExtensions: true
// @Filename: Foo.js

//// /** @type {function(string, boolean=): number} */
//// var f6;
////
//// f6('', /**/false)

goTo.marker();
verify.currentSignatureHelpIs('f6(p0: string, p1?: boolean): number')
32 changes: 32 additions & 0 deletions tests/cases/fourslash/jsDocFunctionSignatures3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
///<reference path="fourslash.ts" />

// @allowNonTsExtensions: true
// @Filename: Foo.js

//// var someObject = {
//// /**
//// * @param {string} param1 Some string param.
//// * @param {number} parm2 Some number param.
//// */
//// someMethod: function(param1, param2) {
//// console.log(param1/*1*/);
//// return false;
//// },
//// /**
//// * @param {number} p1 Some number param.
//// */
//// otherMethod(p1) {
//// p1/*2*/
//// }
////
//// };

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

goTo.marker('2');
edit.insert('.');
verify.memberListContains('toFixed', undefined, undefined, 'method');
edit.backspace();
34 changes: 34 additions & 0 deletions tests/cases/fourslash/jsDocGenerics1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
///<reference path="fourslash.ts" />

// @allowNonTsExtensions: true
// @Filename: ref.d.ts
//// namespace Thing {
//// export interface Thung {
//// a: number;
//// ]
//// ]


// @Filename: Foo.js
////
//// /** @type {Array<number>} */
//// var v;
//// v[0]./*1*/
////
//// /** @type {{x: Array<Array<number>>}} */
//// var w;
//// w.x[0][0]./*2*/
////
//// /** @type {Array<Thing.Thung>} */
//// var x;
//// x[0].a./*3*/


goTo.marker('1');
verify.memberListContains("toFixed", /*displayText:*/ undefined, /*documentation*/ undefined, "method");

goTo.marker('2');
verify.memberListContains("toFixed", /*displayText:*/ undefined, /*documentation*/ undefined, "method");

goTo.marker('3');
verify.memberListContains("toFixed", /*displayText:*/ undefined, /*documentation*/ undefined, "method");