diff options
author | Daniel Jasper <djasper@google.com> | 2016-01-14 05:37:52 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2016-01-14 05:37:52 +0000 |
commit | 11a876533ee63969493b324d5143bca7adfb198f (patch) | |
tree | e7ded1e56bd5e7969f5c1a8e6ef1eb92da43416a | |
parent | c040ad5fde6fb43d256c36d2c1e7bbe0014f6758 (diff) | |
download | bcm5719-llvm-11a876533ee63969493b324d5143bca7adfb198f.tar.gz bcm5719-llvm-11a876533ee63969493b324d5143bca7adfb198f.zip |
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
];
llvm-svn: 257741
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 2 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 4 |
2 files changed, 6 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 8fbb43b7996..6d6df0cf401 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2268,6 +2268,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, 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)) diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 0e0f64a31ac..38fa5cd2b5b 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -591,6 +591,10 @@ TEST_F(FormatTestJS, AutomaticSemicolonInsertion) { verifyFormat("throw aaaaa;", getGoogleJSStyleWithColumns(10)); verifyFormat("aaaaaaaaa++;", getGoogleJSStyleWithColumns(10)); verifyFormat("aaaaaaaaa--;", getGoogleJSStyleWithColumns(10)); + verifyFormat("return [\n" + " aaa\n" + "];", + getGoogleJSStyleWithColumns(12)); } TEST_F(FormatTestJS, ClosureStyleCasts) { |