]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Support regex literals after 'return'.
authorDaniel Jasper <djasper@google.com>
Thu, 8 May 2014 07:45:18 +0000 (07:45 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 8 May 2014 07:45:18 +0000 (07:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208285 91177308-0d34-0410-b5e6-96231b3b80d8

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

index c57993386f30ae2b569d962d936d5ca2fcfb4521..56af0cdfb84c355ea5eea146a031fdc127d91607 100644 (file)
@@ -1258,8 +1258,8 @@ private:
   // Try to determine whether the current token ends a JavaScript regex literal.
   // We heuristically assume that this is a regex literal if we find two
   // unescaped slashes on a line and the token before the first slash is one of
-  // "(;,{}![:?" or a binary operator, as those cannot be followed by a
-  // division.
+  // "(;,{}![:?", a binary operator or 'return', as those cannot be followed by
+  // division.
   bool tryMergeJSRegexLiteral() {
       if (Tokens.size() < 2 || Tokens.back()->isNot(tok::slash) ||
           Tokens[Tokens.size() - 2]->is(tok::unknown))
@@ -1269,9 +1269,9 @@ private:
       for (auto I = Tokens.rbegin() + 1, E = Tokens.rend(); I != E; ++I) {
         ++TokenCount;
         if (I[0]->is(tok::slash) && 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) ||
+            (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())) {
           Tokens.resize(Tokens.size() - TokenCount);
           Tokens.back()->Tok.setKind(tok::unknown);
index 52c85d3a9ac9c5dcfca270f03cfaffd946c2bdbe..606303a68a921c461b988bad73b3fed61e1cd993 100644 (file)
@@ -123,6 +123,8 @@ 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("var regexs = {/abc/, /abc/};");
+  verifyFormat("return /abc/;");
 
   // Not regex literals.
   verifyFormat("var a = a / 2 + b / 3;");