]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] do not insert semicolons after wrapped annotations.
authorMartin Probst <martin@probst.io>
Mon, 11 Apr 2016 07:35:57 +0000 (07:35 +0000)
committerMartin Probst <martin@probst.io>
Mon, 11 Apr 2016 07:35:57 +0000 (07:35 +0000)
Reviewers: djasper

Subscribers: klimek

Differential Revision: http://reviews.llvm.org/D18943

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265916 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestJS.cpp

index e36d7efffd26be5d709f7fd8e5ff882b7bc9dacc..b25abeae937dce4f5678c86e3df04a21cbec8e10 100644 (file)
@@ -715,6 +715,13 @@ void UnwrappedLineParser::readTokenWithJavaScriptASI() {
     return;
 
   bool PreviousMustBeValue = mustBeJSIdentOrValue(Keywords, Previous);
+  if (PreviousMustBeValue && Line && Line->Tokens.size() > 1) {
+    // If the token before the previous one is an '@', the previous token is an
+    // annotation and can precede another identifier/value.
+    const FormatToken *PrePrevious = std::next(Line->Tokens.rend(), 2)->Tok;
+    if (PrePrevious->is(tok::at))
+      return;
+  }
   if (Next->is(tok::exclaim) && PreviousMustBeValue)
     addUnwrappedLine();
   bool NextMustBeValue = mustBeJSIdentOrValue(Keywords, Next);
index 73f3afbaf0960238ed00739e0b3bcfe601324e09..912682449e39f0c9cf1730b9e93e6738d355d185 100644 (file)
@@ -686,6 +686,8 @@ TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) {
   verifyFormat("x instanceof String", "x\n"
                                       "instanceof\n"
                                       "String");
+  verifyFormat("function f(@Foo bar) {}", "function f(@Foo\n"
+                                          "  bar) {}");
 }
 
 TEST_F(FormatTestJS, ClosureStyleCasts) {