Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,9 @@ namespace ts {
function checkResolvedBlockScopedVariable(result: Symbol, errorLocation: Node): void {
Debug.assert(!!(result.flags & SymbolFlags.BlockScopedVariable || result.flags & SymbolFlags.Class || result.flags & SymbolFlags.Enum));
// Block-scoped variables cannot be used before their definition
const declaration = forEach(result.declarations, d => isBlockOrCatchScoped(d) || isClassLike(d) || (d.kind === SyntaxKind.EnumDeclaration) ? d : undefined);
const declaration = find(
result.declarations,
d => isBlockOrCatchScoped(d) || isClassLike(d) || (d.kind === SyntaxKind.EnumDeclaration) || isInJSFile(d) && !!getJSDocEnumTag(d));

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

Expand Down
13 changes: 13 additions & 0 deletions tests/baselines/reference/enumTagUseBeforeDefCrash.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/conformance/jsdoc/bug27134.js ===
/**
* @enum {number}
*/
var foo = { };
>foo : Symbol(foo, Decl(bug27134.js, 3, 3))

/**
* @type {foo}
*/
var s;
>s : Symbol(s, Decl(bug27134.js, 8, 3))

14 changes: 14 additions & 0 deletions tests/baselines/reference/enumTagUseBeforeDefCrash.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
=== tests/cases/conformance/jsdoc/bug27134.js ===
/**
* @enum {number}
*/
var foo = { };
>foo : typeof foo
>{ } : {}

/**
* @type {foo}
*/
var s;
>s : number

13 changes: 13 additions & 0 deletions tests/cases/conformance/jsdoc/enumTagUseBeforeDefCrash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: bug27134.js
/**
* @enum {number}
*/
var foo = { };

/**
* @type {foo}
*/
var s;