Skip to content

Fix binding of this-assignments w/computed properties #35639

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 1 commit into from
Dec 11, 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
5 changes: 4 additions & 1 deletion src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2694,7 +2694,10 @@ namespace ts {
break;
case SyntaxKind.SourceFile:
// this.property = assignment in a source file -- declare symbol in exports for a module, in locals for a script
if ((thisContainer as SourceFile).commonJsModuleIndicator) {
if (hasDynamicName(node)) {
break;
}
else if ((thisContainer as SourceFile).commonJsModuleIndicator) {
declareSymbol(thisContainer.symbol.exports!, thisContainer.symbol, node, SymbolFlags.Property | SymbolFlags.ExportValue, SymbolFlags.None);
}
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tests/cases/conformance/salsa/thisPropertyAssignmentComputed.js(1,1): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof globalThis'.
No index signature with a parameter of type 'string' was found on type 'typeof globalThis'.


==== tests/cases/conformance/salsa/thisPropertyAssignmentComputed.js (1 errors) ====
this["a" + "b"] = 0
~~~~~~~~~~~~~~~
!!! error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof globalThis'.
!!! error TS7053: No index signature with a parameter of type 'string' was found on type 'typeof globalThis'.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== tests/cases/conformance/salsa/thisPropertyAssignmentComputed.js ===
this["a" + "b"] = 0
>this : Symbol(globalThis)

10 changes: 10 additions & 0 deletions tests/baselines/reference/thisPropertyAssignmentComputed.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== tests/cases/conformance/salsa/thisPropertyAssignmentComputed.js ===
this["a" + "b"] = 0
>this["a" + "b"] = 0 : 0
>this["a" + "b"] : any
>this : typeof globalThis
>"a" + "b" : string
>"a" : "a"
>"b" : "b"
>0 : 0

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @allowjs: true
// @checkjs: true
// @noemit: true
// @strict: true
// @filename: thisPropertyAssignmentComputed.js
this["a" + "b"] = 0