]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Fix regex literal detection.
authorDaniel Jasper <djasper@google.com>
Fri, 8 May 2015 07:55:13 +0000 (07:55 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 8 May 2015 07:55:13 +0000 (07:55 +0000)
Before:
  var regex = /= / ;

After:
  var regex = /=/;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236811 91177308-0d34-0410-b5e6-96231b3b80d8

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

index bb10c60b2f11a3cb0ac47c5c843ba976dc957d5e..aa24891adc78b962c3b13547522703f9cde3b1f2 100644 (file)
@@ -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) ||
index 43fc4b47284d50f260a61baa4ce744ea009c2f9a..0d37caf1c94d141ccf2e3b124730125f3708d80d 100644 (file)
@@ -463,6 +463,7 @@ TEST_F(FormatTestJS, RegexLiteralClassification) {
 }
 
 TEST_F(FormatTestJS, RegexLiteralSpecialCharacters) {
+  verifyFormat("var regex = /=/;");
   verifyFormat("var regex = /a*/;");
   verifyFormat("var regex = /a+/;");
   verifyFormat("var regex = /a?/;");