From: Daniel Jasper Date: Thu, 2 Jul 2015 13:20:45 +0000 (+0000) Subject: clang-format: [JS] Support regex literals at the start of a file. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=89095b502603559cf0a92c0e9d4a13658646e412;p=clang clang-format: [JS] Support regex literals at the start of a file. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241259 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 21f3efbb7a..b4ec445b55 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -783,11 +783,12 @@ private: unsigned TokenCount = 0; for (auto I = Tokens.rbegin() + 1, E = Tokens.rend(); I != E; ++I) { ++TokenCount; - if (I[0]->isOneOf(tok::slash, tok::slashequal) && I + 1 != E && - (I[1]->isOneOf(tok::l_paren, tok::semi, tok::l_brace, tok::r_brace, - tok::exclaim, tok::l_square, tok::colon, tok::comma, - tok::question, tok::kw_return) || - I[1]->isBinaryOperator())) { + if (I[0]->isOneOf(tok::slash, tok::slashequal) && + (I + 1 == E || + ((I[1]->isOneOf(tok::l_paren, tok::semi, tok::l_brace, tok::r_brace, + tok::exclaim, tok::l_square, tok::colon, tok::comma, + tok::question, tok::kw_return) || + I[1]->isBinaryOperator())))) { unsigned LastColumn = Tokens.back()->OriginalColumn; SourceLocation Loc = Tokens.back()->Tok.getLocation(); if (MightEndWithEscapedSlash) { diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 845ae5124b..83c21183df 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -579,6 +579,7 @@ TEST_F(FormatTestJS, RegexLiteralClassification) { verifyFormat("var x = a && /abc/.test(y);"); verifyFormat("var x = a || /abc/.test(y);"); verifyFormat("var x = a + /abc/.search(y);"); + verifyFormat("/abc/.search(y);"); verifyFormat("var regexs = {/abc/, /abc/};"); verifyFormat("return /abc/;");