From: Daniel Jasper Date: Mon, 30 Mar 2015 09:56:50 +0000 (+0000) Subject: clang-format: [JS] Fix comment formatting in goog.scopes. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=53ca532d876b8be5c31b3f9dcac227eb8dd618c4;p=clang clang-format: [JS] Fix comment formatting in goog.scopes. 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 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 10ce0e9bee..a036fb29da 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -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(); diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 5707024544..4378ded5c3 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -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) {