diff options
author | Owen Pan <owenpiano@gmail.com> | 2024-09-11 19:34:54 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-11 19:34:54 -0700 |
commit | 8168088f0a9015bc6d930e8bc1c639dee06ca82c (patch) | |
tree | 1482a91f2fc8e69a9ce8078da0868c513454051f /clang/lib/Format/ContinuationIndenter.cpp | |
parent | 335538c271c9c71ef3f2e23680265e7b77595be0 (diff) | |
download | llvm-8168088f0a9015bc6d930e8bc1c639dee06ca82c.zip llvm-8168088f0a9015bc6d930e8bc1c639dee06ca82c.tar.gz llvm-8168088f0a9015bc6d930e8bc1c639dee06ca82c.tar.bz2 |
[clang-format] Fix regressions in BAS_AlwaysBreak (#107506)
Fixes #107401.
Fixes #107574.
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 5843571..f29f879 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -815,7 +815,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, return Tok.is(tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous && Tok.Previous->is(tok::identifier); }; - const auto IsInTemplateString = [this](const FormatToken &Tok) { + auto IsInTemplateString = [this](const FormatToken &Tok) { if (!Style.isJavaScript()) return false; for (const auto *Prev = &Tok; Prev; Prev = Prev->Previous) { @@ -827,7 +827,10 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, return false; }; // Identifies simple (no expression) one-argument function calls. - const auto IsSimpleFunction = [&](const FormatToken &Tok) { + auto StartsSimpleOneArgList = [&](const FormatToken &TokAfterLParen) { + assert(TokAfterLParen.isNot(tok::comment) || TokAfterLParen.Next); + const auto &Tok = + TokAfterLParen.is(tok::comment) ? *TokAfterLParen.Next : TokAfterLParen; if (!Tok.FakeLParens.empty() && Tok.FakeLParens.back() > prec::Unknown) return false; // Nested calls that involve `new` expressions also look like simple @@ -836,6 +839,11 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, // - foo(::new Bar()) if (Tok.is(tok::kw_new) || Tok.startsSequence(tok::coloncolon, tok::kw_new)) return true; + if (Tok.is(TT_UnaryOperator) || + (Style.isJavaScript() && + Tok.isOneOf(tok::ellipsis, Keywords.kw_await))) { + return true; + } const auto *Previous = Tok.Previous; if (!Previous || (!Previous->isOneOf(TT_FunctionDeclarationLParen, TT_LambdaDefinitionLParen) && @@ -861,7 +869,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, // or // caaaaaaaaaaaaaaaaaaaaal( // new SomethingElseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee()); - !IsSimpleFunction(Current)) { + !StartsSimpleOneArgList(Current)) { CurrentState.NoLineBreak = true; } |