From f0e70cbf0fc1f9f3b65d36f4ece8db5e6719dde0 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 28 Jan 2016 15:48:18 -0800 Subject: [PATCH] Don't crash when return type jsdoc tag is malformed Fixes #6662 (cherry picked from commit 5a845bf0fca604a9928ec8762266231ec62fafda) --- 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 c975127a62f..446f426e6d3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10356,7 +10356,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 00000000000..9faf97e7951 --- /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