r208285 - clang-format: [JS] Support regex literals after 'return'.

Daniel Jasper djasper at google.com
Thu May 8 00:45:18 PDT 2014


Author: djasper
Date: Thu May  8 02:45:18 2014
New Revision: 208285

URL: http://llvm.org/viewvc/llvm-project?rev=208285&view=rev
Log:
clang-format: [JS] Support regex literals after 'return'.

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=208285&r1=208284&r2=208285&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu May  8 02:45:18 2014
@@ -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
+  // a 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);

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=208285&r1=208284&r2=208285&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Thu May  8 02:45:18 2014
@@ -123,6 +123,8 @@ 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("var regexs = {/abc/, /abc/};");
+  verifyFormat("return /abc/;");
 
   // Not regex literals.
   verifyFormat("var a = a / 2 + b / 3;");





More information about the cfe-commits mailing list