Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -1006,6 +1006,23 @@ readToken(); FormatToken *Next = FormatTok; + if (Previous->isOneOf(tok::kw_return, tok::kw_break, tok::kw_continue, + Keywords.kw_yield)) { + if (Next->isOneOf(Keywords.kw_let, tok::kw_const, Keywords.kw_var)) + return addUnwrappedLine(); + // Don't go past the end of the file. + if (!eof()) { + if (Next->is(tok::identifier)) { + // Peek the next token. + unsigned StoredPosition = Tokens->getPosition(); + FormatToken *NextNext = Tokens->getNextToken(); + Tokens->setPosition(StoredPosition); + if (NextNext && NextNext->is(tok::equal)) + return addUnwrappedLine(); + } + } + } + bool IsOnSameLine = CommentsBeforeNextToken.empty() ? Next->NewlinesBefore == 0 Index: clang/unittests/Format/FormatTestJS.cpp =================================================================== --- clang/unittests/Format/FormatTestJS.cpp +++ clang/unittests/Format/FormatTestJS.cpp @@ -2604,5 +2604,41 @@ "}\n"); } +TEST_F(FormatTestJS, ASIAfterReturn) { + verifyFormat("if (true) return\n" + "const v = 42"); + verifyFormat("if (true) return\n" + "let v = 42"); + verifyFormat("if (true) return\n" + "var v = 42"); + verifyFormat("if (true) break\n" + "let v = 42"); + verifyFormat("if (true) break\n" + "const v = 42"); + verifyFormat("if (true) break\n" + "v = 42"); + verifyFormat("if (true) continue\n" + "let v = 42"); + verifyFormat("if (true) continue\n" + "var v = 42"); + verifyFormat("if (true) continue\n" + "const v = 42"); + verifyFormat("if (true) yield\n" + "let v = 42"); + verifyFormat("if (true) yield\n" + "var v = 42"); + verifyFormat("if (true) yield\n" + "const v = 42"); + + verifyFormat("if (true) break\n" + "var v = 42"); + verifyFormat("if (true) return\n" + "v = 42"); + verifyFormat("if (true) continue\n" + "v = 42"); + verifyFormat("if (true) yield\n" + "v = 42"); +} + } // namespace format } // end namespace clang