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/
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"
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to