]> granicus.if.org Git - clang/commitdiff
Revert "clang-format: [JS] don't break comments before any '{'"
authorTim Northover <tnorthover@apple.com>
Fri, 3 Aug 2018 12:19:22 +0000 (12:19 +0000)
committerTim Northover <tnorthover@apple.com>
Fri, 3 Aug 2018 12:19:22 +0000 (12:19 +0000)
This reverts commit r338837, it introduced an infinite loop on all bots.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338879 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/BreakableToken.cpp
unittests/Format/FormatTestJS.cpp

index bd80de171550859156530b2a4814d648206514a1..300e3f802cb4ece688bd3e7179e0ebd622d8e957 100644 (file)
@@ -90,19 +90,19 @@ static BreakableToken::Split getCommentSplit(StringRef Text,
 
   StringRef::size_type SpaceOffset = Text.find_last_of(Blanks, MaxSplitBytes);
 
+  // Do not split before a number followed by a dot: this would be interpreted
+  // as a numbered list, which would prevent re-flowing in subsequent passes.
   static auto *const kNumberedListRegexp = new llvm::Regex("^[1-9][0-9]?\\.");
-  while (SpaceOffset != StringRef::npos) {
-    // Do not split before a number followed by a dot: this would be interpreted
-    // as a numbered list, which would prevent re-flowing in subsequent passes.
-    if (kNumberedListRegexp->match(Text.substr(SpaceOffset).ltrim(Blanks)))
-      SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
-    // In JavaScript, some @tags can be followed by {, and machinery that parses
-    // these comments will fail to understand the comment if followed by a line
-    // break. So avoid ever breaking before a {.
-    else if (Style.Language == FormatStyle::LK_JavaScript &&
-             SpaceOffset + 1 < Text.size() && Text[SpaceOffset + 1] == '{')
-      SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
-  }
+  if (SpaceOffset != StringRef::npos &&
+      kNumberedListRegexp->match(Text.substr(SpaceOffset).ltrim(Blanks)))
+    SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
+  // In JavaScript, some @tags can be followed by {, and machinery that parses
+  // these comments will fail to understand the comment if followed by a line
+  // break. So avoid ever breaking before a {.
+  if (Style.Language == FormatStyle::LK_JavaScript &&
+      SpaceOffset != StringRef::npos && SpaceOffset + 1 < Text.size() &&
+      Text[SpaceOffset + 1] == '{')
+    SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
 
   if (SpaceOffset == StringRef::npos ||
       // Don't break at leading whitespace.
index 58a900352a2470e5172b7714a9fbd00aef62137d..fe148393b985f7609cef7862d37ac7c7e059b4dd 100644 (file)
@@ -2067,14 +2067,6 @@ TEST_F(FormatTestJS, JSDocAnnotations) {
                " * @param {canWrap onSpace}\n"
                " */",
                getGoogleJSStyleWithColumns(20));
-  // make sure clang-format doesn't break before *any* '{'
-  verifyFormat("/**\n"
-               " * @lala {lala {lalala\n"
-               " */\n",
-               "/**\n"
-               " * @lala {lala {lalala\n"
-               " */\n",
-               getGoogleJSStyleWithColumns(20));
   verifyFormat("/**\n"
                " * @see http://very/very/long/url/is/long\n"
                " */",