From fd7431291bd2bcd4ea3b768d5eff7098dd22266f Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Thu, 12 May 2016 11:20:32 +0000 Subject: [PATCH] clang-format: [JS] respect clang-format off when requoting strings. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D20200 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@269282 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/Format.cpp | 2 +- unittests/Format/FormatTestJS.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index efcecee140..66077d8832 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -1652,7 +1652,7 @@ private: for (FormatToken *FormatTok = Line->First; FormatTok; FormatTok = FormatTok->Next) { StringRef Input = FormatTok->TokenText; - if (!FormatTok->isStringLiteral() || + if (FormatTok->Finalized || !FormatTok->isStringLiteral() || // NB: testing for not starting with a double quote to avoid // breaking // `template strings`. diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 95fd2e7bb0..72d8948bb7 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -1236,6 +1236,14 @@ TEST_F(FormatTestJS, RequoteStringsSingle) { // Code below fits into 15 chars *after* removing the \ escape. verifyFormat("var x = 'fo\"o';", "var x = \"fo\\\"o\";", getGoogleJSStyleWithColumns(15)); + verifyFormat("// clang-format off\n" + "let x = \"double\";\n" + "// clang-format on\n" + "let x = 'single';\n", + "// clang-format off\n" + "let x = \"double\";\n" + "// clang-format on\n" + "let x = \"single\";\n"); } TEST_F(FormatTestJS, RequoteStringsDouble) { -- 2.40.0