Skip to content

Commit

Permalink
clang-format: [JS] Make Closure module detection more narrow.
Browse files Browse the repository at this point in the history
Before:
  var MyLongClassName = goog.module.get('my.long.module.name.followedBy.MyLongClassName');

After:
  var MyLongClassName =
      goog.module.get('my.long.module.name.followedBy.MyLongClassName');

llvm-svn: 222888
  • Loading branch information
djasper-gh committed Nov 27, 2014
1 parent aa2b927 commit 53c38f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,8 @@ class AnnotatingParser {
Tok.TokenText == "goog" && Tok.Next && Tok.Next->is(tok::period) &&
Tok.Next->Next && (Tok.Next->Next->TokenText == "module" ||
Tok.Next->Next->TokenText == "require" ||
Tok.Next->Next->TokenText == "provide");
Tok.Next->Next->TokenText == "provide") &&
Tok.Next->Next->Next && Tok.Next->Next->Next->is(tok::l_paren);
}

void resetTokenMetadata(FormatToken *Token) {
Expand Down
5 changes: 5 additions & 0 deletions clang/unittests/Format/FormatTestJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ TEST_F(FormatTestJS, GoogModules) {
getGoogleJSStyleWithColumns(40));
verifyFormat("var long = goog.require('this.is.really.absurdly.long');",
getGoogleJSStyleWithColumns(40));

// These should be wrapped normally.
verifyFormat(
"var MyLongClassName =\n"
" goog.module.get('my.long.module.name.followedBy.MyLongClassName');");
}

TEST_F(FormatTestJS, FormatsFreestandingFunctions) {
Expand Down

0 comments on commit 53c38f4

Please sign in to comment.