]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Keep space between 'return' and '['.
authorDaniel Jasper <djasper@google.com>
Tue, 6 May 2014 14:12:21 +0000 (14:12 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 6 May 2014 14:12:21 +0000 (14:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208090 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 98ef453e4cd4a65be822e12370ad5faa8d0a927e..e873e984605fb49ed101e0874fb09d4d8ef4a111 100644 (file)
@@ -1215,7 +1215,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) {
         }
       }
     } else if (Current->SpacesRequiredBefore == 0 &&
-             spaceRequiredBefore(Line, *Current)) {
+               spaceRequiredBefore(Line, *Current)) {
       Current->SpacesRequiredBefore = 1;
     }
 
@@ -1385,6 +1385,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
         (Left.TokenText == "returns" || Left.TokenText == "option"))
       return true;
   }
+  if (Left.is(tok::kw_return) && Right.isNot(tok::semi))
+    return true;
   if (Style.ObjCSpaceAfterProperty && Line.Type == LT_ObjCProperty &&
       Left.Tok.getObjCKeywordID() == tok::objc_property)
     return true;
@@ -1459,8 +1461,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
     if (Left.is(tok::r_paren) && Left.Type == TT_AttributeParen)
       return true;
     return Line.Type == LT_ObjCDecl ||
-           Left.isOneOf(tok::kw_return, tok::kw_new, tok::kw_delete,
-                        tok::semi) ||
+           Left.isOneOf(tok::kw_new, tok::kw_delete, tok::semi) ||
            (Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
             (Left.isOneOf(tok::kw_if, tok::kw_for, tok::kw_while,
                           tok::kw_switch, tok::kw_catch, tok::kw_case) ||
index 4e8908685f01c299fbe497b5fb97c2321e2057e0..153b07535ee99b2a256db455583f4eb3b42a3970 100644 (file)
@@ -98,5 +98,9 @@ TEST_F(FormatTestJS, GoogScopes) {
                "});  // goog.scope");
 }
 
+TEST_F(FormatTestJS, ReturnStatements) {
+  verifyFormat("function() { return [hello, world]; }");
+}
+
 } // end namespace tooling
 } // end namespace clang