Author: djasper Date: Thu Jul 2 10:00:44 2015 New Revision: 241273 URL: http://llvm.org/viewvc/llvm-project?rev=241273&view=rev Log: clang-format: [JS] Treat regex literals like string literals.
Using the token type "unknown" can interfere badly with WhitespaceManager's way of handling multiline comments. 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=241273&r1=241272&r2=241273&view=diff ============================================================================== --- cfe/trunk/lib/Format/Format.cpp (original) +++ cfe/trunk/lib/Format/Format.cpp Thu Jul 2 10:00:44 2015 @@ -808,6 +808,8 @@ private: Tokens.resize(Tokens.size() - TokenCount); Tokens.back()->Tok.setKind(tok::unknown); Tokens.back()->Type = TT_RegexLiteral; + // Treat regex literals like other string_literals. + Tokens.back()->Tok.setKind(tok::string_literal); Tokens.back()->ColumnWidth += LastColumn - I[0]->OriginalColumn; return true; } Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=241273&r1=241272&r2=241273&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTestJS.cpp (original) +++ cfe/trunk/unittests/Format/FormatTestJS.cpp Thu Jul 2 10:00:44 2015 @@ -638,6 +638,10 @@ TEST_F(FormatTestJS, RegexLiteralSpecial getGoogleJSStyleWithColumns(15)); verifyFormat("var regex = //\n" " /a/;"); + verifyFormat("var regexs = [\n" + " /d/, //\n" + " /aa/, //\n" + "];"); } TEST_F(FormatTestJS, RegexLiteralModifiers) { _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits