summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2016-05-20 06:16:01 +0000
committerDaniel Jasper <djasper@google.com>2016-05-20 06:16:01 +0000
commit997cf2fea83516555b9c0804bd7da42949788a69 (patch)
treecbc8aa82ab2008ae36b70e3732acc4b60a177f22
parent357b0e3a7c37911c958449c73c3736ec99471b74 (diff)
downloadbcm5719-llvm-997cf2fea83516555b9c0804bd7da42949788a69.tar.gz
bcm5719-llvm-997cf2fea83516555b9c0804bd7da42949788a69.zip
clang-format: [JS] Treat "for" as a reserved word after a ".".
Otherwise, clang-format can get confused with statements like: x.for = 1; llvm-svn: 270188
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp3
-rw-r--r--clang/unittests/Format/FormatTestJS.cpp1
2 files changed, 4 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 1713865ee59..2ddff47b930 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -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())
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index 5f60f1d2162..457298704d8 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -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;");
OpenPOWER on IntegriCloud