From 5e92afa681f2594a23b53ecf2a525b4d381c62b6 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 2 Jul 2015 15:00:44 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241273 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/Format.cpp | 2 ++ unittests/Format/FormatTestJS.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index f97e1fbc6d..2bbe4c63d1 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -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; } diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index ef5901e8d6..b3e0f68ac3 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -638,6 +638,10 @@ TEST_F(FormatTestJS, RegexLiteralSpecialCharacters) { getGoogleJSStyleWithColumns(15)); verifyFormat("var regex = //\n" " /a/;"); + verifyFormat("var regexs = [\n" + " /d/, //\n" + " /aa/, //\n" + "];"); } TEST_F(FormatTestJS, RegexLiteralModifiers) { -- 2.40.0