1describe("unittests:: evaluation:: superInStaticInitializer", () => { 2 it("super-property-get in es2015", () => { 3 const result = evaluator.evaluateTypeScript(` 4 export function main() { 5 class Base { 6 static x = 1; 7 } 8 class Derived extends Base { 9 static y = super.x; 10 } 11 return [ 12 Base, 13 Derived 14 ]; 15 } 16 `, { target: ts.ScriptTarget.ES2015 }); 17 const [Base, Derived] = result.main(); 18 assert.strictEqual(Base.x, 1); 19 assert.strictEqual(Derived.y, 1); 20 }); 21 it("super-property-set in es2015", () => { 22 const result = evaluator.evaluateTypeScript(` 23 export function main() { 24 class Base { 25 static x = 1; 26 } 27 class Derived extends Base { 28 static y = super.x++; 29 } 30 return [ 31 Base, 32 Derived 33 ]; 34 } 35 `, { target: ts.ScriptTarget.ES2015 }); 36 const [Base, Derived] = result.main(); 37 assert.strictEqual(Base.x, 1); 38 assert.strictEqual(Derived.x, 2); 39 assert.strictEqual(Derived.y, 1); 40 }); 41 it("super-accessor-get in es2015", () => { 42 const result = evaluator.evaluateTypeScript(` 43 export function main() { 44 let thisInBase; 45 class Base { 46 static _x = 1; 47 static get x() { 48 thisInBase = this; 49 return this._x; 50 } 51 } 52 class Derived extends Base { 53 static y = super.x; 54 } 55 return [ 56 Base, 57 Derived, 58 thisInBase 59 ]; 60 } 61 `, { target: ts.ScriptTarget.ES2015 }); 62 const [Base, Derived, thisInBase] = result.main(); 63 assert.strictEqual(Base._x, 1); 64 assert.strictEqual(Derived.y, 1); 65 assert.strictEqual(thisInBase, Derived); 66 }); 67 it("super-accessor-set in es2015", () => { 68 const result = evaluator.evaluateTypeScript(` 69 export function main() { 70 let thisInBaseGet; 71 let thisInBaseSet; 72 class Base { 73 static _x = 1; 74 static get x() { 75 thisInBaseGet = this; 76 return this._x; 77 } 78 static set x(value) { 79 thisInBaseSet = this; 80 this._x = value; 81 } 82 } 83 class Derived extends Base { 84 static y = super.x++; 85 } 86 return [ 87 Base, 88 Derived, 89 thisInBaseGet, 90 thisInBaseSet 91 ]; 92 } 93 `, { target: ts.ScriptTarget.ES2015 }); 94 const [Base, Derived, thisInBaseGet, thisInBaseSet] = result.main(); 95 assert.strictEqual(Base._x, 1); 96 assert.strictEqual(Derived._x, 2); 97 assert.strictEqual(Derived.y, 1); 98 assert.strictEqual(thisInBaseGet, Derived); 99 assert.strictEqual(thisInBaseSet, Derived); 100 }); 101 it("super-call in es2015", () => { 102 const result = evaluator.evaluateTypeScript(` 103 export function main() { 104 let thisInBase; 105 class Base { 106 static x() { 107 thisInBase = this; 108 return 1; 109 } 110 } 111 class Derived extends Base { 112 static y = super.x(); 113 } 114 return [ 115 Derived, 116 thisInBase, 117 ]; 118 } 119 `, { target: ts.ScriptTarget.ES2015 }); 120 const [Derived, thisInBase] = result.main(); 121 assert.strictEqual(Derived.y, 1); 122 assert.strictEqual(thisInBase, Derived); 123 }); 124 it("super-call in es5", () => { 125 const result = evaluator.evaluateTypeScript(` 126 export function main() { 127 let thisInBase; 128 class Base { 129 static x() { 130 thisInBase = this; 131 return 1; 132 } 133 } 134 class Derived extends Base { 135 static y = super.x(); 136 } 137 return [ 138 Derived, 139 thisInBase, 140 ]; 141 } 142 `, { target: ts.ScriptTarget.ES5 }); 143 const [Derived, thisInBase] = result.main(); 144 assert.strictEqual(Derived.y, 1); 145 assert.strictEqual(thisInBase, Derived); 146 }); 147 it("super- and this-call in es2015", () => { 148 const result = evaluator.evaluateTypeScript(` 149 export function main() { 150 class Base { 151 static x() { 152 return 1; 153 } 154 } 155 class Derived extends Base { 156 static x() { 157 return super.x() + 1; 158 } 159 static y = this.x(); 160 } 161 return [ 162 Derived, 163 ]; 164 } 165 `, { target: ts.ScriptTarget.ES2015 }); 166 const [Derived] = result.main(); 167 assert.strictEqual(Derived.y, 2); 168 }); 169 it("super- and this-call in es5", () => { 170 const result = evaluator.evaluateTypeScript(` 171 export function main() { 172 class Base { 173 static x() { 174 return 1; 175 } 176 } 177 class Derived extends Base { 178 static x() { 179 return super.x() + 1; 180 } 181 static y = this.x(); 182 } 183 return [ 184 Derived, 185 ]; 186 } 187 `, { target: ts.ScriptTarget.ES2015 }); 188 const [Derived] = result.main(); 189 assert.strictEqual(Derived.y, 2); 190 }); 191});