Skip to content

Commit 479d306

Browse files
Knagissandersn
authored andcommitted
Fix crash in assigning function with this ref to alias (microsoft#34650)
1 parent 1cbbe28 commit 479d306

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2709,7 +2709,7 @@ namespace ts {
27092709
}
27102710
}
27112711

2712-
if (constructorSymbol) {
2712+
if (constructorSymbol && constructorSymbol.valueDeclaration) {
27132713
// Declare a 'member' if the container is an ES5 class or ES6 constructor
27142714
constructorSymbol.members = constructorSymbol.members || createSymbolTable();
27152715
// It's acceptable for multiple 'this' assignments of the same identifier to occur
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
tests/cases/conformance/salsa/main.js(2,13): error TS2339: Property 'foo' does not exist on type 'Alias'.
2-
tests/cases/conformance/salsa/main.js(4,9): error TS2339: Property 'foo' does not exist on type 'Alias'.
2+
tests/cases/conformance/salsa/main.js(3,13): error TS2339: Property 'func' does not exist on type 'Alias'.
3+
tests/cases/conformance/salsa/main.js(3,38): error TS2339: Property '_func' does not exist on type 'Alias'.
4+
tests/cases/conformance/salsa/main.js(5,9): error TS2339: Property 'foo' does not exist on type 'Alias'.
5+
tests/cases/conformance/salsa/main.js(6,9): error TS2339: Property 'func' does not exist on type 'Alias'.
36

47

58
==== tests/cases/conformance/salsa/mod1.js (0 errors) ====
@@ -8,13 +11,21 @@ tests/cases/conformance/salsa/main.js(4,9): error TS2339: Property 'foo' does no
811
}
912
module.exports = Alias;
1013

11-
==== tests/cases/conformance/salsa/main.js (2 errors) ====
14+
==== tests/cases/conformance/salsa/main.js (5 errors) ====
1215
import A from './mod1'
1316
A.prototype.foo = 0
1417
~~~
1518
!!! error TS2339: Property 'foo' does not exist on type 'Alias'.
19+
A.prototype.func = function() { this._func = 0; }
20+
~~~~
21+
!!! error TS2339: Property 'func' does not exist on type 'Alias'.
22+
~~~~~
23+
!!! error TS2339: Property '_func' does not exist on type 'Alias'.
1624
new A().bar
1725
new A().foo
1826
~~~
1927
!!! error TS2339: Property 'foo' does not exist on type 'Alias'.
28+
new A().func()
29+
~~~~
30+
!!! error TS2339: Property 'func' does not exist on type 'Alias'.
2031

tests/baselines/reference/importAliasModuleExports.symbols

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ A.prototype.foo = 0
2020
>A : Symbol(A, Decl(main.js, 0, 6))
2121
>prototype : Symbol(A.prototype)
2222

23+
A.prototype.func = function() { this._func = 0; }
24+
>A.prototype : Symbol(A.prototype)
25+
>A : Symbol(A, Decl(main.js, 0, 6))
26+
>prototype : Symbol(A.prototype)
27+
>this : Symbol(A, Decl(mod1.js, 0, 0))
28+
2329
new A().bar
2430
>new A().bar : Symbol(A.bar, Decl(mod1.js, 0, 13))
2531
>A : Symbol(A, Decl(main.js, 0, 6))
@@ -28,3 +34,6 @@ new A().bar
2834
new A().foo
2935
>A : Symbol(A, Decl(main.js, 0, 6))
3036

37+
new A().func()
38+
>A : Symbol(A, Decl(main.js, 0, 6))
39+

tests/baselines/reference/importAliasModuleExports.types

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ A.prototype.foo = 0
2626
>foo : any
2727
>0 : 0
2828

29+
A.prototype.func = function() { this._func = 0; }
30+
>A.prototype.func = function() { this._func = 0; } : () => void
31+
>A.prototype.func : any
32+
>A.prototype : A
33+
>A : typeof A
34+
>prototype : A
35+
>func : any
36+
>function() { this._func = 0; } : () => void
37+
>this._func = 0 : 0
38+
>this._func : any
39+
>this : A
40+
>_func : any
41+
>0 : 0
42+
2943
new A().bar
3044
>new A().bar : () => number
3145
>new A() : A
@@ -38,3 +52,10 @@ new A().foo
3852
>A : typeof A
3953
>foo : any
4054

55+
new A().func()
56+
>new A().func() : any
57+
>new A().func : any
58+
>new A() : A
59+
>A : typeof A
60+
>func : any
61+

tests/cases/conformance/salsa/importAliasModuleExports.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ module.exports = Alias;
1111
// @filename: main.js
1212
import A from './mod1'
1313
A.prototype.foo = 0
14+
A.prototype.func = function() { this._func = 0; }
1415
new A().bar
1516
new A().foo
17+
new A().func()

0 commit comments

Comments
 (0)