]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] revert over-eager ASI check.
authorMartin Probst <martin@probst.io>
Mon, 16 Jan 2017 09:52:40 +0000 (09:52 +0000)
committerMartin Probst <martin@probst.io>
Mon, 16 Jan 2017 09:52:40 +0000 (09:52 +0000)
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

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

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

index 8fc3b78aee01060d2495a3feeb59feddd5c40ece..1dcb866a16bda67df5b55bcb32837e951ca94cf6 100644 (file)
@@ -746,8 +746,7 @@ void UnwrappedLineParser::readTokenWithJavaScriptASI() {
        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();
 }
 
index 230717fe47cc4a2bfc2b369e1508b89ca3830516..50ba4ffdae99a0c0454e4f8a21b8d319e6263ad5 100644 (file)
@@ -858,13 +858,25 @@ TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) {
                "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) {