[PATCH] D28246: clang-format: [JS] avoid indent after ambient function declarations.

Martin Probst via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 3 11:45:26 PST 2017


mprobst created this revision.
mprobst added a reviewer: djasper.
mprobst added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

Before:

  declare function foo();
    let x = 1;

After:

  declare function foo();
  let x = 1;

The problem was that clang-format would unconditionally try to parse a child block, even though ambient function declarations do not have a body (similar to forward declarations).


https://reviews.llvm.org/D28246

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


Index: unittests/Format/FormatTestJS.cpp
===================================================================
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -377,6 +377,12 @@
       "declare function\n"
       "x();",  // TODO(martinprobst): should ideally be indented.
       NineCols);
+  verifyFormat("declare function foo();\n"
+               "let x = 1;\n");
+  verifyFormat("declare class X {}\n"
+               "let x = 1;\n");
+  verifyFormat("declare interface Y {}\n"
+               "let x = 1;\n");
   verifyFormat(
       "declare enum X {\n"
       "}",
Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1259,6 +1259,9 @@
         nextToken();
   }
 
+  if (FormatTok->is(tok::semi))
+    return;
+
   parseChildBlock();
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28246.82923.patch
Type: text/x-patch
Size: 915 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170103/602bf5aa/attachment.bin>


More information about the cfe-commits mailing list