Author: mprobst
Date: Mon Jan 16 03:52:40 2017
New Revision: 292099

URL: http://llvm.org/viewvc/llvm-project?rev=292099&view=rev
Log:
clang-format: [JS] revert over-eager ASI check.

Summary: Change r291428 introduced ASI detection after closing curly braces. 
That would generally be correct, however this breaks indentation for structural 
statements. What happens is that CompoundStatementIndenter increases 
indentation for the current line, then after reading ASI creates a new line 
(with the increased line level), and only after the structural parser sees e.g. 
the if/then/else branch closed, line level is reduced. That leads to the new 
line started by ASI having a level too high.

Reviewers: djasper

Subscribers: sammccall, cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D28763

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

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=292099&r1=292098&r2=292099&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Jan 16 03:52:40 2017
@@ -746,8 +746,7 @@ void UnwrappedLineParser::readTokenWithJ
        Previous->isOneOf(tok::r_square, tok::r_paren, tok::plusplus,
                          tok::minusminus)))
     return addUnwrappedLine();
-  if ((PreviousMustBeValue || Previous->is(tok::r_brace)) &&
-      isJSDeclOrStmt(Keywords, Next))
+  if (PreviousMustBeValue && isJSDeclOrStmt(Keywords, Next))
     return addUnwrappedLine();
 }
 

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=292099&r1=292098&r2=292099&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon Jan 16 03:52:40 2017
@@ -858,13 +858,25 @@ TEST_F(FormatTestJS, AutomaticSemicolonI
                "return 1",
                "a = null\n"
                "  return   1");
+  // Below "class Y {}" should ideally be on its own line.
   verifyFormat(
       "x = {\n"
       "  a: 1\n"
-      "}\n"
-      "class Y {}",
+      "} class Y {}",
       "  x  =  {a  : 1}\n"
       "   class  Y {  }");
+  verifyFormat(
+      "if (x) {\n"
+      "}\n"
+      "return 1",
+      "if (x) {}\n"
+      " return   1");
+  verifyFormat(
+      "if (x) {\n"
+      "}\n"
+      "class X {}",
+      "if (x) {}\n"
+      " class X {}");
 }
 
 TEST_F(FormatTestJS, ImportExportASI) {
@@ -873,11 +885,17 @@ TEST_F(FormatTestJS, ImportExportASI) {
       "export function z() {}",
       "import   {x} from 'y'\n"
       "  export function z() {}");
+  // Below "class Y {}" should ideally be on its own line.
   verifyFormat(
-      "export {x}\n"
-      "class Y {}",
+      "export {x} class Y {}",
       "  export {x}\n"
       "  class  Y {\n}");
+  verifyFormat(
+      "if (x) {\n"
+      "}\n"
+      "export class Y {}",
+      "if ( x ) { }\n"
+      " export class Y {}");
 }
 
 TEST_F(FormatTestJS, ClosureStyleCasts) {


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to