]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Fix space when for is used as regular identifier.
authorDaniel Jasper <djasper@google.com>
Tue, 1 Nov 2016 06:22:54 +0000 (06:22 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 1 Nov 2016 06:22:54 +0000 (06:22 +0000)
Before:
  x.for () = 1;

After:
  x.for() = 1;

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

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

index 1253e56c9867f921502a8adeba90f0b0ae8bcf3f..bd55e114a684983aade18d0d78a2116743cf75c7 100644 (file)
@@ -2159,6 +2159,9 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
                      Keywords.kw_of, tok::kw_const) &&
         (!Left.Previous || !Left.Previous->is(tok::period)))
       return true;
+    if (Left.is(tok::kw_for) && Left.Previous &&
+        Left.Previous->is(tok::period) && Right.is(tok::l_paren))
+      return false;
     if (Left.is(Keywords.kw_as) &&
         Right.isOneOf(tok::l_square, tok::l_brace, tok::l_paren))
       return true;
index 8c4bced24c7d270e2716e77eafdd526ef886ea90..71d09db7c071f9d92b0e703a1f2d5052c29aa434 100644 (file)
@@ -135,6 +135,7 @@ TEST_F(FormatTestJS, ReservedWords) {
   verifyFormat("x.in() = 1;");
   verifyFormat("x.let() = 1;");
   verifyFormat("x.var() = 1;");
+  verifyFormat("x.for() = 1;");
   verifyFormat("x = {\n"
                "  a: 12,\n"
                "  interface: 1,\n"