]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Fix bugs in parsing and aligning template strings.
authorDaniel Jasper <djasper@google.com>
Fri, 3 Feb 2017 14:32:38 +0000 (14:32 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 3 Feb 2017 14:32:38 +0000 (14:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@294009 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/ContinuationIndenter.cpp
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJS.cpp

index cd39c54e3538b77753e8e5541abf07f07fc218c3..173ca17c2a3f6724af69659d554b79631efa09fc 100644 (file)
@@ -837,8 +837,8 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
   }
 
   moveStatePastFakeLParens(State, Newline);
-  moveStatePastScopeOpener(State, Newline);
   moveStatePastScopeCloser(State);
+  moveStatePastScopeOpener(State, Newline);
   moveStatePastFakeRParens(State);
 
   if (Current.isStringLiteral() && State.StartOfStringLiteral == 0)
@@ -1060,7 +1060,7 @@ void ContinuationIndenter::moveStatePastScopeCloser(LineState &State) {
   // If we encounter a closing ), ], } or >, we can remove a level from our
   // stacks.
   if (State.Stack.size() > 1 &&
-      (Current.isOneOf(tok::r_paren, tok::r_square) ||
+      (Current.isOneOf(tok::r_paren, tok::r_square, TT_TemplateString) ||
        (Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
        State.NextToken->is(TT_TemplateCloser)))
     State.Stack.pop_back();
index 16115611a5da66109882b97155fa5522c9dcb5ef..a462fbc5426c03c5c2a3478de3c4f81e34ef4df6 100644 (file)
@@ -1445,7 +1445,9 @@ public:
 
       // At the end of the line or when an operator with higher precedence is
       // found, insert fake parenthesis and return.
-      if (!Current || (Current->closesScope() && Current->MatchingParen) ||
+      if (!Current ||
+          (Current->closesScope() &&
+           (Current->MatchingParen || Current->is(TT_TemplateString))) ||
           (CurrentPrecedence != -1 && CurrentPrecedence < Precedence) ||
           (CurrentPrecedence == prec::Conditional &&
            Precedence == prec::Assignment && Current->is(tok::colon))) {
index 9feda05226c04e5fbff8f70a5c2eab6b26b0a3f9..70bccb9f4936044b8755541fc99de2ceefa617d8 100644 (file)
@@ -1399,6 +1399,10 @@ TEST_F(FormatTestJS, TemplateStrings) {
                "         aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa`;",
                "var f = `aaaaaaaaaaaaa:${aaaaaaa.  aaaaa} aaaaaaaa\n"
                "         aaaaaaaaaaaaa:${  aaaaaaa. aaaaa} aaaaaaaa`;");
+  verifyFormat("var x = someFunction(`${})`)  //\n"
+               "            .oooooooooooooooooon();");
+  verifyFormat("var x = someFunction(`${aaaa}${aaaaa(  //\n"
+               "                                   aaaaa)})`);");
 }
 
 TEST_F(FormatTestJS, TemplateStringMultiLineExpression) {