r241259 - clang-format: [JS] Support regex literals at the start of a file.

Daniel Jasper djasper at google.com
Thu Jul 2 06:20:45 PDT 2015


Author: djasper
Date: Thu Jul  2 08:20:45 2015
New Revision: 241259

URL: http://llvm.org/viewvc/llvm-project?rev=241259&view=rev
Log:
clang-format: [JS] Support regex literals at the start of a file.

Modified:
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=241259&r1=241258&r2=241259&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu Jul  2 08:20:45 2015
@@ -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) {

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=241259&r1=241258&r2=241259&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Thu Jul  2 08:20:45 2015
@@ -579,6 +579,7 @@ TEST_F(FormatTestJS, RegexLiteralClassif
   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/;");
 





More information about the cfe-commits mailing list