Fix crash in JS when checking destructuring shorthand assignment (#25529)

This commit is contained in:
Nathan Shively-Sanders 2018-07-10 08:32:56 -07:00 committed by GitHub
parent b3b6c3bdbc
commit 60c0dfeb25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 1 deletions

View File

@ -21128,7 +21128,7 @@ namespace ts {
getUnionType([removeDefinitelyFalsyTypes(leftType), rightType], UnionReduction.Subtype) :
leftType;
case SyntaxKind.EqualsToken:
const special = getSpecialPropertyAssignmentKind(left.parent as BinaryExpression);
const special = isBinaryExpression(left.parent) ? getSpecialPropertyAssignmentKind(left.parent) : SpecialPropertyAssignmentKind.None;
checkSpecialAssignment(special, right);
if (isJSSpecialPropertyAssignment(special)) {
return leftType;

View File

@ -0,0 +1,11 @@
tests/cases/compiler/bug25434.js(4,9): error TS2304: Cannot find name 'b'.
==== tests/cases/compiler/bug25434.js (1 errors) ====
// should not crash while checking
function Test({ b = '' } = {}) {}
Test(({ b = '5' } = {}));
~
!!! error TS2304: Cannot find name 'b'.

View File

@ -0,0 +1,10 @@
=== tests/cases/compiler/bug25434.js ===
// should not crash while checking
function Test({ b = '' } = {}) {}
>Test : Symbol(Test, Decl(bug25434.js, 0, 0))
>b : Symbol(b, Decl(bug25434.js, 1, 15))
Test(({ b = '5' } = {}));
>Test : Symbol(Test, Decl(bug25434.js, 0, 0))
>b : Symbol(b, Decl(bug25434.js, 3, 7))

View File

@ -0,0 +1,17 @@
=== tests/cases/compiler/bug25434.js ===
// should not crash while checking
function Test({ b = '' } = {}) {}
>Test : ({ b }?: { [x: string]: any; }) => void
>b : string
>'' : ""
>{} : { b?: string; }
Test(({ b = '5' } = {}));
>Test(({ b = '5' } = {})) : void
>Test : ({ b }?: { [x: string]: any; }) => void
>({ b = '5' } = {}) : { b?: any; }
>{ b = '5' } = {} : { b?: any; }
>{ b = '5' } : { [x: string]: any; b?: any; }
>b : any
>{} : { b?: any; }

View File

@ -0,0 +1,8 @@
// @allowjs: true
// @checkjs: true
// @noEmit: true
// @Filename: bug25434.js
// should not crash while checking
function Test({ b = '' } = {}) {}
Test(({ b = '5' } = {}));