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();
}
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