@@ -818,7 +818,8 @@ void UnwrappedLineParser::parseStructuralElement() {
818
818
case tok::kw_enum:
819
819
// parseEnum falls through and does not yet add an unwrapped line as an
820
820
// enum definition can start a structural element.
821
- parseEnum ();
821
+ if (!parseEnum ())
822
+ break ;
822
823
// This only applies for C++.
823
824
if (Style.Language != FormatStyle::LK_Cpp) {
824
825
addUnwrappedLine ();
@@ -1524,11 +1525,17 @@ void UnwrappedLineParser::parseAccessSpecifier() {
1524
1525
addUnwrappedLine ();
1525
1526
}
1526
1527
1527
- void UnwrappedLineParser::parseEnum () {
1528
+ bool UnwrappedLineParser::parseEnum () {
1528
1529
// Won't be 'enum' for NS_ENUMs.
1529
1530
if (FormatTok->Tok .is (tok::kw_enum))
1530
1531
nextToken ();
1531
1532
1533
+ // In TypeScript, "enum" can also be used as property name, e.g. in interface
1534
+ // declarations. An "enum" keyword followed by a colon would be a syntax
1535
+ // error and thus assume it is just an identifier.
1536
+ if (Style.Language == FormatStyle::LK_JavaScript && FormatTok->is (tok::colon))
1537
+ return false ;
1538
+
1532
1539
// Eat up enum class ...
1533
1540
if (FormatTok->Tok .is (tok::kw_class) || FormatTok->Tok .is (tok::kw_struct))
1534
1541
nextToken ();
@@ -1546,22 +1553,23 @@ void UnwrappedLineParser::parseEnum() {
1546
1553
// return type. In Java, this can be "implements", etc.
1547
1554
if (Style.Language == FormatStyle::LK_Cpp &&
1548
1555
FormatTok->is (tok::identifier))
1549
- return ;
1556
+ return false ;
1550
1557
}
1551
1558
}
1552
1559
1553
1560
// Just a declaration or something is wrong.
1554
1561
if (FormatTok->isNot (tok::l_brace))
1555
- return ;
1562
+ return true ;
1556
1563
FormatTok->BlockKind = BK_Block;
1557
1564
1558
1565
if (Style.Language == FormatStyle::LK_Java) {
1559
1566
// Java enums are different.
1560
1567
parseJavaEnumBody ();
1561
- return ;
1562
- } else if (Style.Language == FormatStyle::LK_Proto) {
1568
+ return true ;
1569
+ }
1570
+ if (Style.Language == FormatStyle::LK_Proto) {
1563
1571
parseBlock (/* MustBeDeclaration=*/ true );
1564
- return ;
1572
+ return true ;
1565
1573
}
1566
1574
1567
1575
// Parse enum body.
@@ -1571,6 +1579,7 @@ void UnwrappedLineParser::parseEnum() {
1571
1579
nextToken ();
1572
1580
addUnwrappedLine ();
1573
1581
}
1582
+ return true ;
1574
1583
1575
1584
// There is no addUnwrappedLine() here so that we fall through to parsing a
1576
1585
// structural element afterwards. Thus, in "enum A {} n, m;",
0 commit comments