@@ -112,6 +112,18 @@ public void testCannotConvertYet() {
112
112
"}")*/
113
113
CANNOT_CONVERT_YET ); // uses `this` in static block
114
114
115
+ testError (
116
+ lines (
117
+ "let C = class {" ,
118
+ " static prop = 5;" ,
119
+ "}," ,
120
+ "D = class extends C {" ,
121
+ " static {" ,
122
+ " console.log(this.prop);" ,
123
+ " }" ,
124
+ "}" ),
125
+ CANNOT_CONVERT_YET ); // uses `this` in static block
126
+
115
127
testError (
116
128
lines (
117
129
"var z = 1" , //
@@ -722,7 +734,7 @@ public void testClassStaticBlocksNoFieldAssign() {
722
734
"{" ,
723
735
" let x = 5;" ,
724
736
" class Bar {}" ,
725
- " {let x = 'str';}" ,
737
+ " {let x$jscomp$1 = 'str';}" ,
726
738
"}" ));
727
739
}
728
740
@@ -1531,58 +1543,113 @@ public void testConstuctorAndStaticFieldDontConflict() {
1531
1543
lines (
1532
1544
"let x = 2;" , //
1533
1545
"class C {" ,
1534
- " constructor(x) {}" ,
1546
+ " constructor(x$jscomp$1 ) {}" ,
1535
1547
"}" ,
1536
1548
"C.y = x" ));
1537
1549
}
1538
1550
1539
1551
@ Test
1540
1552
public void testInstanceInitializerShadowsConstructorDeclaration () {
1541
- testError (
1553
+ test (
1542
1554
lines (
1543
1555
"let x = 2;" , //
1544
1556
"class C {" ,
1545
1557
" y = x" ,
1546
1558
" constructor(x) {}" ,
1547
1559
"}" ),
1548
- CANNOT_CONVERT_YET );
1560
+ lines (
1561
+ "let x = 2;" , //
1562
+ "class C {" ,
1563
+ " constructor(x$jscomp$1) {" ,
1564
+ " this.y = x;" ,
1565
+ " }" ,
1566
+ "}" ));
1549
1567
1550
- testError (
1568
+ test (
1551
1569
lines (
1552
1570
"let x = 2;" , //
1553
1571
"class C {" ,
1554
- " y = x" ,
1555
- " constructor() { let x;}" ,
1572
+ " y = x; " ,
1573
+ " constructor() { let x; }" ,
1556
1574
"}" ),
1557
- CANNOT_CONVERT_YET );
1575
+ lines (
1576
+ "let x = 2;" ,
1577
+ "class C {" ,
1578
+ " constructor() {" ,
1579
+ " this.y = x;" ,
1580
+ " let x$jscomp$1;" ,
1581
+ " }" ,
1582
+ "}" ));
1558
1583
1559
- testError (
1584
+ test (
1560
1585
lines (
1561
1586
"let x = 2;" , //
1562
1587
"class C {" ,
1563
1588
" y = x" ,
1564
1589
" constructor() { {var x;} }" ,
1565
1590
"}" ),
1566
- CANNOT_CONVERT_YET );
1591
+ lines (
1592
+ "let x = 2;" ,
1593
+ "class C {" ,
1594
+ " constructor() {" ,
1595
+ " this.y = x;" ,
1596
+ " {" ,
1597
+ " var x$jscomp$1;" ,
1598
+ " }" ,
1599
+ " }" ,
1600
+ "}" ));
1567
1601
1568
- testError (
1602
+ test (
1569
1603
lines (
1570
- "function f() { return 4; }; " , //
1604
+ "function f() { return 4; }" , //
1571
1605
"class C {" ,
1572
1606
" y = f();" ,
1573
1607
" constructor() {function f() { return 'str'; }}" ,
1574
1608
"}" ),
1575
- CANNOT_CONVERT_YET );
1609
+ lines (
1610
+ "function f() {" ,
1611
+ " return 4;" ,
1612
+ "}" ,
1613
+ "class C {" ,
1614
+ " constructor() {" ,
1615
+ " this.y = f();" ,
1616
+ " function f$jscomp$1() {" ,
1617
+ " return 'str';" ,
1618
+ " }" ,
1619
+ " }" ,
1620
+ "}" ));
1576
1621
1577
- // TODO(b/189993301): Technically this has no shadowing, so we could inline without renaming
1578
- testError (
1622
+ test (
1623
+ lines (
1624
+ "class Foo {" , //
1625
+ " constructor(x) {}" ,
1626
+ " y = (x) => x;" ,
1627
+ "}" ),
1628
+ lines (
1629
+ "class Foo {" ,
1630
+ " constructor(x) {" ,
1631
+ " this.y = x$jscomp$1 => {" ,
1632
+ " return x$jscomp$1;" ,
1633
+ " };" ,
1634
+ " }" ,
1635
+ "}" ));
1636
+
1637
+ test (
1579
1638
lines (
1580
1639
"let x = 2;" , //
1581
1640
"class C {" ,
1582
1641
" y = (x) => x;" ,
1583
1642
" constructor(x) {}" ,
1584
1643
"}" ),
1585
- CANNOT_CONVERT_YET );
1644
+ lines (
1645
+ "let x = 2;" ,
1646
+ "class C {" ,
1647
+ " constructor(x$jscomp$2) {" ,
1648
+ " this.y = x$jscomp$1 => {" ,
1649
+ " return x$jscomp$1;" ,
1650
+ " };" ,
1651
+ " }" ,
1652
+ "}" ));
1586
1653
}
1587
1654
1588
1655
@ Test
@@ -1591,15 +1658,15 @@ public void testInstanceInitializerDoesntShadowConstructorDeclaration() {
1591
1658
lines (
1592
1659
"let x = 2;" , //
1593
1660
"class C {" ,
1594
- " y = x" ,
1661
+ " y = x; " ,
1595
1662
" constructor() { {let x;} }" ,
1596
1663
"}" ),
1597
1664
lines (
1598
1665
"let x = 2;" ,
1599
1666
"class C {" ,
1600
1667
" constructor() {" ,
1601
1668
" this.y = x;" ,
1602
- " {let x;}" ,
1669
+ " {let x$jscomp$1 ;}" ,
1603
1670
" }" ,
1604
1671
"}" ));
1605
1672
@@ -1615,7 +1682,7 @@ public void testInstanceInitializerDoesntShadowConstructorDeclaration() {
1615
1682
"class C {" ,
1616
1683
" constructor() {" ,
1617
1684
" this.y = x;" ,
1618
- " () => { let x; };" ,
1685
+ " () => { let x$jscomp$1 ; };" ,
1619
1686
" }" ,
1620
1687
"}" ));
1621
1688
@@ -1631,7 +1698,7 @@ public void testInstanceInitializerDoesntShadowConstructorDeclaration() {
1631
1698
"class C {" ,
1632
1699
" constructor() {" ,
1633
1700
" this.y = x;" ,
1634
- " (x) => { return 3; };" ,
1701
+ " (x$jscomp$1 ) => { return 3; };" ,
1635
1702
" }" ,
1636
1703
"}" ));
1637
1704
}
@@ -1656,16 +1723,28 @@ public void testInstanceFieldInitializersDontBleedOut() {
1656
1723
1657
1724
@ Test
1658
1725
public void testNestedClassesWithShadowingInstanceFields () {
1659
- testError (
1726
+ test (
1660
1727
lines (
1661
- "let x = 2;" , //
1728
+ "let x = 2;" ,
1662
1729
"class C {" ,
1663
1730
" y = () => {" ,
1664
- " class Foo { z = x }; " ,
1731
+ " class Foo { z = x }" ,
1665
1732
" };" ,
1666
1733
" constructor(x) {}" ,
1667
1734
"}" ),
1668
- CANNOT_CONVERT_YET );
1735
+ lines (
1736
+ "let x = 2;" ,
1737
+ "class C {" ,
1738
+ " constructor(x$jscomp$1) {" ,
1739
+ " this.y = () => {" ,
1740
+ " class Foo {" ,
1741
+ " constructor() {" ,
1742
+ " this.z = x;" ,
1743
+ " }" ,
1744
+ " }" ,
1745
+ " };" ,
1746
+ " }" ,
1747
+ "}" ));
1669
1748
}
1670
1749
1671
1750
// Added when fixing transpilation of real-world code that passed a class expression to a
0 commit comments