Skip to content

Commit b50c37d

Browse files
authored
No assert for nameless typedefs (microsoft#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 microsoft#26693
1 parent 0dbad04 commit b50c37d

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

src/compiler/utilities.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4853,13 +4853,13 @@ namespace ts {
48534853
if (isDeclaration(hostNode)) {
48544854
return getDeclarationIdentifier(hostNode);
48554855
}
4856-
// Covers remaining cases
4856+
// Covers remaining cases (returning undefined if none match).
48574857
switch (hostNode.kind) {
48584858
case SyntaxKind.VariableStatement:
48594859
if (hostNode.declarationList && hostNode.declarationList.declarations[0]) {
48604860
return getDeclarationIdentifier(hostNode.declarationList.declarations[0]);
48614861
}
4862-
return undefined;
4862+
break;
48634863
case SyntaxKind.ExpressionStatement:
48644864
const expr = hostNode.expression;
48654865
switch (expr.kind) {
@@ -4871,20 +4871,16 @@ namespace ts {
48714871
return arg;
48724872
}
48734873
}
4874-
return undefined;
4875-
case SyntaxKind.EndOfFileToken:
4876-
return undefined;
4874+
break;
48774875
case SyntaxKind.ParenthesizedExpression: {
48784876
return getDeclarationIdentifier(hostNode.expression);
48794877
}
48804878
case SyntaxKind.LabeledStatement: {
48814879
if (isDeclaration(hostNode.statement) || isExpression(hostNode.statement)) {
48824880
return getDeclarationIdentifier(hostNode.statement);
48834881
}
4884-
return undefined;
4882+
break;
48854883
}
4886-
default:
4887-
Debug.assertNever(hostNode, "Found typedef tag attached to node which it should not be!");
48884884
}
48894885
}
48904886

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tests/cases/conformance/jsdoc/bug26693.js(1,15): error TS2304: Cannot find name 'module'.
2+
tests/cases/conformance/jsdoc/bug26693.js(1,21): error TS1005: '}' expected.
3+
tests/cases/conformance/jsdoc/bug26693.js(2,22): error TS2307: Cannot find module 'nope'.
4+
5+
6+
==== tests/cases/conformance/jsdoc/bug26693.js (3 errors) ====
7+
/** @typedef {module:locale} hi */
8+
~~~~~~
9+
!!! error TS2304: Cannot find name 'module'.
10+
~
11+
!!! error TS1005: '}' expected.
12+
import { nope } from 'nope';
13+
~~~~~~
14+
!!! error TS2307: Cannot find module 'nope'.
15+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/conformance/jsdoc/bug26693.js ===
2+
/** @typedef {module:locale} hi */
3+
import { nope } from 'nope';
4+
>nope : Symbol(nope, Decl(bug26693.js, 1, 8))
5+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/conformance/jsdoc/bug26693.js ===
2+
/** @typedef {module:locale} hi */
3+
import { nope } from 'nope';
4+
>nope : any
5+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @noEmit: true
2+
// @allowJs: true
3+
// @checkJs: true
4+
// @Filename: bug26693.js
5+
6+
/** @typedef {module:locale} hi */
7+
import { nope } from 'nope';

0 commit comments

Comments
 (0)