Add undefined checks for malformed type tags

Fixes #7002
This commit is contained in:
Ryan Cavanaugh 2016-02-10 10:41:52 -08:00
parent 30e1f8344e
commit 5b1469aece
6 changed files with 58 additions and 2 deletions

View file

@ -2613,7 +2613,7 @@ namespace ts {
function getJSDocTypeForVariableLikeDeclarationFromJSDocComment(declaration: VariableLikeDeclaration): JSDocType {
// First, see if this node has an @type annotation on it directly.
const typeTag = getJSDocTypeTag(declaration);
if (typeTag) {
if (typeTag && typeTag.typeExpression) {
return typeTag.typeExpression.type;
}
@ -2623,7 +2623,7 @@ namespace ts {
// @type annotation might have been on the variable statement, try that instead.
const annotation = getJSDocTypeTag(declaration.parent.parent);
if (annotation) {
if (annotation && annotation.typeExpression) {
return annotation.typeExpression.type;
}
}

View file

@ -938,6 +938,9 @@ namespace Harness {
}
}
}
else if (name === 'suppressOutputPathCheck') {
options.suppressOutputPathCheck = true;
}
else {
throw new Error(`Unknown compiler option '${name}'.`);
}

View file

@ -0,0 +1,17 @@
//// [myFile02.js]
/**
* Checks if `value` is classified as an `Array` object.
*
* @type Function
*/
var isArray = Array.isArray;
//// [myFile02.js]
/**
* Checks if `value` is classified as an `Array` object.
*
* @type Function
*/
var isArray = Array.isArray;

View file

@ -0,0 +1,13 @@
=== tests/cases/conformance/salsa/myFile02.js ===
/**
* Checks if `value` is classified as an `Array` object.
*
* @type Function
*/
var isArray = Array.isArray;
>isArray : Symbol(isArray, Decl(myFile02.js, 6, 3))
>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.d.ts, --, --))
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.d.ts, --, --))

View file

@ -0,0 +1,13 @@
=== tests/cases/conformance/salsa/myFile02.js ===
/**
* Checks if `value` is classified as an `Array` object.
*
* @type Function
*/
var isArray = Array.isArray;
>isArray : (arg: any) => arg is any[]
>Array.isArray : (arg: any) => arg is any[]
>Array : ArrayConstructor
>isArray : (arg: any) => arg is any[]

View file

@ -0,0 +1,10 @@
// @allowJS: true
// @suppressOutputPathCheck: true
// @filename: myFile02.js
/**
* Checks if `value` is classified as an `Array` object.
*
* @type Function
*/
var isArray = Array.isArray;