Skip to content

Commit

Permalink
[clang-format] More on unbreakable strings in TypeScript (llvm#66321)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sstwcw authored and kstoimenov committed Sep 14, 2023
1 parent 0aef07f commit 3e175cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2242,8 +2242,10 @@ ContinuationIndenter::createBreakableToken(const FormatToken &Current,
return nullptr;

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

Expand Down
3 changes: 3 additions & 0 deletions clang/unittests/Format/FormatTestJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,9 @@ TEST_F(FormatTestJS, StringLiteralConcatenation) {
verifyFormat("/* type */ type x =\n"
" 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';",
getGoogleJSStyleWithColumns(20));
verifyFormat("export type x =\n"
" 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';",
getGoogleJSStyleWithColumns(20));
// Dictionary keys can't be broken. Values can be broken.
verifyFormat("var w = {\n"
" 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx':\n"
Expand Down

0 comments on commit 3e175cc

Please sign in to comment.