]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Supprot "catch" as function name.
authorDaniel Jasper <djasper@google.com>
Thu, 4 Sep 2014 15:03:34 +0000 (15:03 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 4 Sep 2014 15:03:34 +0000 (15:03 +0000)
Before:
  someObject.catch ();

After:
  someObject.catch();

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

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

index 6142e7dc56ba677b3e0aeaeda54dbc04d170adae..00c486a3add7671a9d0be5479589f06fa51774f0 100644 (file)
@@ -1586,7 +1586,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
            Left.isOneOf(tok::kw_new, tok::kw_delete, tok::semi) ||
            (Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
             (Left.isOneOf(tok::kw_if, tok::kw_for, tok::kw_while,
-                          tok::kw_switch, tok::kw_catch, tok::kw_case) ||
+                          tok::kw_switch, tok::kw_case) ||
+             (Left.is(tok::kw_catch) &&
+              (!Left.Previous || Left.Previous->isNot(tok::period))) ||
              Left.IsForEachMacro)) ||
            (Style.SpaceBeforeParens == FormatStyle::SBPO_Always &&
             (Left.is(tok::identifier) || Left.isFunctionLikeKeyword()) &&
index 4b0d1e77bd742ef7402d72746a2f5bbf8dcdb97c..5bb1a3850c8e9c89e8f0982726652a6d7499b1e1 100644 (file)
@@ -254,6 +254,9 @@ TEST_F(FormatTestJS, TryCatch) {
                "} finally {\n"
                "  h();\n"
                "}");
+
+  // But, of course, "catch" is a perfectly fine function name in JavaScript.
+  verifyFormat("someObject.catch();");
 }
 
 TEST_F(FormatTestJS, StringLiteralConcatenation) {