Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ lib/Format/ContinuationIndenter.cpp @@ -1059,6 +1059,8 @@ return 0; } +static llvm::Regex JSImportLocationCommentRegex("^//[ \n\t]*from[ \n\t]+//"); + unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current, LineState &State, bool DryRun) { @@ -1137,6 +1139,10 @@ if (!Style.ReflowComments || CommentPragmasRegex.match(Current.TokenText.substr(2))) return 0; + if (Style.Language == FormatStyle::LK_JavaScript && + JSImportLocationCommentRegex.match(Current.TokenText)) + return 0; + Token.reset(new BreakableLineComment(Current, State.Line->Level, StartColumn, /*InPPDirective=*/false, Encoding, Style)); Index: unittests/Format/FormatTestJS.cpp =================================================================== --- unittests/Format/FormatTestJS.cpp +++ unittests/Format/FormatTestJS.cpp @@ -1188,5 +1188,15 @@ verifyFormat("var x = 'foo';", LeaveQuotes); } + +TEST_F(FormatTestJS, LocationComment) { + verifyFormat("import {\n" + " x\n" + "} from\n" + " 'asd'; // from //some/really/long/path/here", + "import {x} from 'asd'; // from //some/really/long/path/here", + getGoogleJSStyleWithColumns(25)); +} + } // end namespace tooling } // end namespace clang