Skip to content

Commit 61aad4c

Browse files
authored
Handle toplevel this-assignment (#22913)
Do nothing now. Someday we might handle it correctly.
1 parent 2bd66b3 commit 61aad4c

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed

src/compiler/binder.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,6 +2362,10 @@ namespace ts {
23622362
const symbolTable = hasModifier(thisContainer, ModifierFlags.Static) ? containingClass.symbol.exports : containingClass.symbol.members;
23632363
declareSymbol(symbolTable, containingClass.symbol, node, SymbolFlags.Property, SymbolFlags.None, /*isReplaceableByMethod*/ true);
23642364
break;
2365+
case SyntaxKind.SourceFile:
2366+
// this.foo assignment in a source file
2367+
// Do not bind. It would be nice to support this someday though.
2368+
break;
23652369

23662370
default:
23672371
Debug.fail(Debug.showSyntaxKind(thisContainer));
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [tests/cases/conformance/salsa/topLevelThisAssignment.ts] ////
2+
3+
//// [a.js]
4+
this.a = 10;
5+
this.a;
6+
a;
7+
8+
//// [b.js]
9+
this.a;
10+
a;
11+
12+
13+
//// [output.js]
14+
this.a = 10;
15+
this.a;
16+
a;
17+
this.a;
18+
a;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/conformance/salsa/a.js ===
2+
this.a = 10;
3+
No type information for this code.this.a;
4+
No type information for this code.a;
5+
No type information for this code.
6+
No type information for this code.=== tests/cases/conformance/salsa/b.js ===
7+
this.a;
8+
No type information for this code.a;
9+
No type information for this code.
10+
No type information for this code.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== tests/cases/conformance/salsa/a.js ===
2+
this.a = 10;
3+
>this.a = 10 : 10
4+
>this.a : any
5+
>this : any
6+
>a : any
7+
>10 : 10
8+
9+
this.a;
10+
>this.a : any
11+
>this : any
12+
>a : any
13+
14+
a;
15+
>a : any
16+
17+
=== tests/cases/conformance/salsa/b.js ===
18+
this.a;
19+
>this.a : any
20+
>this : any
21+
>a : any
22+
23+
a;
24+
>a : any
25+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @out: output.js
2+
// @allowJs: true
3+
// @Filename: a.js
4+
this.a = 10;
5+
this.a;
6+
a;
7+
8+
// @Filename: b.js
9+
this.a;
10+
a;

0 commit comments

Comments
 (0)