]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Treat "for" as a reserved word after a ".".
authorDaniel Jasper <djasper@google.com>
Fri, 20 May 2016 06:16:01 +0000 (06:16 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 20 May 2016 06:16:01 +0000 (06:16 +0000)
Otherwise, clang-format can get confused with statements like:

  x.for = 1;

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

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

index 1713865ee5965cad5b327b0c723a5283c263dfd5..2ddff47b930caa7028f5684da51c685a25327f21 100644 (file)
@@ -538,6 +538,9 @@ private:
       }
       break;
     case tok::kw_for:
+      if (Style.Language == FormatStyle::LK_JavaScript && Tok->Previous &&
+          Tok->Previous->is(tok::period))
+        break;
       Contexts.back().ColonIsForRangeExpr = true;
       next();
       if (!parseParens())
index 5f60f1d2162bb67bb1e4e942247e45f355738b7b..457298704d8bf041f4535e1504be1b2dc6ba7c5a 100644 (file)
@@ -125,6 +125,7 @@ TEST_F(FormatTestJS, ReservedWords) {
   verifyFormat("x.class.struct = 1;");
   verifyFormat("x.case = 1;");
   verifyFormat("x.interface = 1;");
+  verifyFormat("x.for = 1;");
   verifyFormat("x.of() = 1;");
   verifyFormat("x.in() = 1;");
   verifyFormat("x.let() = 1;");