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
This commit is contained in:
Daniel Jasper 2016-01-14 05:37:52 +00:00
parent c040ad5fde
commit 11a876533e
2 changed files with 6 additions and 0 deletions

View File

@ -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))

View File

@ -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) {