]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Fix incorrect line break leading to semicolon insertion.
authorDaniel Jasper <djasper@google.com>
Thu, 14 Jan 2016 05:37:52 +0000 (05:37 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 14 Jan 2016 05:37:52 +0000 (05:37 +0000)
clang-format only works for JavaScript code, if all the semicolons are
present anyway, so this linebreak can never be desired.

Before (with appropriate statement lengths or column limit):
  return
      [ aaa ];

After:
  return [
    aaaa
  ];

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

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJS.cpp

index 8fbb43b7996db7ec27b5b9393e936adcdc08b8ee..6d6df0cf4012c2ad70c3c832d6de0096ddd76788 100644 (file)
@@ -2268,6 +2268,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
                       Keywords.kw_implements))
       return true;
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
+    if (Left.is(tok::kw_return))
+      return false; // Otherwise a semicolon is inserted.
     if (Left.is(TT_JsFatArrow) && Right.is(tok::l_brace))
       return false;
     if (Left.is(TT_JsTypeColon))
index 0e0f64a31ac6d7b2be03d9f60efe3fe6769e2ca7..38fa5cd2b5b6fbf80ee68800e83b1500687359cc 100644 (file)
@@ -591,6 +591,10 @@ TEST_F(FormatTestJS, AutomaticSemicolonInsertion) {
   verifyFormat("throw aaaaa;", getGoogleJSStyleWithColumns(10));
   verifyFormat("aaaaaaaaa++;", getGoogleJSStyleWithColumns(10));
   verifyFormat("aaaaaaaaa--;", getGoogleJSStyleWithColumns(10));
+  verifyFormat("return [\n"
+               "  aaa\n"
+               "];",
+               getGoogleJSStyleWithColumns(12));
 }
 
 TEST_F(FormatTestJS, ClosureStyleCasts) {