Skip to content

Commit 8564a8b

Browse files
Add support for variadic JSDoc types.
1 parent 7ff85b3 commit 8564a8b

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

src/compiler/checker.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -3710,7 +3710,7 @@ module ts {
37103710
// NYI:
37113711
break;
37123712
case SyntaxKind.JSDocVariadicType:
3713-
return getTypeFromJSDocType((<JSDocVariadicType>jsDocType).type);
3713+
return getTypeFromJSDocVariadicType(<JSDocVariadicType>jsDocType);
37143714
case SyntaxKind.JSDocConstructorType:
37153715
// NYI:
37163716
break;
@@ -3721,6 +3721,13 @@ module ts {
37213721
}
37223722
}
37233723

3724+
function getTypeFromJSDocVariadicType(node: JSDocVariadicType): Type {
3725+
let type = getTypeFromJSDocType(node.type);
3726+
if (type) {
3727+
return createArrayType(type);
3728+
}
3729+
}
3730+
37243731
function getTypeForJSDocTypeReference(node: JSDocTypeReference): Type {
37253732
if (node.name.kind === SyntaxKind.Identifier) {
37263733
switch ((<Identifier>node.name).text) {

src/compiler/utilities.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,26 @@ module ts {
820820
}
821821

822822
export function hasRestParameters(s: SignatureDeclaration): boolean {
823-
return s.parameters.length > 0 && s.parameters[s.parameters.length - 1].dotDotDotToken !== undefined;
823+
let lastParameter = lastOrUndefined(s.parameters);
824+
if (!lastParameter) {
825+
return false;
826+
}
827+
828+
if (s.parserContextFlags & ParserContextFlags.JavaScriptFile) {
829+
if (lastParameter.name.kind === SyntaxKind.Identifier) {
830+
let lastParameterName = (<Identifier>lastParameter.name).text;
831+
832+
let docComment = getJSDocComment(s, getSourceFileOfNode(s));
833+
if (docComment) {
834+
let parameter = forEach(docComment.parameters, p => p.name === lastParameterName ? p : undefined);
835+
if (parameter) {
836+
return parameter.type.kind === SyntaxKind.JSDocVariadicType;
837+
}
838+
}
839+
}
840+
}
841+
842+
return lastParameter.dotDotDotToken !== undefined;
824843
}
825844

826845
export function isLiteralKind(kind: SyntaxKind): boolean {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
///<reference path="fourslash.ts" />
2+
3+
// @allowNonTsExtensions: true
4+
// @Filename: Foo.js
5+
/////**
6+
//// * @param {...number} a
7+
//// */
8+
////function foo(a) {
9+
//// a./**/
10+
////}
11+
12+
debugger;
13+
goTo.marker();
14+
verify.completionListContains("concat", /*displayText:*/ undefined, /*documentation*/ undefined, "method");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
///<reference path="fourslash.ts" />
2+
3+
// @allowNonTsExtensions: true
4+
// @Filename: Foo.js
5+
/////**
6+
//// * @param {...number} a
7+
//// */
8+
////function foo(a) {
9+
//// a[0]./**/
10+
////}
11+
12+
goTo.marker();
13+
verify.completionListContains("toExponential", /*displayText:*/ undefined, /*documentation*/ undefined, "method");

0 commit comments

Comments
 (0)