No assert for nameless typedefs (#26695)

The assert is over-optimistic and should be removed until we can parse
every possible thing that people might put in a JSDoc type position.

Fixes #26693
This commit is contained in:
Nathan Shively-Sanders
2018-08-27 14:12:14 -07:00
parent 820220077b
commit 945fa541c3
5 changed files with 36 additions and 8 deletions

View File

@@ -4814,13 +4814,13 @@ namespace ts {
if (isDeclaration(hostNode)) {
return getDeclarationIdentifier(hostNode);
}
// Covers remaining cases
// Covers remaining cases (returning undefined if none match).
switch (hostNode.kind) {
case SyntaxKind.VariableStatement:
if (hostNode.declarationList && hostNode.declarationList.declarations[0]) {
return getDeclarationIdentifier(hostNode.declarationList.declarations[0]);
}
return undefined;
break;
case SyntaxKind.ExpressionStatement:
const expr = hostNode.expression;
switch (expr.kind) {
@@ -4832,9 +4832,7 @@ namespace ts {
return arg;
}
}
return undefined;
case SyntaxKind.EndOfFileToken:
return undefined;
break;
case SyntaxKind.ParenthesizedExpression: {
return getDeclarationIdentifier(hostNode.expression);
}
@@ -4842,10 +4840,8 @@ namespace ts {
if (isDeclaration(hostNode.statement) || isExpression(hostNode.statement)) {
return getDeclarationIdentifier(hostNode.statement);
}
return undefined;
break;
}
default:
Debug.assertNever(hostNode, "Found typedef tag attached to node which it should not be!");
}
}

View File

@@ -0,0 +1,15 @@
tests/cases/conformance/jsdoc/bug26693.js(1,15): error TS2304: Cannot find name 'module'.
tests/cases/conformance/jsdoc/bug26693.js(1,21): error TS1005: '}' expected.
tests/cases/conformance/jsdoc/bug26693.js(2,22): error TS2307: Cannot find module 'nope'.
==== tests/cases/conformance/jsdoc/bug26693.js (3 errors) ====
/** @typedef {module:locale} hi */
~~~~~~
!!! error TS2304: Cannot find name 'module'.
~
!!! error TS1005: '}' expected.
import { nope } from 'nope';
~~~~~~
!!! error TS2307: Cannot find module 'nope'.

View File

@@ -0,0 +1,5 @@
=== tests/cases/conformance/jsdoc/bug26693.js ===
/** @typedef {module:locale} hi */
import { nope } from 'nope';
>nope : Symbol(nope, Decl(bug26693.js, 1, 8))

View File

@@ -0,0 +1,5 @@
=== tests/cases/conformance/jsdoc/bug26693.js ===
/** @typedef {module:locale} hi */
import { nope } from 'nope';
>nope : any

View File

@@ -0,0 +1,7 @@
// @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: bug26693.js
/** @typedef {module:locale} hi */
import { nope } from 'nope';