Skip to content

Commit 53c38f4

Browse files
committed
clang-format: [JS] Make Closure module detection more narrow.
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
1 parent aa2b927 commit 53c38f4

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,8 @@ class AnnotatingParser {
661661
Tok.TokenText == "goog" && Tok.Next && Tok.Next->is(tok::period) &&
662662
Tok.Next->Next && (Tok.Next->Next->TokenText == "module" ||
663663
Tok.Next->Next->TokenText == "require" ||
664-
Tok.Next->Next->TokenText == "provide");
664+
Tok.Next->Next->TokenText == "provide") &&
665+
Tok.Next->Next->Next && Tok.Next->Next->Next->is(tok::l_paren);
665666
}
666667

667668
void resetTokenMetadata(FormatToken *Token) {

clang/unittests/Format/FormatTestJS.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ TEST_F(FormatTestJS, GoogModules) {
167167
getGoogleJSStyleWithColumns(40));
168168
verifyFormat("var long = goog.require('this.is.really.absurdly.long');",
169169
getGoogleJSStyleWithColumns(40));
170+
171+
// These should be wrapped normally.
172+
verifyFormat(
173+
"var MyLongClassName =\n"
174+
" goog.module.get('my.long.module.name.followedBy.MyLongClassName');");
170175
}
171176

172177
TEST_F(FormatTestJS, FormatsFreestandingFunctions) {

0 commit comments

Comments
 (0)