r217237 - clang-format: [JS] JavaScript does not have the */&/&& madness.

Daniel Jasper djasper at google.com
Fri Sep 5 01:53:45 PDT 2014


Author: djasper
Date: Fri Sep  5 03:53:45 2014
New Revision: 217237

URL: http://llvm.org/viewvc/llvm-project?rev=217237&view=rev
Log:
clang-format: [JS] JavaScript does not have the */&/&& madness.

Before:
  e&& e.SomeFunction();

After:
  e && e.SomeFunction();

Yeah, this might be useful for C++, too, but it is not such a frequent
pattern there (plus the fix is much harder).

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=217237&r1=217236&r2=217237&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Sep  5 03:53:45 2014
@@ -917,6 +917,9 @@ private:
   /// \brief Return the type of the given token assuming it is * or &.
   TokenType determineStarAmpUsage(const FormatToken &Tok, bool IsExpression,
                                   bool InTemplateArgument) {
+    if (Style.Language == FormatStyle::LK_JavaScript)
+      return TT_BinaryOperator;
+
     const FormatToken *PrevToken = Tok.getPreviousNonComment();
     if (!PrevToken)
       return TT_UnaryOperator;

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=217237&r1=217236&r2=217237&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Fri Sep  5 03:53:45 2014
@@ -83,6 +83,10 @@ TEST_F(FormatTestJS, UnderstandsJavaScri
   verifyFormat("var b = a.map((x) => x + 1);");
 }
 
+TEST_F(FormatTestJS, UnderstandsAmpAmp) {
+  verifyFormat("e && e.SomeFunction();");
+}
+
 TEST_F(FormatTestJS, LiteralOperatorsCanBeKeywords) {
   verifyFormat("not.and.or.not_eq = 1;");
 }





More information about the cfe-commits mailing list