@@ -91,7 +91,7 @@ public void testCannotConvertYet() {
91
91
92
92
testError (
93
93
lines (
94
- "class C extends B{" , //
94
+ "class C extends B {" , //
95
95
" static {" ,
96
96
" let x = super.y" ,
97
97
" }" ,
@@ -165,14 +165,6 @@ public void testCannotConvertYet() {
165
165
"}" ),
166
166
TranspilationUtil .CANNOT_CONVERT_YET ); // `var` in static block
167
167
168
- testError (
169
- lines (
170
- "class C {" , //
171
- " static x = 1;" ,
172
- " static y = this.x;" ,
173
- "}" ),
174
- TranspilationUtil .CANNOT_CONVERT_YET ); // `this` in static field
175
-
176
168
testError (
177
169
lines (
178
170
"let c = class C {" , //
@@ -196,14 +188,6 @@ public void testCannotConvertYet() {
196
188
"})" ),
197
189
TranspilationUtil .CANNOT_CONVERT_YET ); // not class decl
198
190
199
- testError (
200
- lines (
201
- "class C {" , //
202
- " x = 1;" ,
203
- " y = this.x;" ,
204
- "}" ),
205
- TranspilationUtil .CANNOT_CONVERT_YET ); // `this` in public field
206
-
207
191
testError (
208
192
lines (
209
193
"foo(class C {" , //
@@ -288,10 +272,169 @@ public void testCannotConvertYet() {
288
272
"}" // testing that the correct number of diagnostics are thrown
289
273
)),
290
274
error (TranspilationUtil .CANNOT_CONVERT_YET ),
291
- error (TranspilationUtil .CANNOT_CONVERT_YET ),
292
275
error (TranspilationUtil .CANNOT_CONVERT_YET ));
293
276
}
294
277
278
+ @ Test
279
+ public void testThisInNonStaticPublicField () {
280
+ test (
281
+ lines (
282
+ "class A {" , //
283
+ " b = 'word';" ,
284
+ " c = this.b;" ,
285
+ "}" ),
286
+ lines (
287
+ "class A {" ,
288
+ " constructor() {" ,
289
+ " this.b = 'word';" ,
290
+ " this.c = this.b;" ,
291
+ " }" ,
292
+ "}" ));
293
+
294
+ test (
295
+ lines (
296
+ "let obj = { bar() { return 9; } };" , //
297
+ "class D {" ,
298
+ " e = obj;" ,
299
+ " f = this.e.bar() * 4;" ,
300
+ "}" ),
301
+ lines (
302
+ "let obj = { bar() { return 9; } };" ,
303
+ "class D {" ,
304
+ " constructor() {" ,
305
+ " this.e = obj;" ,
306
+ " this.f = this.e.bar() * 4;" ,
307
+ " }" ,
308
+ "}" ));
309
+
310
+ test (
311
+ lines (
312
+ "class Foo {" , //
313
+ " y = 'apple';" ,
314
+ " x = () => { return this.y + ' and banana'; };" ,
315
+ "}" ),
316
+ lines (
317
+ "class Foo {" ,
318
+ " constructor() {" ,
319
+ " this.y = 'apple';" ,
320
+ " this.x = () => { return this.y + ' and banana'; };" ,
321
+ " }" ,
322
+ "}" ));
323
+
324
+ test (
325
+ lines (
326
+ "class Bar {" , //
327
+ " x = () => { this.method(); };" ,
328
+ " method() {}" ,
329
+ "}" ),
330
+ lines (
331
+ "class Bar {" ,
332
+ " constructor() {" ,
333
+ " this.x = () => { this.method(); };" ,
334
+ " }" ,
335
+ " method() {}" ,
336
+ "}" ));
337
+ }
338
+
339
+ @ Test
340
+ public void testSuperInNonStaticPublicField () {
341
+ test (
342
+ lines (
343
+ "class Foo {" ,
344
+ " x() {" ,
345
+ " return 3;" ,
346
+ " }" ,
347
+ "}" ,
348
+ "class Bar extends Foo {" ,
349
+ " y = 1 + super.x();" ,
350
+ "}" ),
351
+ lines (
352
+ "class Foo {" ,
353
+ " x() {" ,
354
+ " return 3;" ,
355
+ " }" ,
356
+ "}" ,
357
+ "class Bar extends Foo {" ,
358
+ " constructor() {" ,
359
+ " super(...arguments);" ,
360
+ " this.y = 1 + super.x();" ,
361
+ " }" ,
362
+ "}" ));
363
+ }
364
+
365
+ @ Test
366
+ public void testThisInStaticField () {
367
+ test (
368
+ lines (
369
+ "class C {" , //
370
+ " static x = 2;" ,
371
+ " static y = () => this.x;" ,
372
+ "}" ),
373
+ lines (
374
+ "class C {}" , //
375
+ "C.x = 2;" ,
376
+ "C.y = () => C.x;" ));
377
+
378
+ test (
379
+ lines (
380
+ "class F {" , //
381
+ " static a = 'there';" ,
382
+ " static b = this.c() + this.a;" ,
383
+ " static c() { return 'hi'; }" ,
384
+ "}" ),
385
+ lines (
386
+ "class F {" , //
387
+ " static c() { return 'hi'; }" ,
388
+ "}" ,
389
+ "F.a = 'there';" ,
390
+ "F.b = F.c() + F.a;" ));
391
+ }
392
+
393
+ @ Test
394
+ public void testSuperInStaticField () {
395
+ test (
396
+ lines (
397
+ "class Foo {" ,
398
+ " static x() {" ,
399
+ " return 5;" ,
400
+ " }" ,
401
+ " static y() {" ,
402
+ " return 20;" ,
403
+ " }" ,
404
+ "}" ,
405
+ "class Bar extends Foo {" ,
406
+ " static z = () => super.x() + 12 + super.y();" ,
407
+ "}" ),
408
+ lines (
409
+ "class Foo {" ,
410
+ " static x() {" ,
411
+ " return 5;" ,
412
+ " }" ,
413
+ " static y() {" ,
414
+ " return 20;" ,
415
+ " }" ,
416
+ "}" ,
417
+ "class Bar extends Foo {}" ,
418
+ "Bar.z = () => Foo.x() + 12 + Foo.y();" ));
419
+
420
+ test (
421
+ lines (
422
+ "class Bar {" ,
423
+ " static a = { method1() {} };" ,
424
+ " static b = { method2() { super.method1(); } };" ,
425
+ "}" ,
426
+ "Object.setPrototypeOf = function(c, d) {}" ,
427
+ "Object.setPrototypeOf(Foo.b, Foo.a);" ,
428
+ "Foo.b.method2();" ),
429
+ lines (
430
+ "class Bar {}" ,
431
+ "Bar.a = { method1() {} };" ,
432
+ "Bar.b = { method2() { super.method1(); } };" ,
433
+ "Object.setPrototypeOf = function(c, d) {}" ,
434
+ "Object.setPrototypeOf(Foo.b, Foo.a);" ,
435
+ "Foo.b.method2();" ));
436
+ }
437
+
295
438
@ Test
296
439
public void testClassStaticBlocksNoFieldAssign () {
297
440
test (
@@ -1243,9 +1386,19 @@ public void testInstanceInitializerDoesntShadowConstructorDeclaration() {
1243
1386
@ Test
1244
1387
public void testInstanceFieldInitializersDontBleedOut () {
1245
1388
test (
1246
- lines ("class C {" , " y = z" , " method() { x; }" , " constructor(x) {}" , "}" ),
1247
1389
lines (
1248
- "class C {" , " method() { x; }" , " constructor(x) {" , " this.y = z;" , " }" , "}" ));
1390
+ "class C {" , //
1391
+ " y = z" ,
1392
+ " method() { x; }" ,
1393
+ " constructor(x) {}" ,
1394
+ "}" ),
1395
+ lines (
1396
+ "class C {" , //
1397
+ " method() { x; }" ,
1398
+ " constructor(x) {" ,
1399
+ " this.y = z;" ,
1400
+ " }" ,
1401
+ "}" ));
1249
1402
}
1250
1403
1251
1404
@ Test
0 commit comments