Hi djasper,

We should consume function identifier only when we are in braced list.

This fixes bug introduced in 71bd6fc3 that effectively disabled JS function
formatting.

http://reviews.llvm.org/D4190

Files:
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/UnwrappedLineParser.h

Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -905,11 +905,11 @@
   return false;
 }
 
-void UnwrappedLineParser::tryToParseJSFunction() {
+void UnwrappedLineParser::tryToParseJSFunction(bool BracedList) {
   nextToken();
 
-  // Consume function name.
-  if (FormatTok->is(tok::identifier))
+  // Consume function name if in braced list.
+  if (BracedList && FormatTok->is(tok::identifier))
       nextToken();
 
   if (FormatTok->isNot(tok::l_paren))
@@ -945,7 +945,7 @@
   do {
     if (Style.Language == FormatStyle::LK_JavaScript &&
         FormatTok->TokenText == "function") {
-      tryToParseJSFunction();
+      tryToParseJSFunction(true);
       continue;
     }
     switch (FormatTok->Tok.getKind()) {
Index: lib/Format/UnwrappedLineParser.h
===================================================================
--- lib/Format/UnwrappedLineParser.h
+++ lib/Format/UnwrappedLineParser.h
@@ -101,7 +101,7 @@
   void parseObjCProtocol();
   bool tryToParseLambda();
   bool tryToParseLambdaIntroducer();
-  void tryToParseJSFunction();
+  void tryToParseJSFunction(bool BracedList = false);
   void addUnwrappedLine();
   bool eof() const;
   void nextToken();
Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -905,11 +905,11 @@
   return false;
 }
 
-void UnwrappedLineParser::tryToParseJSFunction() {
+void UnwrappedLineParser::tryToParseJSFunction(bool BracedList) {
   nextToken();
 
-  // Consume function name.
-  if (FormatTok->is(tok::identifier))
+  // Consume function name if in braced list.
+  if (BracedList && FormatTok->is(tok::identifier))
       nextToken();
 
   if (FormatTok->isNot(tok::l_paren))
@@ -945,7 +945,7 @@
   do {
     if (Style.Language == FormatStyle::LK_JavaScript &&
         FormatTok->TokenText == "function") {
-      tryToParseJSFunction();
+      tryToParseJSFunction(true);
       continue;
     }
     switch (FormatTok->Tok.getKind()) {
Index: lib/Format/UnwrappedLineParser.h
===================================================================
--- lib/Format/UnwrappedLineParser.h
+++ lib/Format/UnwrappedLineParser.h
@@ -101,7 +101,7 @@
   void parseObjCProtocol();
   bool tryToParseLambda();
   bool tryToParseLambdaIntroducer();
-  void tryToParseJSFunction();
+  void tryToParseJSFunction(bool BracedList = false);
   void addUnwrappedLine();
   bool eof() const;
   void nextToken();
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to