[PATCH] D107267: [clang-format] don't break between function and function name in JS
Krasimir Georgiev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 3 02:19:36 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4f4f2783056f: [clang-format] don't break between function and function name in JS (authored by krasimir).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D107267/new/
https://reviews.llvm.org/D107267
Files:
clang/lib/Format/ContinuationIndenter.cpp
clang/unittests/Format/FormatTestJS.cpp
Index: clang/unittests/Format/FormatTestJS.cpp
===================================================================
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -692,6 +692,13 @@
" let x = 1;\n"
" console.log(x);\n"
"}\n");
+ EXPECT_EQ("a = function(x) {}\n"
+ "\n"
+ "function f(x) {}",
+ format("a = function(x) {}\n"
+ "\n"
+ "function f(x) {}",
+ getGoogleJSStyleWithColumns(20)));
}
TEST_F(FormatTestJS, GeneratorFunctions) {
Index: clang/lib/Format/ContinuationIndenter.cpp
===================================================================
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -495,7 +495,10 @@
if (((Current.is(TT_FunctionDeclarationName) &&
// Don't break before a C# function when no break after return type
(!Style.isCSharp() ||
- Style.AlwaysBreakAfterReturnType != FormatStyle::RTBS_None)) ||
+ Style.AlwaysBreakAfterReturnType != FormatStyle::RTBS_None) &&
+ // Don't always break between a JavaScript `function` and the function
+ // name.
+ Style.Language != FormatStyle::LK_JavaScript) ||
(Current.is(tok::kw_operator) && !Previous.is(tok::coloncolon))) &&
!Previous.is(tok::kw_template) && State.Stack.back().BreakBeforeParameter)
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107267.363659.patch
Type: text/x-patch
Size: 1486 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210803/d8965233/attachment.bin>
More information about the cfe-commits
mailing list