Fix crash in use-before-def checking of enum tag (#27350) (#27354)

This commit is contained in:
Nathan Shively-Sanders 2018-09-26 09:05:18 -07:00 committed by GitHub
parent b065902a99
commit 4fac5f26dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 1 deletions

View File

@ -1711,7 +1711,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");

View File

@ -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))

View File

@ -0,0 +1,14 @@
=== tests/cases/conformance/jsdoc/bug27134.js ===
/**
* @enum {number}
*/
var foo = { };
>foo : typeof foo
>{ } : {}
/**
* @type {foo}
*/
var s;
>s : number

View File

@ -0,0 +1,13 @@
// @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: bug27134.js
/**
* @enum {number}
*/
var foo = { };
/**
* @type {foo}
*/
var s;