From 5a845bf0fca604a9928ec8762266231ec62fafda Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 28 Jan 2016 15:48:18 -0800 Subject: [PATCH 1/4] Don't crash when return type jsdoc tag is malformed Fixes #6662 --- src/compiler/checker.ts | 2 +- .../fourslash/getJavaScriptQuickInfo7.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/getJavaScriptQuickInfo7.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 784d3ef67e822..43b91551a2914 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10344,7 +10344,7 @@ namespace ts { function getReturnTypeFromJSDocComment(func: SignatureDeclaration | FunctionDeclaration): Type { const returnTag = getJSDocReturnTag(func); - if (returnTag) { + if (returnTag && returnTag.typeExpression) { return getTypeFromTypeNode(returnTag.typeExpression.type); } } diff --git a/tests/cases/fourslash/getJavaScriptQuickInfo7.ts b/tests/cases/fourslash/getJavaScriptQuickInfo7.ts new file mode 100644 index 0000000000000..9faf97e795171 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptQuickInfo7.ts @@ -0,0 +1,19 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: file.js +//// /** +//// * This is a very cool function that is very nice. +//// * @returns something +//// */ +//// function a1() { +//// try { +//// throw new Error('x'); +//// } catch (x) { x--; } +//// return 23; +//// } +//// +//// x - /**/a1() + +goTo.marker(); +verify.quickInfoExists(); \ No newline at end of file From 1f503f1b27fb52ee5dacd75bd9379908ce6ee68e Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 28 Jan 2016 16:07:06 -0800 Subject: [PATCH 2/4] Add explicit `return undefined;` --- src/compiler/checker.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 43b91551a2914..389fed3591614 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10347,6 +10347,8 @@ namespace ts { if (returnTag && returnTag.typeExpression) { return getTypeFromTypeNode(returnTag.typeExpression.type); } + + return undefined; } function createPromiseType(promisedType: Type): Type { From 95196886f7fb37078ddcbc2b85c8d171fc9e5a6e Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 1 Feb 2016 10:14:14 -0800 Subject: [PATCH 3/4] Fix lint --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 389fed3591614..5adcbcf59063b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10347,7 +10347,7 @@ namespace ts { if (returnTag && returnTag.typeExpression) { return getTypeFromTypeNode(returnTag.typeExpression.type); } - + return undefined; } From b15ff81384f33e17bb8e10e10d5992cd6727e68c Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 1 Feb 2016 21:48:16 -0800 Subject: [PATCH 4/4] Add malformed parameter test --- tests/cases/fourslash/getJavaScriptQuickInfo7.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/cases/fourslash/getJavaScriptQuickInfo7.ts b/tests/cases/fourslash/getJavaScriptQuickInfo7.ts index 9faf97e795171..5aa8474757d50 100644 --- a/tests/cases/fourslash/getJavaScriptQuickInfo7.ts +++ b/tests/cases/fourslash/getJavaScriptQuickInfo7.ts @@ -5,8 +5,9 @@ //// /** //// * This is a very cool function that is very nice. //// * @returns something +//// * @param p anotherthing //// */ -//// function a1() { +//// function a1(p) { //// try { //// throw new Error('x'); //// } catch (x) { x--; }