]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Fix comment formatting in goog.scopes.
authorDaniel Jasper <djasper@google.com>
Mon, 30 Mar 2015 09:56:50 +0000 (09:56 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 30 Mar 2015 09:56:50 +0000 (09:56 +0000)
Before:
  goog.scope(function() {
  // test
  var x = 0;
  // test
  });

After:
  goog.scope(function() {
  // test
  var x = 0;
    // test
  });

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233530 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 10ce0e9bee273c787b937107838d374f46e457e0..a036fb29da31a323c2c4f65935b5df624382c930 100644 (file)
@@ -420,7 +420,7 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel,
   Line->Level = InitialLevel;
 }
 
-static bool IsGoogScope(const UnwrappedLine &Line) {
+static bool isGoogScope(const UnwrappedLine &Line) {
   // FIXME: Closure-library specific stuff should not be hard-coded but be
   // configurable.
   if (Line.Tokens.size() < 4)
@@ -456,12 +456,13 @@ void UnwrappedLineParser::parseChildBlock() {
   nextToken();
   {
     bool GoogScope =
-        Style.Language == FormatStyle::LK_JavaScript && IsGoogScope(*Line);
+        Style.Language == FormatStyle::LK_JavaScript && isGoogScope(*Line);
     ScopedLineState LineState(*this);
     ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
                                             /*MustBeDeclaration=*/false);
     Line->Level += GoogScope ? 0 : 1;
     parseLevel(/*HasOpeningBrace=*/true);
+    flushComments(isOnNewLine(*FormatTok));
     Line->Level -= GoogScope ? 0 : 1;
   }
   nextToken();
index 5707024544759f321a707f39e987f97972220579..4378ded5c361b13785fd7e09055c669d6a40ad68 100644 (file)
@@ -167,6 +167,11 @@ TEST_F(FormatTestJS, GoogScopes) {
                "var x = a.b;\n"
                "var y = c.d;\n"
                "});  // goog.scope");
+  verifyFormat("goog.scope(function() {\n"
+               "// test\n"
+               "var x = 0;\n"
+               "// test\n"
+               "});");
 }
 
 TEST_F(FormatTestJS, GoogModules) {