From 0be4d0a05153fee4e8a00541491983c61781fb53 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 14 Jan 2016 05:37:52 +0000 Subject: [PATCH] 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 ]; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257741 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 2 ++ unittests/Format/FormatTestJS.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 8fbb43b799..6d6df0cf40 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/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/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 0e0f64a31a..38fa5cd2b5 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/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) { -- 2.40.0