From: Daniel Jasper Date: Fri, 20 May 2016 06:16:01 +0000 (+0000) Subject: clang-format: [JS] Treat "for" as a reserved word after a ".". X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b01e846494bf1b34459689a49ea3d9b8530788f8;p=clang clang-format: [JS] Treat "for" as a reserved word after a ".". 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 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 1713865ee5..2ddff47b93 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/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/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 5f60f1d216..457298704d 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/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;");