r241262 - clang-format: [JS] Fix bug in regex literal parsing.

Daniel Jasper djasper at google.com
Thu Jul 2 07:01:35 PDT 2015


Author: djasper
Date: Thu Jul  2 09:01:34 2015
New Revision: 241262

URL: http://llvm.org/viewvc/llvm-project?rev=241262&view=rev
Log:
clang-format: [JS] Fix bug in regex literal parsing.

The lexer wasn't properly reset leading to unexpected deletions.

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=241262&r1=241261&r2=241262&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu Jul  2 09:01:34 2015
@@ -1227,6 +1227,7 @@ private:
                         getFormattingLangOpts(Style), Buffer.begin(),
                         Buffer.begin() + Offset, Buffer.end()));
     Lex->SetKeepWhitespaceMode(true);
+    TrailingWhitespace = 0;
   }
 };
 

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=241262&r1=241261&r2=241262&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Thu Jul  2 09:01:34 2015
@@ -631,6 +631,7 @@ TEST_F(FormatTestJS, RegexLiteralSpecial
             "var x = 0;",
             format("var regex = /\\/*/;\n"
                    "var x=0;"));
+  EXPECT_EQ("var x = /a\\//;", format("var x = /a\\//  \n;"));
   verifyFormat("var regex = /\"/;", getGoogleJSStyleWithColumns(16));
   verifyFormat("var regex =\n"
                "    /\"/;",





More information about the cfe-commits mailing list