Skip to content

Commit 53105b3

Browse files
authored
Fix crash in use-before-def checking of enum tag (#27350)
1 parent 29dbbff commit 53105b3

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,9 @@ namespace ts {
17071707
function checkResolvedBlockScopedVariable(result: Symbol, errorLocation: Node): void {
17081708
Debug.assert(!!(result.flags & SymbolFlags.BlockScopedVariable || result.flags & SymbolFlags.Class || result.flags & SymbolFlags.Enum));
17091709
// Block-scoped variables cannot be used before their definition
1710-
const declaration = forEach(result.declarations, d => isBlockOrCatchScoped(d) || isClassLike(d) || (d.kind === SyntaxKind.EnumDeclaration) ? d : undefined);
1710+
const declaration = find(
1711+
result.declarations,
1712+
d => isBlockOrCatchScoped(d) || isClassLike(d) || (d.kind === SyntaxKind.EnumDeclaration) || isInJSFile(d) && !!getJSDocEnumTag(d));
17111713

17121714
if (declaration === undefined) return Debug.fail("Declaration to checkResolvedBlockScopedVariable is undefined");
17131715

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/conformance/jsdoc/bug27134.js ===
2+
/**
3+
* @enum {number}
4+
*/
5+
var foo = { };
6+
>foo : Symbol(foo, Decl(bug27134.js, 3, 3))
7+
8+
/**
9+
* @type {foo}
10+
*/
11+
var s;
12+
>s : Symbol(s, Decl(bug27134.js, 8, 3))
13+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/conformance/jsdoc/bug27134.js ===
2+
/**
3+
* @enum {number}
4+
*/
5+
var foo = { };
6+
>foo : typeof foo
7+
>{ } : {}
8+
9+
/**
10+
* @type {foo}
11+
*/
12+
var s;
13+
>s : number
14+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @noEmit: true
2+
// @allowJs: true
3+
// @checkJs: true
4+
// @Filename: bug27134.js
5+
/**
6+
* @enum {number}
7+
*/
8+
var foo = { };
9+
10+
/**
11+
* @type {foo}
12+
*/
13+
var s;

0 commit comments

Comments
 (0)