]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] JavaScript does not have the */&/&& madness.
authorDaniel Jasper <djasper@google.com>
Fri, 5 Sep 2014 08:53:45 +0000 (08:53 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 5 Sep 2014 08:53:45 +0000 (08:53 +0000)
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).

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

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

index 13613287789ca2a425db4b40e6e52c987688583a..4f3ec0b1996238a35c041f1f4e4895f5350971e9 100644 (file)
@@ -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;
index a4bd84a3242a65f9c46abf810d374eae098a9d07..bd931aaf0a3cb45bc13859a2a0744852b518fe4c 100644 (file)
@@ -83,6 +83,10 @@ TEST_F(FormatTestJS, UnderstandsJavaScriptOperators) {
   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;");
 }