r236811 - clang-format: [JS] Fix regex literal detection.
Daniel Jasper
djasper at google.com
Fri May 8 00:55:13 PDT 2015
Author: djasper
Date: Fri May 8 02:55:13 2015
New Revision: 236811
URL: http://llvm.org/viewvc/llvm-project?rev=236811&view=rev
Log:
clang-format: [JS] Fix regex literal detection.
Before:
var regex = /= / ;
After:
var regex = /=/;
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=236811&r1=236810&r2=236811&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri May 8 02:55:13 2015
@@ -752,7 +752,7 @@ private:
unsigned LastColumn = Tokens.back()->OriginalColumn;
for (auto I = Tokens.rbegin() + 1, E = Tokens.rend(); I != E; ++I) {
++TokenCount;
- if (I[0]->is(tok::slash) && I + 1 != E &&
+ 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) ||
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=236811&r1=236810&r2=236811&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Fri May 8 02:55:13 2015
@@ -463,6 +463,7 @@ TEST_F(FormatTestJS, RegexLiteralClassif
}
TEST_F(FormatTestJS, RegexLiteralSpecialCharacters) {
+ verifyFormat("var regex = /=/;");
verifyFormat("var regex = /a*/;");
verifyFormat("var regex = /a+/;");
verifyFormat("var regex = /a?/;");
More information about the cfe-commits
mailing list