[PATCH] clang-format: [JS] fix incorrectly collapsed lines after export statement.

Martin Probst martinprobst at google.com
Thu Jun 11 21:35:21 PDT 2015


kw_import is unneeded, there is no "import function ..." statement.


http://reviews.llvm.org/D10408

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

Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -838,9 +838,13 @@
       return;
     case tok::identifier: {
       // Parse function literal unless 'function' is the first token in a line
-      // in which case this should be treated as a free-standing function.
+      // (or it is part of an export statement) in which case this should be
+      // treated as a free-standing function.
       if (Style.Language == FormatStyle::LK_JavaScript &&
-          FormatTok->is(Keywords.kw_function) && Line->Tokens.size() > 0) {
+          FormatTok->is(Keywords.kw_function) && Line->Tokens.size() > 0 &&
+          (true ||
+           !(Line->Tokens.size() == 1 &&
+             Line->Tokens.begin()->Tok->is(tok::kw_export)))) {
         tryToParseJSFunction();
         break;
       }
Index: unittests/Format/FormatTestJS.cpp
===================================================================
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -726,6 +726,9 @@
   verifyFormat("export default class X { y: number }");
   verifyFormat("export default function() {\n  return 1;\n}");
   verifyFormat("export var x = 12;");
+  verifyFormat("class C {}\n"
+               "export function f() {}\n"
+               "var v;");
   verifyFormat("export var x: number = 12;");
   verifyFormat("export const y = {\n"
                "  a: 1,\n"

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10408.27563.patch
Type: text/x-patch
Size: 1512 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150612/6ab4f270/attachment.bin>


More information about the cfe-commits mailing list