From 4214aed37de464490128294fa425797096a7f644 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 4 Apr 2017 14:50:42 -0700 Subject: [PATCH] Test:static inits can refer to later static methods --- .../scopeCheckStaticInitializer.errors.txt | 30 +++++++++++++++ .../reference/scopeCheckStaticInitializer.js | 37 +++++++++++++++++++ .../compiler/scopeCheckStaticInitializer.ts | 14 +++++++ 3 files changed, 81 insertions(+) create mode 100644 tests/baselines/reference/scopeCheckStaticInitializer.errors.txt create mode 100644 tests/baselines/reference/scopeCheckStaticInitializer.js create mode 100644 tests/cases/compiler/scopeCheckStaticInitializer.ts diff --git a/tests/baselines/reference/scopeCheckStaticInitializer.errors.txt b/tests/baselines/reference/scopeCheckStaticInitializer.errors.txt new file mode 100644 index 00000000000..c023c356a2a --- /dev/null +++ b/tests/baselines/reference/scopeCheckStaticInitializer.errors.txt @@ -0,0 +1,30 @@ +tests/cases/compiler/scopeCheckStaticInitializer.ts(2,38): error TS2448: Block-scoped variable 'data' used before its declaration. +tests/cases/compiler/scopeCheckStaticInitializer.ts(5,23): error TS2449: Class 'After' used before its declaration. +tests/cases/compiler/scopeCheckStaticInitializer.ts(5,29): error TS2448: Block-scoped variable 'data' used before its declaration. +tests/cases/compiler/scopeCheckStaticInitializer.ts(6,23): error TS2449: Class 'After' used before its declaration. + + +==== tests/cases/compiler/scopeCheckStaticInitializer.ts (4 errors) ==== + class X { + static illegalBeforeProperty = X.data; + ~~~~ +!!! error TS2448: Block-scoped variable 'data' used before its declaration. + static okBeforeMethod = X.method; + + static illegal2 = After.data; + ~~~~~ +!!! error TS2449: Class 'After' used before its declaration. + ~~~~ +!!! error TS2448: Block-scoped variable 'data' used before its declaration. + static illegal3 = After.method; + ~~~~~ +!!! error TS2449: Class 'After' used before its declaration. + static data = 13; + static method() { } + } + class After { + static data = 12; + static method() { }; + } + + \ No newline at end of file diff --git a/tests/baselines/reference/scopeCheckStaticInitializer.js b/tests/baselines/reference/scopeCheckStaticInitializer.js new file mode 100644 index 00000000000..59711f07380 --- /dev/null +++ b/tests/baselines/reference/scopeCheckStaticInitializer.js @@ -0,0 +1,37 @@ +//// [scopeCheckStaticInitializer.ts] +class X { + static illegalBeforeProperty = X.data; + static okBeforeMethod = X.method; + + static illegal2 = After.data; + static illegal3 = After.method; + static data = 13; + static method() { } +} +class After { + static data = 12; + static method() { }; +} + + + +//// [scopeCheckStaticInitializer.js] +var X = (function () { + function X() { + } + X.method = function () { }; + return X; +}()); +X.illegalBeforeProperty = X.data; +X.okBeforeMethod = X.method; +X.illegal2 = After.data; +X.illegal3 = After.method; +X.data = 13; +var After = (function () { + function After() { + } + After.method = function () { }; + ; + return After; +}()); +After.data = 12; diff --git a/tests/cases/compiler/scopeCheckStaticInitializer.ts b/tests/cases/compiler/scopeCheckStaticInitializer.ts new file mode 100644 index 00000000000..a5c7b6ccd62 --- /dev/null +++ b/tests/cases/compiler/scopeCheckStaticInitializer.ts @@ -0,0 +1,14 @@ +class X { + static illegalBeforeProperty = X.data; + static okBeforeMethod = X.method; + + static illegal2 = After.data; + static illegal3 = After.method; + static data = 13; + static method() { } +} +class After { + static data = 12; + static method() { }; +} +