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

Martin Probst via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 4 05:46:49 PST 2017


mprobst updated this revision to Diff 83038.
mprobst added a comment.

- Handle type declarations.
- test for object literal return types


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,16 @@
       "declare function\n"
       "x();",  // TODO(martinprobst): should ideally be indented.
       NineCols);
+  verifyFormat("declare function foo();\n"
+               "let x = 1;\n");
+  verifyFormat("declare function foo(): string;\n"
+               "let x = 1;\n");
+  verifyFormat("declare function foo(): {x: number};\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
@@ -1255,10 +1255,13 @@
     if (FormatTok->is(tok::l_brace))
       tryToParseBracedList();
     else
-      while (FormatTok->isNot(tok::l_brace) && !eof())
+      while (!FormatTok->isOneOf(tok::l_brace, tok::semi) && !eof())
         nextToken();
   }
 
+  if (FormatTok->is(tok::semi))
+    return;
+
   parseChildBlock();
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28246.83038.patch
Type: text/x-patch
Size: 1297 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170104/9e6c5cd6/attachment.bin>


More information about the cfe-commits mailing list