Skip to content

Commit 5b1469a

Browse files
committed
Add undefined checks for malformed type tags
Fixes microsoft#7002
1 parent 30e1f83 commit 5b1469a

File tree

6 files changed

+58
-2
lines changed

6 files changed

+58
-2
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,7 +2613,7 @@ namespace ts {
26132613
function getJSDocTypeForVariableLikeDeclarationFromJSDocComment(declaration: VariableLikeDeclaration): JSDocType {
26142614
// First, see if this node has an @type annotation on it directly.
26152615
const typeTag = getJSDocTypeTag(declaration);
2616-
if (typeTag) {
2616+
if (typeTag && typeTag.typeExpression) {
26172617
return typeTag.typeExpression.type;
26182618
}
26192619

@@ -2623,7 +2623,7 @@ namespace ts {
26232623

26242624
// @type annotation might have been on the variable statement, try that instead.
26252625
const annotation = getJSDocTypeTag(declaration.parent.parent);
2626-
if (annotation) {
2626+
if (annotation && annotation.typeExpression) {
26272627
return annotation.typeExpression.type;
26282628
}
26292629
}

src/harness/harness.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,9 @@ namespace Harness {
938938
}
939939
}
940940
}
941+
else if (name === 'suppressOutputPathCheck') {
942+
options.suppressOutputPathCheck = true;
943+
}
941944
else {
942945
throw new Error(`Unknown compiler option '${name}'.`);
943946
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [myFile02.js]
2+
3+
/**
4+
* Checks if `value` is classified as an `Array` object.
5+
*
6+
* @type Function
7+
*/
8+
var isArray = Array.isArray;
9+
10+
11+
//// [myFile02.js]
12+
/**
13+
* Checks if `value` is classified as an `Array` object.
14+
*
15+
* @type Function
16+
*/
17+
var isArray = Array.isArray;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/conformance/salsa/myFile02.js ===
2+
3+
/**
4+
* Checks if `value` is classified as an `Array` object.
5+
*
6+
* @type Function
7+
*/
8+
var isArray = Array.isArray;
9+
>isArray : Symbol(isArray, Decl(myFile02.js, 6, 3))
10+
>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.d.ts, --, --))
11+
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
12+
>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.d.ts, --, --))
13+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/conformance/salsa/myFile02.js ===
2+
3+
/**
4+
* Checks if `value` is classified as an `Array` object.
5+
*
6+
* @type Function
7+
*/
8+
var isArray = Array.isArray;
9+
>isArray : (arg: any) => arg is any[]
10+
>Array.isArray : (arg: any) => arg is any[]
11+
>Array : ArrayConstructor
12+
>isArray : (arg: any) => arg is any[]
13+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @allowJS: true
2+
// @suppressOutputPathCheck: true
3+
4+
// @filename: myFile02.js
5+
/**
6+
* Checks if `value` is classified as an `Array` object.
7+
*
8+
* @type Function
9+
*/
10+
var isArray = Array.isArray;

0 commit comments

Comments
 (0)