r294009 - clang-format: [JS] Fix bugs in parsing and aligning template strings.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 3 06:32:39 PST 2017
Author: djasper
Date: Fri Feb 3 08:32:38 2017
New Revision: 294009
URL: http://llvm.org/viewvc/llvm-project?rev=294009&view=rev
Log:
clang-format: [JS] Fix bugs in parsing and aligning template strings.
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=294009&r1=294008&r2=294009&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Feb 3 08:32:38 2017
@@ -837,8 +837,8 @@ unsigned ContinuationIndenter::moveState
}
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::moveStatePast
// 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();
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=294009&r1=294008&r2=294009&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Feb 3 08:32:38 2017
@@ -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))) {
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=294009&r1=294008&r2=294009&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Fri Feb 3 08:32:38 2017
@@ -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) {
More information about the cfe-commits
mailing list