]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Properly add a space after "in" in for loops.
authorDaniel Jasper <djasper@google.com>
Fri, 20 Nov 2015 16:18:42 +0000 (16:18 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 20 Nov 2015 16:18:42 +0000 (16:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253672 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 751b070cdf92124ab2fd0ad24da57ba8475e2245..171ecc41d7844ceedc5af84338e81c2e2dae14dc 100644 (file)
@@ -1955,7 +1955,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
         Left.isOneOf(Keywords.kw_returns, Keywords.kw_option))
       return true;
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
-    if (Left.isOneOf(Keywords.kw_let, Keywords.kw_var, TT_JsFatArrow))
+    if (Left.isOneOf(Keywords.kw_let, Keywords.kw_var, TT_JsFatArrow,
+                     Keywords.kw_in))
       return true;
     if (Right.isOneOf(TT_JsTypeColon, TT_JsTypeOptionalQuestion))
       return false;
index 9be375243c810f73c7ea734c97852ddef9a03bb6..56a91442f9a352bcc16df20e79d01dcaddaa944b 100644 (file)
@@ -545,6 +545,11 @@ TEST_F(FormatTestJS, ReturnStatements) {
                "}");
 }
 
+TEST_F(FormatTestJS, ForLoops) {
+  verifyFormat("for (var i in [2, 3]) {\n"
+               "}");
+}
+
 TEST_F(FormatTestJS, AutomaticSemicolonInsertion) {
   // The following statements must not wrap, as otherwise the program meaning
   // would change due to automatic semicolon insertion.