From a8bebde7fa800c3d774093c5659a7a4c5e8b34af Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 3 Feb 2017 14:32:38 +0000 Subject: [PATCH] clang-format: [JS] Fix bugs in parsing and aligning template strings. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@294009 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/ContinuationIndenter.cpp | 4 ++-- lib/Format/TokenAnnotator.cpp | 4 +++- unittests/Format/FormatTestJS.cpp | 4 ++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index cd39c54e35..173ca17c2a 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -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(); diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 16115611a5..a462fbc542 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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))) { diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 9feda05226..70bccb9f49 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -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) { -- 2.40.0