summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/BreakableToken.cpp
diff options
context:
space:
mode:
authorMartin Probst <martin@probst.io>2018-08-03 13:58:33 +0000
committerMartin Probst <martin@probst.io>2018-08-03 13:58:33 +0000
commitf326b6b975409a2f29c7c852406b89c910e9d4c7 (patch)
tree30d8d78317e2c79e0459511302108f6c38b122be /clang/lib/Format/BreakableToken.cpp
parentad710b2cab2c6d62bb866a189389fe29acf04b08 (diff)
downloadbcm5719-llvm-f326b6b975409a2f29c7c852406b89c910e9d4c7.tar.gz
bcm5719-llvm-f326b6b975409a2f29c7c852406b89c910e9d4c7.zip
clang-format: [JS] don't break comments before any '{'
Summary: Previously, clang-format would avoid breaking before the first `{` found, but then happily break before subsequent '{'s on the line. This change fixes that by looking for the first location that has no opening curly, if any. This fixes the original commit by correcting the loop condition. This reverts commit 66dc646e09b795b943668179c33d09da71a3b6bc. Reviewers: krasimir Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D50249 llvm-svn: 338890
Diffstat (limited to 'clang/lib/Format/BreakableToken.cpp')
-rw-r--r--clang/lib/Format/BreakableToken.cpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp
index 300e3f802cb..e6ce01b520b 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -90,19 +90,21 @@ static BreakableToken::Split getCommentSplit(StringRef Text,
StringRef::size_type SpaceOffset = Text.find_last_of(Blanks, MaxSplitBytes);
- // Do not split before a number followed by a dot: this would be interpreted
- // as a numbered list, which would prevent re-flowing in subsequent passes.
static auto *const kNumberedListRegexp = new llvm::Regex("^[1-9][0-9]?\\.");
- if (SpaceOffset != StringRef::npos &&
- kNumberedListRegexp->match(Text.substr(SpaceOffset).ltrim(Blanks)))
- SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
- // In JavaScript, some @tags can be followed by {, and machinery that parses
- // these comments will fail to understand the comment if followed by a line
- // break. So avoid ever breaking before a {.
- if (Style.Language == FormatStyle::LK_JavaScript &&
- SpaceOffset != StringRef::npos && SpaceOffset + 1 < Text.size() &&
- Text[SpaceOffset + 1] == '{')
- SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
+ while (SpaceOffset != StringRef::npos) {
+ // Do not split before a number followed by a dot: this would be interpreted
+ // as a numbered list, which would prevent re-flowing in subsequent passes.
+ if (kNumberedListRegexp->match(Text.substr(SpaceOffset).ltrim(Blanks)))
+ SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
+ // In JavaScript, some @tags can be followed by {, and machinery that parses
+ // these comments will fail to understand the comment if followed by a line
+ // break. So avoid ever breaking before a {.
+ else if (Style.Language == FormatStyle::LK_JavaScript &&
+ SpaceOffset + 1 < Text.size() && Text[SpaceOffset + 1] == '{')
+ SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
+ else
+ break;
+ }
if (SpaceOffset == StringRef::npos ||
// Don't break at leading whitespace.
OpenPOWER on IntegriCloud