diff options
| author | Daniel Jasper <djasper@google.com> | 2014-05-06 13:54:10 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2014-05-06 13:54:10 +0000 |
| commit | 4a39c84c91aa2c03394245121cf3e182a1654b42 (patch) | |
| tree | e627ef978917e671bc1597115d8f827636689a4f /clang/lib | |
| parent | 0b397eaf9365fdfd417a77be7b03eacd27227cf7 (diff) | |
| download | bcm5719-llvm-4a39c84c91aa2c03394245121cf3e182a1654b42.tar.gz bcm5719-llvm-4a39c84c91aa2c03394245121cf3e182a1654b42.zip | |
clang-format: [JS] Don't indent in goog.scope blocks.
Before:
goog.scope(function() {
var x = a.b;
var y = c.d;
}); // goog.scope
After:
goog.scope(function() {
var x = a.b;
var y = c.d;
}); // goog.scope
llvm-svn: 208088
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 22 |
1 files changed, 20 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(); } |

