r208403 - clang-format: [JS] Fix spacing in dict literals.

Daniel Jasper djasper at google.com
Fri May 9 03:26:08 PDT 2014


Author: djasper
Date: Fri May  9 05:26:08 2014
New Revision: 208403

URL: http://llvm.org/viewvc/llvm-project?rev=208403&view=rev
Log:
clang-format: [JS] Fix spacing in dict literals.

Before:
  someVariable = {'a':[{}]};

After:
  someVariable = {'a': [{}]};

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=208403&r1=208402&r2=208403&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri May  9 05:26:08 2014
@@ -225,8 +225,10 @@ private:
     FormatToken *Parent = Left->getPreviousNonComment();
     bool StartsObjCMethodExpr =
         Contexts.back().CanBeExpression && Left->Type != TT_LambdaLSquare &&
-        (!Parent || Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren,
-                                    tok::kw_return, tok::kw_throw) ||
+        CurrentToken->isNot(tok::l_brace) &&
+        (!Parent ||
+         Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren,
+                         tok::kw_return, tok::kw_throw) ||
          Parent->isUnaryOperator() || Parent->Type == TT_ObjCForIn ||
          Parent->Type == TT_CastRParen ||
          getBinOpPrecedence(Parent->Tok.getKind(), true, true) > prec::Unknown);
@@ -1452,7 +1454,8 @@ bool TokenAnnotator::spaceRequiredBetwee
     return Right.MatchingParen && Style.SpacesInContainerLiterals &&
            Right.MatchingParen->Type == TT_ArrayInitializerLSquare;
   if (Right.is(tok::l_square) && Right.Type != TT_ObjCMethodExpr &&
-      Right.Type != TT_LambdaLSquare && Left.isNot(tok::numeric_constant))
+      Right.Type != TT_LambdaLSquare && Left.isNot(tok::numeric_constant) &&
+      Left.Type != TT_DictLiteral)
     return false;
   if (Left.is(tok::colon))
     return Left.Type != TT_ObjCMethodExpr;

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=208403&r1=208402&r2=208403&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Fri May  9 05:26:08 2014
@@ -85,6 +85,7 @@ TEST_F(FormatTestJS, SpacesInContainerLi
 
   verifyFormat("var obj = {a: 1, b: 2, c: 3};",
                getChromiumStyle(FormatStyle::LK_JavaScript));
+  verifyFormat("someVariable = {'a': [{}]};");
 }
 
 TEST_F(FormatTestJS, SingleQuoteStrings) {





More information about the cfe-commits mailing list