r257741 - clang-format: [JS] Fix incorrect line break leading to semicolon insertion.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 13 21:37:52 PST 2016
Author: djasper
Date: Wed Jan 13 23:37:52 2016
New Revision: 257741
URL: http://llvm.org/viewvc/llvm-project?rev=257741&view=rev
Log:
clang-format: [JS] Fix incorrect line break leading to semicolon insertion.
clang-format only works for JavaScript code, if all the semicolons are
present anyway, so this linebreak can never be desired.
Before (with appropriate statement lengths or column limit):
return
[ aaa ];
After:
return [
aaaa
];
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=257741&r1=257740&r2=257741&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Jan 13 23:37:52 2016
@@ -2268,6 +2268,8 @@ bool TokenAnnotator::canBreakBefore(cons
Keywords.kw_implements))
return true;
} else if (Style.Language == FormatStyle::LK_JavaScript) {
+ if (Left.is(tok::kw_return))
+ return false; // Otherwise a semicolon is inserted.
if (Left.is(TT_JsFatArrow) && Right.is(tok::l_brace))
return false;
if (Left.is(TT_JsTypeColon))
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=257741&r1=257740&r2=257741&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Jan 13 23:37:52 2016
@@ -591,6 +591,10 @@ TEST_F(FormatTestJS, AutomaticSemicolonI
verifyFormat("throw aaaaa;", getGoogleJSStyleWithColumns(10));
verifyFormat("aaaaaaaaa++;", getGoogleJSStyleWithColumns(10));
verifyFormat("aaaaaaaaa--;", getGoogleJSStyleWithColumns(10));
+ verifyFormat("return [\n"
+ " aaa\n"
+ "];",
+ getGoogleJSStyleWithColumns(12));
}
TEST_F(FormatTestJS, ClosureStyleCasts) {
More information about the cfe-commits
mailing list