From 496c1999593d9aee2f4ea991561851ba8e712aca Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 7 Sep 2016 22:48:53 +0000 Subject: clang-format: [JavaScript] Do requoting in a separate pass The attempt to fix requoting behavior in r280487 after changes to tooling::Replacements are incomplete. We essentially need to add to replacements at the same position, one to insert a line break and one to change the quoting and that's incompatible with the new tooling::Replacement API, which does not allow for order-dependent Replacements. To make the order clear, Replacements::merge() has to be used, but that requires the merged Replacement to actually refer to the changed text, which is hard to reproduce for the requoting. This change fixes the behavior by moving the requoting to a completely separate pass. The added benefit is that no weird ColumnWidth calculations are necessary anymore and this should just work even if we implement string literal splitting in the future. llvm-svn: 280874 --- clang/unittests/Format/FormatTestJS.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'clang/unittests/Format/FormatTestJS.cpp') diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 569f0657617..22ed04f6304 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -1342,6 +1342,14 @@ TEST_F(FormatTestJS, RequoteAndIndent) { " 'double quoted string that needs wrapping');", "let x = someVeryLongFunctionThatGoesOnAndOn(" "\"double quoted string that needs wrapping\");"); + + verifyFormat("let x =\n" + " 'foo\\'oo';\n" + "let x =\n" + " 'foo\\'oo';", + "let x=\"foo'oo\";\n" + "let x=\"foo'oo\";", + getGoogleJSStyleWithColumns(15)); } TEST_F(FormatTestJS, RequoteStringsDouble) { -- cgit v1.2.3