Skip to content

Commit

Permalink
clang-format: [JS] Add goog.setTestOnly to the list of stuff that
Browse files Browse the repository at this point in the history
is import-statement-like and shouldn't be wrapped.

llvm-svn: 251643
  • Loading branch information
djasper committed Oct 29, 2015
1 parent 204aa1d commit b488a74
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions clang/lib/Format/TokenAnnotator.cpp
Expand Up @@ -727,7 +727,7 @@ class AnnotatingParser {
while (CurrentToken) {
if (CurrentToken->is(tok::kw_virtual))
KeywordVirtualFound = true;
if (IsImportStatement(*CurrentToken))
if (isImportStatement(*CurrentToken))
ImportStatement = true;
if (!consumeToken())
return LT_Invalid;
Expand All @@ -748,14 +748,15 @@ class AnnotatingParser {
}

private:
bool IsImportStatement(const FormatToken &Tok) {
bool isImportStatement(const FormatToken &Tok) {
// FIXME: Closure-library specific stuff should not be hard-coded but be
// configurable.
return Style.Language == FormatStyle::LK_JavaScript &&
Tok.TokenText == "goog" && Tok.Next && Tok.Next->is(tok::period) &&
Tok.Next->Next && (Tok.Next->Next->TokenText == "module" ||
Tok.Next->Next->TokenText == "provide" ||
Tok.Next->Next->TokenText == "require" ||
Tok.Next->Next->TokenText == "provide") &&
Tok.Next->Next->TokenText == "setTestOnly") &&
Tok.Next->Next->Next && Tok.Next->Next->Next->is(tok::l_paren);
}

Expand Down
2 changes: 2 additions & 0 deletions clang/unittests/Format/FormatTestJS.cpp
Expand Up @@ -252,6 +252,8 @@ TEST_F(FormatTestJS, GoogModules) {
getGoogleJSStyleWithColumns(40));
verifyFormat("var long = goog.require('this.is.really.absurdly.long');",
getGoogleJSStyleWithColumns(40));
verifyFormat("goog.setTestOnly('this.is.really.absurdly.long');",
getGoogleJSStyleWithColumns(40));

// These should be wrapped normally.
verifyFormat(
Expand Down

0 comments on commit b488a74

Please sign in to comment.