Skip to content

Fix crash in expando assignment to alias #34566

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 2 commits into from
Oct 18, 2019
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 @@ -2870,7 +2870,7 @@ namespace ts {
}
});
}
if (containerIsClass && namespaceSymbol) {
if (containerIsClass && namespaceSymbol && namespaceSymbol.valueDeclaration) {
addDeclarationToSymbol(namespaceSymbol, namespaceSymbol.valueDeclaration, SymbolFlags.Class);
}
return namespaceSymbol;
Expand Down
20 changes: 20 additions & 0 deletions tests/baselines/reference/importAliasModuleExports.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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/mod1.js (0 errors) ====
class Alias {
bar() { return 1 }
}
module.exports = Alias;

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

30 changes: 30 additions & 0 deletions tests/baselines/reference/importAliasModuleExports.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
=== tests/cases/conformance/salsa/mod1.js ===
class Alias {
>Alias : Symbol(Alias, Decl(mod1.js, 0, 0))

bar() { return 1 }
>bar : Symbol(Alias.bar, Decl(mod1.js, 0, 13))
}
module.exports = Alias;
>module.exports : Symbol("tests/cases/conformance/salsa/mod1", Decl(mod1.js, 0, 0))
>module : Symbol(export=, Decl(mod1.js, 2, 1))
>exports : Symbol(export=, Decl(mod1.js, 2, 1))
>Alias : Symbol(Alias, Decl(mod1.js, 0, 0))

=== tests/cases/conformance/salsa/main.js ===
import A from './mod1'
>A : Symbol(A, Decl(main.js, 0, 6))

A.prototype.foo = 0
>A.prototype : Symbol(A.prototype)
>A : Symbol(A, Decl(main.js, 0, 6))
>prototype : Symbol(A.prototype)

new A().bar
>new A().bar : Symbol(A.bar, Decl(mod1.js, 0, 13))
>A : Symbol(A, Decl(main.js, 0, 6))
>bar : Symbol(A.bar, Decl(mod1.js, 0, 13))

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

40 changes: 40 additions & 0 deletions tests/baselines/reference/importAliasModuleExports.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
=== tests/cases/conformance/salsa/mod1.js ===
class Alias {
>Alias : Alias

bar() { return 1 }
>bar : () => number
>1 : 1
}
module.exports = Alias;
>module.exports = Alias : typeof Alias
>module.exports : typeof Alias
>module : { "tests/cases/conformance/salsa/mod1": typeof Alias; }
>exports : typeof Alias
>Alias : typeof Alias

=== tests/cases/conformance/salsa/main.js ===
import A from './mod1'
>A : typeof A

A.prototype.foo = 0
>A.prototype.foo = 0 : 0
>A.prototype.foo : any
>A.prototype : A
>A : typeof A
>prototype : A
>foo : any
>0 : 0

new A().bar
>new A().bar : () => number
>new A() : A
>A : typeof A
>bar : () => number

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

15 changes: 15 additions & 0 deletions tests/cases/conformance/salsa/importAliasModuleExports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true
// @esModuleInterop: true
// @filename: mod1.js
class Alias {
bar() { return 1 }
}
module.exports = Alias;

// @filename: main.js
import A from './mod1'
A.prototype.foo = 0
new A().bar
new A().foo