r273422 - clang-format: [JS] Do not break before 'as'.

Martin Probst via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 22 07:35:15 PDT 2016


Author: mprobst
Date: Wed Jun 22 09:35:14 2016
New Revision: 273422

URL: http://llvm.org/viewvc/llvm-project?rev=273422&view=rev
Log:
clang-format: [JS] Do not break before 'as'.

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

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=273422&r1=273421&r2=273422&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Jun 22 09:35:14 2016
@@ -2373,6 +2373,8 @@ bool TokenAnnotator::canBreakBefore(cons
       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))

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=273422&r1=273421&r2=273422&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Jun 22 09:35:14 2016
@@ -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"




More information about the cfe-commits mailing list