From c5a301065ff51c248508a41f558d38b9f03329cd Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 27 Mar 2018 11:07:28 -0700 Subject: [PATCH] Handle toplevel this-assignment Do nothing now. Someday we might handle it correctly. --- src/compiler/binder.ts | 4 +++ .../reference/topLevelThisAssignment.js | 18 +++++++++++++ .../reference/topLevelThisAssignment.symbols | 10 ++++++++ .../reference/topLevelThisAssignment.types | 25 +++++++++++++++++++ .../salsa/topLevelThisAssignment.ts | 10 ++++++++ 5 files changed, 67 insertions(+) create mode 100644 tests/baselines/reference/topLevelThisAssignment.js create mode 100644 tests/baselines/reference/topLevelThisAssignment.symbols create mode 100644 tests/baselines/reference/topLevelThisAssignment.types create mode 100644 tests/cases/conformance/salsa/topLevelThisAssignment.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 2b66e92cdc357..c7d258bb1d919 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -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)); diff --git a/tests/baselines/reference/topLevelThisAssignment.js b/tests/baselines/reference/topLevelThisAssignment.js new file mode 100644 index 0000000000000..c87fad289f709 --- /dev/null +++ b/tests/baselines/reference/topLevelThisAssignment.js @@ -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; diff --git a/tests/baselines/reference/topLevelThisAssignment.symbols b/tests/baselines/reference/topLevelThisAssignment.symbols new file mode 100644 index 0000000000000..e9b94983bf287 --- /dev/null +++ b/tests/baselines/reference/topLevelThisAssignment.symbols @@ -0,0 +1,10 @@ +=== tests/cases/conformance/salsa/a.js === +this.a = 10; +No type information for this code.this.a; +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. \ No newline at end of file diff --git a/tests/baselines/reference/topLevelThisAssignment.types b/tests/baselines/reference/topLevelThisAssignment.types new file mode 100644 index 0000000000000..024c360f8ccd6 --- /dev/null +++ b/tests/baselines/reference/topLevelThisAssignment.types @@ -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 + diff --git a/tests/cases/conformance/salsa/topLevelThisAssignment.ts b/tests/cases/conformance/salsa/topLevelThisAssignment.ts new file mode 100644 index 0000000000000..162bed0c30fc7 --- /dev/null +++ b/tests/cases/conformance/salsa/topLevelThisAssignment.ts @@ -0,0 +1,10 @@ +// @out: output.js +// @allowJs: true +// @Filename: a.js +this.a = 10; +this.a; +a; + +// @Filename: b.js +this.a; +a;