]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Support regex literals at the start of a file.
authorDaniel Jasper <djasper@google.com>
Thu, 2 Jul 2015 13:20:45 +0000 (13:20 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 2 Jul 2015 13:20:45 +0000 (13:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241259 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 21f3efbb7a075a91aa844b5131b02827cfe9042d..b4ec445b5566d434a5f800c16203e0a75e776c83 100644 (file)
@@ -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) {
index 845ae5124b242d625b28056573b29d80f06a330a..83c21183dfdc6ab930a85eed5f49004b86e77e8f 100644 (file)
@@ -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/;");