diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp index c3853687c228f..4975c89164a4d 100644 --- a/clang/lib/Format/BreakableToken.cpp +++ b/clang/lib/Format/BreakableToken.cpp @@ -124,9 +124,10 @@ getCommentSplit(StringRef Text, unsigned ContentStartColumn, continue; } - // Avoid ever breaking before a { in JavaScript. + // Avoid ever breaking before a @tag or a { in JavaScript. if (Style.Language == FormatStyle::LK_JavaScript && - SpaceOffset + 1 < Text.size() && Text[SpaceOffset + 1] == '{') { + SpaceOffset + 1 < Text.size() && + (Text[SpaceOffset + 1] == '{' || Text[SpaceOffset + 1] == '@')) { SpaceOffset = Text.find_last_of(Blanks, SpaceOffset); continue; } diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 84d76c67764ad..8963c9f19024d 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -187,22 +187,11 @@ TEST_F(FormatTestJS, JSDocComments) { format("/** @returns j */", getGoogleJSStyleWithColumns(20))); // Break a single line long jsdoc comment pragma. - EXPECT_EQ("/**\n" - " * @returns {string} jsdoc line 12\n" - " */", - format("/** @returns {string} jsdoc line 12 */", - getGoogleJSStyleWithColumns(20))); EXPECT_EQ("/**\n" " * @returns {string}\n" " * jsdoc line 12\n" " */", format("/** @returns {string} jsdoc line 12 */", - getGoogleJSStyleWithColumns(25))); - - EXPECT_EQ("/**\n" - " * @returns {string} jsdoc line 12\n" - " */", - format("/** @returns {string} jsdoc line 12 */", getGoogleJSStyleWithColumns(20))); // FIXME: this overcounts the */ as a continuation of the 12 when breaking. @@ -2194,6 +2183,16 @@ TEST_F(FormatTestJS, JSDocAnnotations) { " */", getGoogleJSStyleWithColumns(ColumnLimit)); } + // don't break before @tags + verifyFormat("/**\n" + " * This\n" + " * tag @param\n" + " * stays.\n" + " */", + "/**\n" + " * This tag @param stays.\n" + " */", + getGoogleJSStyleWithColumns(13)); verifyFormat("/**\n" " * @see http://very/very/long/url/is/long\n" " */",