Skip to content

Commit

Permalink
Fix crash in use-before-def checking of enum tag (#27350)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandersn authored Sep 25, 2018
1 parent 29dbbff commit 53105b3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
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;

0 comments on commit 53105b3

Please sign in to comment.