Skip to content

Commit 0774bb8

Browse files
authored
Fix crash on property assignment of unresolved module (#28606)
Previously, the compiler would crash when binding a non-top-level property assignment on the symbol of an unresolved module: ```js import x from 'arglebaz' { x.bar = 1 } ``` That's because `x` looks like an alias but doesn't have a valueDeclaration (since there is no file named 'arglebaz'), and the new code for binding Object.defineProperty calls forgot to check for an undefined valueDeclaration. This change adds the checks for an undefined valueDeclaration.
1 parent 79b9fa5 commit 0774bb8

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2608,7 +2608,7 @@ namespace ts {
26082608
return true;
26092609
}
26102610
const node = symbol.valueDeclaration;
2611-
if (isCallExpression(node)) {
2611+
if (node && isCallExpression(node)) {
26122612
return !!getAssignedExpandoInitializer(node);
26132613
}
26142614
let init = !node ? undefined :
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/conformance/salsa/bug28576.js(1,15): error TS2307: Cannot find module 'arglebaz'.
2+
3+
4+
==== tests/cases/conformance/salsa/bug28576.js (1 errors) ====
5+
import x from 'arglebaz'
6+
~~~~~~~~~~
7+
!!! error TS2307: Cannot find module 'arglebaz'.
8+
{
9+
x.bar = 1
10+
}
11+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/conformance/salsa/bug28576.js ===
2+
import x from 'arglebaz'
3+
>x : Symbol(x, Decl(bug28576.js, 0, 6))
4+
{
5+
x.bar = 1
6+
>x : Symbol(x, Decl(bug28576.js, 0, 6))
7+
}
8+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/conformance/salsa/bug28576.js ===
2+
import x from 'arglebaz'
3+
>x : any
4+
{
5+
x.bar = 1
6+
>x.bar = 1 : 1
7+
>x.bar : any
8+
>x : any
9+
>bar : any
10+
>1 : 1
11+
}
12+
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: bug28576.js
5+
import x from 'arglebaz'
6+
{
7+
x.bar = 1
8+
}

0 commit comments

Comments
 (0)