Skip to content

Commit 945fa54

Browse files
committed
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
1 parent 8202200 commit 945fa54

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
@@ -4814,13 +4814,13 @@ namespace ts {
48144814
if (isDeclaration(hostNode)) {
48154815
return getDeclarationIdentifier(hostNode);
48164816
}
4817-
// Covers remaining cases
4817+
// Covers remaining cases (returning undefined if none match).
48184818
switch (hostNode.kind) {
48194819
case SyntaxKind.VariableStatement:
48204820
if (hostNode.declarationList && hostNode.declarationList.declarations[0]) {
48214821
return getDeclarationIdentifier(hostNode.declarationList.declarations[0]);
48224822
}
4823-
return undefined;
4823+
break;
48244824
case SyntaxKind.ExpressionStatement:
48254825
const expr = hostNode.expression;
48264826
switch (expr.kind) {
@@ -4832,20 +4832,16 @@ namespace ts {
48324832
return arg;
48334833
}
48344834
}
4835-
return undefined;
4836-
case SyntaxKind.EndOfFileToken:
4837-
return undefined;
4835+
break;
48384836
case SyntaxKind.ParenthesizedExpression: {
48394837
return getDeclarationIdentifier(hostNode.expression);
48404838
}
48414839
case SyntaxKind.LabeledStatement: {
48424840
if (isDeclaration(hostNode.statement) || isExpression(hostNode.statement)) {
48434841
return getDeclarationIdentifier(hostNode.statement);
48444842
}
4845-
return undefined;
4843+
break;
48464844
}
4847-
default:
4848-
Debug.assertNever(hostNode, "Found typedef tag attached to node which it should not be!");
48494845
}
48504846
}
48514847

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)