diff options
| -rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 22 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 7 |
2 files changed, 27 insertions, 2 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 0467b3a1662..5b6727bf9e4 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -415,16 +415,34 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel, Line->Level = InitialLevel; } +static bool IsGoogScope(const UnwrappedLine &Line) { + if (Line.Tokens.size() < 4) + return false; + auto I = Line.Tokens.begin(); + if (I->Tok->TokenText != "goog") + return false; + ++I; + if (I->Tok->isNot(tok::period)) + return false; + ++I; + if (I->Tok->TokenText != "scope") + return false; + ++I; + return I->Tok->is(tok::l_paren); +} + void UnwrappedLineParser::parseChildBlock() { FormatTok->BlockKind = BK_Block; nextToken(); { + bool GoogScope = + Style.Language == FormatStyle::LK_JavaScript && IsGoogScope(*Line); ScopedLineState LineState(*this); ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack, /*MustBeDeclaration=*/false); - Line->Level += 1; + Line->Level += GoogScope ? 0 : 1; parseLevel(/*HasOpeningBrace=*/true); - Line->Level -= 1; + Line->Level -= GoogScope ? 0 : 1; } nextToken(); } diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index e7ca14f595d..4e8908685f0 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -91,5 +91,12 @@ TEST_F(FormatTestJS, SingleQuoteStrings) { verifyFormat("this.function('', true);"); } +TEST_F(FormatTestJS, GoogScopes) { + verifyFormat("goog.scope(function() {\n" + "var x = a.b;\n" + "var y = c.d;\n" + "}); // goog.scope"); +} + } // end namespace tooling } // end namespace clang |

