Skip to content

Handle toplevel this-assignment without crashing #22913

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
Mar 27, 2018
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
4 changes: 4 additions & 0 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2362,6 +2362,10 @@ namespace ts {
const symbolTable = hasModifier(thisContainer, ModifierFlags.Static) ? containingClass.symbol.exports : containingClass.symbol.members;
declareSymbol(symbolTable, containingClass.symbol, node, SymbolFlags.Property, SymbolFlags.None, /*isReplaceableByMethod*/ true);
break;
case SyntaxKind.SourceFile:
// this.foo assignment in a source file
// Do not bind. It would be nice to support this someday though.
break;

default:
Debug.fail(Debug.showSyntaxKind(thisContainer));
Expand Down
18 changes: 18 additions & 0 deletions tests/baselines/reference/topLevelThisAssignment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [tests/cases/conformance/salsa/topLevelThisAssignment.ts] ////

//// [a.js]
this.a = 10;
this.a;
a;

//// [b.js]
this.a;
a;


//// [output.js]
this.a = 10;
this.a;
a;
this.a;
a;
10 changes: 10 additions & 0 deletions tests/baselines/reference/topLevelThisAssignment.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== tests/cases/conformance/salsa/a.js ===
this.a = 10;
No type information for this code.this.a;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should fix this output formatting some day...

No type information for this code.a;
No type information for this code.
No type information for this code.=== tests/cases/conformance/salsa/b.js ===
this.a;
No type information for this code.a;
No type information for this code.
No type information for this code.
25 changes: 25 additions & 0 deletions tests/baselines/reference/topLevelThisAssignment.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
=== tests/cases/conformance/salsa/a.js ===
this.a = 10;
>this.a = 10 : 10
>this.a : any
>this : any
>a : any
>10 : 10

this.a;
>this.a : any
>this : any
>a : any

a;
>a : any

=== tests/cases/conformance/salsa/b.js ===
this.a;
>this.a : any
>this : any
>a : any

a;
>a : any

10 changes: 10 additions & 0 deletions tests/cases/conformance/salsa/topLevelThisAssignment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @out: output.js
// @allowJs: true
// @Filename: a.js
this.a = 10;
this.a;
a;

// @Filename: b.js
this.a;
a;