Skip to content

Commit 3062a35

Browse files
sstwcwZijunZhaoCCK
authored andcommitted
[clang-format] More on unbreakable strings in TypeScript (llvm#66321)
Now. string literals in lines beginning with `export type` will not be broken. The case was missed in 5db201f. I don't know TypeScript. And merging GitHub pull requests seems to be a little too easy. So it got committed before the reviewers had a chance to find edge cases.
1 parent 24e5cf4 commit 3062a35

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,8 +2242,10 @@ ContinuationIndenter::createBreakableToken(const FormatToken &Current,
22422242
return nullptr;
22432243

22442244
// Strings in TypeScript types and dictionary keys can not be broken.
2245-
if (Style.isJavaScript() && (Current.is(TT_SelectorName) ||
2246-
State.Line->startsWith(Keywords.kw_type))) {
2245+
if (Style.isJavaScript() &&
2246+
(Current.is(TT_SelectorName) ||
2247+
State.Line->startsWith(Keywords.kw_type) ||
2248+
State.Line->startsWith(tok::kw_export, Keywords.kw_type))) {
22472249
return nullptr;
22482250
}
22492251

clang/unittests/Format/FormatTestJS.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,9 @@ TEST_F(FormatTestJS, StringLiteralConcatenation) {
16041604
verifyFormat("/* type */ type x =\n"
16051605
" 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';",
16061606
getGoogleJSStyleWithColumns(20));
1607+
verifyFormat("export type x =\n"
1608+
" 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';",
1609+
getGoogleJSStyleWithColumns(20));
16071610
// Dictionary keys can't be broken. Values can be broken.
16081611
verifyFormat("var w = {\n"
16091612
" 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx':\n"

0 commit comments

Comments
 (0)