r217235 - clang-format: [JS] Fix indentation in dict literals.

Daniel Jasper djasper at google.com
Fri Sep 5 01:29:32 PDT 2014


Author: djasper
Date: Fri Sep  5 03:29:31 2014
New Revision: 217235

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

Before:
  return {
    'finish':
        //
        a
        };

After:
  return {
    'finish':
        //
        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=217235&r1=217234&r2=217235&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Sep  5 03:29:31 2014
@@ -1110,12 +1110,16 @@ private:
   /// and other tokens that we treat like binary operators.
   int getCurrentPrecedence() {
     if (Current) {
+      const FormatToken *NextNonComment = Current->getNextNonComment();
       if (Current->Type == TT_ConditionalExpr)
         return prec::Conditional;
+      else if (NextNonComment && NextNonComment->is(tok::colon) &&
+               NextNonComment->Type == TT_DictLiteral)
+        return prec::Comma;
       else if (Current->is(tok::semi) || Current->Type == TT_InlineASMColon ||
                Current->Type == TT_SelectorName ||
-               (Current->is(tok::comment) && Current->getNextNonComment() &&
-                Current->getNextNonComment()->Type == TT_SelectorName))
+               (Current->is(tok::comment) && NextNonComment &&
+                NextNonComment->Type == TT_SelectorName))
         return 0;
       else if (Current->Type == TT_RangeBasedForLoopColon)
         return prec::Comma;

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=217235&r1=217234&r2=217235&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Fri Sep  5 03:29:31 2014
@@ -123,6 +123,11 @@ TEST_F(FormatTestJS, ContainerLiterals)
                "  // comment for tasks\n"
                "  tasks: false\n"
                "};");
+  verifyFormat("return {\n"
+               "  'finish':\n"
+               "      //\n"
+               "      a\n"
+               "};");
 }
 
 TEST_F(FormatTestJS, SpacesInContainerLiterals) {





More information about the cfe-commits mailing list