r285670 - clang-format: [JS] Fix formatting of generator functions.

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 31 23:22:59 PDT 2016


Author: djasper
Date: Tue Nov  1 01:22:59 2016
New Revision: 285670

URL: http://llvm.org/viewvc/llvm-project?rev=285670&view=rev
Log:
clang-format: [JS] Fix formatting of generator functions.

Before:
  var x = {
    a: function*
	() {
	  //
	}
  }

After:
  var x = {
    a: function*() {
      //
    }
  }

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/lib/Format/UnwrappedLineParser.cpp
    cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=285670&r1=285669&r2=285670&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Nov  1 01:22:59 2016
@@ -859,7 +859,8 @@ private:
     if (!CurrentToken->isOneOf(TT_LambdaLSquare, TT_ForEachMacro,
                                TT_FunctionLBrace, TT_ImplicitStringLiteral,
                                TT_InlineASMBrace, TT_JsFatArrow, TT_LambdaArrow,
-                               TT_RegexLiteral, TT_TemplateString))
+                               TT_OverloadedOperator, TT_RegexLiteral,
+                               TT_TemplateString))
       CurrentToken->Type = TT_Unknown;
     CurrentToken->Role.reset();
     CurrentToken->MatchingParen = nullptr;

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=285670&r1=285669&r2=285670&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Tue Nov  1 01:22:59 2016
@@ -1230,9 +1230,11 @@ void UnwrappedLineParser::tryToParseJSFu
   // Consume "function".
   nextToken();
 
-  // Consume * (generator function).
-  if (FormatTok->is(tok::star))
+  // Consume * (generator function). Treat it like C++'s overloaded operators.
+  if (FormatTok->is(tok::star)) {
+    FormatTok->Type = TT_OverloadedOperator;
     nextToken();
+  }
 
   // Consume function name.
   if (FormatTok->is(tok::identifier))

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=285670&r1=285669&r2=285670&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Nov  1 01:22:59 2016
@@ -384,6 +384,11 @@ TEST_F(FormatTestJS, GeneratorFunctions)
                "    yield x;\n"
                "  }\n"
                "}");
+  verifyFormat("var x = {\n"
+               "  a: function*() {\n"
+               "    //\n"
+               "  }\n"
+               "}\n");
 }
 
 TEST_F(FormatTestJS, AsyncFunctions) {




More information about the cfe-commits mailing list