Skip to content

Commit 60c0dfe

Browse files
authored
Fix crash in JS when checking destructuring shorthand assignment (microsoft#25529)
1 parent b3b6c3b commit 60c0dfe

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21128,7 +21128,7 @@ namespace ts {
2112821128
getUnionType([removeDefinitelyFalsyTypes(leftType), rightType], UnionReduction.Subtype) :
2112921129
leftType;
2113021130
case SyntaxKind.EqualsToken:
21131-
const special = getSpecialPropertyAssignmentKind(left.parent as BinaryExpression);
21131+
const special = isBinaryExpression(left.parent) ? getSpecialPropertyAssignmentKind(left.parent) : SpecialPropertyAssignmentKind.None;
2113221132
checkSpecialAssignment(special, right);
2113321133
if (isJSSpecialPropertyAssignment(special)) {
2113421134
return leftType;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/compiler/bug25434.js(4,9): error TS2304: Cannot find name 'b'.
2+
3+
4+
==== tests/cases/compiler/bug25434.js (1 errors) ====
5+
// should not crash while checking
6+
function Test({ b = '' } = {}) {}
7+
8+
Test(({ b = '5' } = {}));
9+
~
10+
!!! error TS2304: Cannot find name 'b'.
11+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/compiler/bug25434.js ===
2+
// should not crash while checking
3+
function Test({ b = '' } = {}) {}
4+
>Test : Symbol(Test, Decl(bug25434.js, 0, 0))
5+
>b : Symbol(b, Decl(bug25434.js, 1, 15))
6+
7+
Test(({ b = '5' } = {}));
8+
>Test : Symbol(Test, Decl(bug25434.js, 0, 0))
9+
>b : Symbol(b, Decl(bug25434.js, 3, 7))
10+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/compiler/bug25434.js ===
2+
// should not crash while checking
3+
function Test({ b = '' } = {}) {}
4+
>Test : ({ b }?: { [x: string]: any; }) => void
5+
>b : string
6+
>'' : ""
7+
>{} : { b?: string; }
8+
9+
Test(({ b = '5' } = {}));
10+
>Test(({ b = '5' } = {})) : void
11+
>Test : ({ b }?: { [x: string]: any; }) => void
12+
>({ b = '5' } = {}) : { b?: any; }
13+
>{ b = '5' } = {} : { b?: any; }
14+
>{ b = '5' } : { [x: string]: any; b?: any; }
15+
>b : any
16+
>{} : { b?: any; }
17+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @allowjs: true
2+
// @checkjs: true
3+
// @noEmit: true
4+
// @Filename: bug25434.js
5+
// should not crash while checking
6+
function Test({ b = '' } = {}) {}
7+
8+
Test(({ b = '5' } = {}));

0 commit comments

Comments
 (0)