]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Do not break before 'as'.
authorMartin Probst <martin@probst.io>
Wed, 22 Jun 2016 14:35:14 +0000 (14:35 +0000)
committerMartin Probst <martin@probst.io>
Wed, 22 Jun 2016 14:35:14 +0000 (14:35 +0000)
Summary:
'as' is a pseudo operator, so automatic semicolon insertion kicks in and the
code fails to part.

Reviewers: djasper

Subscribers: klimek

Differential Revision: http://reviews.llvm.org/D21576

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

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

index fe7e001daaf74d6b5347b2aa0837a210cd0cd9d1..9c4a6268abe712adbf7c6a389f4412d870b55b48 100644 (file)
@@ -2373,6 +2373,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
       return Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None;
     if (Right.is(Keywords.kw_in))
       return Style.BreakBeforeBinaryOperators != FormatStyle::BOS_None;
+    if (Right.is(Keywords.kw_as))
+      return false; // must not break before as in 'x as type' casts
   }
 
   if (Left.is(tok::at))
index f71571c16a32207afb7a410ec95eab1d738d3b39..4feb55dae2496533ffe597289351634a27acaaac 100644 (file)
@@ -1051,8 +1051,8 @@ TEST_F(FormatTestJS, Modules) {
   // ... but not if from is just an identifier.
   verifyFormat("export {\n"
                "  from as from,\n"
-               "  someSurprisinglyLongVariable\n"
-               "      as from\n"
+               "  someSurprisinglyLongVariable as\n"
+               "      from\n"
                "};",
                getGoogleJSStyleWithColumns(20));
   verifyFormat("export class C {\n"
@@ -1205,6 +1205,9 @@ TEST_F(FormatTestJS, TemplateStrings) {
 TEST_F(FormatTestJS, CastSyntax) {
   verifyFormat("var x = <type>foo;");
   verifyFormat("var x = foo as type;");
+  verifyFormat("let x = (a + b) as\n"
+               "    LongTypeIsLong;",
+               getGoogleJSStyleWithColumns(20));
   verifyFormat("foo = <Bar[]>[\n"
                "  1,  //\n"
                "  2\n"