Skip to content

🤖 Cherry-pick PR #34650 into release-3.7 #34658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2709,7 +2709,7 @@ namespace ts {
}
}

if (constructorSymbol) {
if (constructorSymbol && constructorSymbol.valueDeclaration) {
// Declare a 'member' if the container is an ES5 class or ES6 constructor
constructorSymbol.members = constructorSymbol.members || createSymbolTable();
// It's acceptable for multiple 'this' assignments of the same identifier to occur
Expand Down
15 changes: 13 additions & 2 deletions tests/baselines/reference/importAliasModuleExports.errors.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
tests/cases/conformance/salsa/main.js(2,13): error TS2339: Property 'foo' does not exist on type 'Alias'.
tests/cases/conformance/salsa/main.js(4,9): error TS2339: Property 'foo' does not exist on type 'Alias'.
tests/cases/conformance/salsa/main.js(3,13): error TS2339: Property 'func' does not exist on type 'Alias'.
tests/cases/conformance/salsa/main.js(3,38): error TS2339: Property '_func' does not exist on type 'Alias'.
tests/cases/conformance/salsa/main.js(5,9): error TS2339: Property 'foo' does not exist on type 'Alias'.
tests/cases/conformance/salsa/main.js(6,9): error TS2339: Property 'func' does not exist on type 'Alias'.


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

==== tests/cases/conformance/salsa/main.js (2 errors) ====
==== tests/cases/conformance/salsa/main.js (5 errors) ====
import A from './mod1'
A.prototype.foo = 0
~~~
!!! error TS2339: Property 'foo' does not exist on type 'Alias'.
A.prototype.func = function() { this._func = 0; }
~~~~
!!! error TS2339: Property 'func' does not exist on type 'Alias'.
~~~~~
!!! error TS2339: Property '_func' does not exist on type 'Alias'.
new A().bar
new A().foo
~~~
!!! error TS2339: Property 'foo' does not exist on type 'Alias'.
new A().func()
~~~~
!!! error TS2339: Property 'func' does not exist on type 'Alias'.

9 changes: 9 additions & 0 deletions tests/baselines/reference/importAliasModuleExports.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ A.prototype.foo = 0
>A : Symbol(A, Decl(main.js, 0, 6))
>prototype : Symbol(A.prototype)

A.prototype.func = function() { this._func = 0; }
>A.prototype : Symbol(A.prototype)
>A : Symbol(A, Decl(main.js, 0, 6))
>prototype : Symbol(A.prototype)
>this : Symbol(A, Decl(mod1.js, 0, 0))

new A().bar
>new A().bar : Symbol(A.bar, Decl(mod1.js, 0, 13))
>A : Symbol(A, Decl(main.js, 0, 6))
Expand All @@ -28,3 +34,6 @@ new A().bar
new A().foo
>A : Symbol(A, Decl(main.js, 0, 6))

new A().func()
>A : Symbol(A, Decl(main.js, 0, 6))

21 changes: 21 additions & 0 deletions tests/baselines/reference/importAliasModuleExports.types
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ A.prototype.foo = 0
>foo : any
>0 : 0

A.prototype.func = function() { this._func = 0; }
>A.prototype.func = function() { this._func = 0; } : () => void
>A.prototype.func : any
>A.prototype : A
>A : typeof A
>prototype : A
>func : any
>function() { this._func = 0; } : () => void
>this._func = 0 : 0
>this._func : any
>this : A
>_func : any
>0 : 0

new A().bar
>new A().bar : () => number
>new A() : A
Expand All @@ -38,3 +52,10 @@ new A().foo
>A : typeof A
>foo : any

new A().func()
>new A().func() : any
>new A().func : any
>new A() : A
>A : typeof A
>func : any

2 changes: 2 additions & 0 deletions tests/cases/conformance/salsa/importAliasModuleExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ module.exports = Alias;
// @filename: main.js
import A from './mod1'
A.prototype.foo = 0
A.prototype.func = function() { this._func = 0; }
new A().bar
new A().foo
new A().func()