]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Support for EC6 arrow functions.
authorDaniel Jasper <djasper@google.com>
Mon, 19 May 2014 07:27:02 +0000 (07:27 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 19 May 2014 07:27:02 +0000 (07:27 +0000)
Before:
  var b = a.map((x) = > x + 1);

After:
  var b = a.map((x) => x + 1);

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

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

index dea2386e0ace35b546e5134dd98f2a783f9d863e..ae8c75ff6dc4a592090363ebe02d1568fdbb4aee 100644 (file)
@@ -1244,6 +1244,7 @@ private:
       static tok::TokenKind JSNotIdentity[] = { tok::exclaimequal, tok::equal };
       static tok::TokenKind JSShiftEqual[] = { tok::greater, tok::greater,
                                                tok::greaterequal };
+      static tok::TokenKind JSRightArrow[] = { tok::equal, tok::greater };
       // FIXME: We probably need to change token type to mimic operator with the
       // correct priority.
       if (tryMergeTokens(JSIdentity))
@@ -1252,6 +1253,8 @@ private:
         return;
       if (tryMergeTokens(JSShiftEqual))
         return;
+      if (tryMergeTokens(JSRightArrow))
+        return;
     }
   }
 
index 7a853b037819ab3182347332109abd194cf1e820..c10dc9675f4bb53fa837c81ccd9f9b41bfa93626 100644 (file)
@@ -77,6 +77,8 @@ TEST_F(FormatTestJS, UnderstandsJavaScriptOperators) {
                "            bbbbbb :\n"
                "            ccc;",
                getGoogleJSStyleWithColumns(20));
+
+  verifyFormat("var b = a.map((x) => x + 1);");
 }
 
 TEST_F(FormatTestJS, SpacesInContainerLiterals) {