diff options
| author | Daniel Jasper <djasper@google.com> | 2014-05-08 07:45:18 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2014-05-08 07:45:18 +0000 |
| commit | f7405c129e4ffb01b7817e8b2b2da60c4f7efcce (patch) | |
| tree | 334876f12164b46faf57f12105ba655c99ec496f | |
| parent | 1187a3d8db35afec80423dca192c9826a403771e (diff) | |
| download | bcm5719-llvm-f7405c129e4ffb01b7817e8b2b2da60c4f7efcce.tar.gz bcm5719-llvm-f7405c129e4ffb01b7817e8b2b2da60c4f7efcce.zip | |
clang-format: [JS] Support regex literals after 'return'.
llvm-svn: 208285
| -rw-r--r-- | clang/lib/Format/Format.cpp | 10 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 2 |
2 files changed, 7 insertions, 5 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index c57993386f3..56af0cdfb84 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -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); diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 52c85d3a9ac..606303a68a9 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -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;"); |

