]> granicus.if.org Git - clang/commitdiff
clang-format: Fix the counting of leading whitespace in tok::unknown tokens
authorDaniel Jasper <djasper@google.com>
Sat, 9 Jan 2016 21:12:45 +0000 (21:12 +0000)
committerDaniel Jasper <djasper@google.com>
Sat, 9 Jan 2016 21:12:45 +0000 (21:12 +0000)
Previously, all whitespace characters would increase the starting
column, which doesn't make sense. This fixes a problem, e.g. with the
length calculation in JS template strings.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257267 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/Format.cpp
unittests/Format/FormatTestJS.cpp

index 2ea3b07a291c6c1ee9dcbb5f365984175eeb3eb2..2689368da513dabe9edc4cc20cf3fd97c8034edc 100644 (file)
@@ -1239,6 +1239,8 @@ private:
           FormatTok->Type = TT_ImplicitStringLiteral;
           break;
         }
+        if (FormatTok->Type == TT_ImplicitStringLiteral)
+          break;
       }
 
       if (FormatTok->is(TT_ImplicitStringLiteral))
index a35a86ea4ede0f33dc095e21c48f0062020c87f0..4e974d7285ded0d118b85014dbebb556dae3f51a 100644 (file)
@@ -956,6 +956,9 @@ TEST_F(FormatTestJS, TemplateStrings) {
                "var y;");
   verifyFormat("var x = `\"`;  // comment with matching quote \"\n"
                "var y;");
+  EXPECT_EQ("it(`'aaaaaaaaaaaaaaa   `, aaaaaaaaa);",
+            format("it(`'aaaaaaaaaaaaaaa   `,   aaaaaaaaa) ;",
+                   getGoogleJSStyleWithColumns(40)));
   // Backticks in a comment - not a template string.
   EXPECT_EQ("var x = 1  // `/*a`;\n"
             "    ;",