[clang] cb479e7 - [clang-format] More on unbreakable strings in TypeScript (#66321)

via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 14 05:43:08 PDT 2023


Author: sstwcw
Date: 2023-09-14T12:41:21Z
New Revision: cb479e7d7d6e70748ebeef3b930d7911dc9e4276

URL: https://github.com/llvm/llvm-project/commit/cb479e7d7d6e70748ebeef3b930d7911dc9e4276
DIFF: https://github.com/llvm/llvm-project/commit/cb479e7d7d6e70748ebeef3b930d7911dc9e4276.diff

LOG: [clang-format] More on unbreakable strings in TypeScript (#66321)

Now. string literals in lines beginning with `export type` will not be
broken.

The case was missed in 5db201fb75e6.  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.

Added: 
    

Modified: 
    clang/lib/Format/ContinuationIndenter.cpp
    clang/unittests/Format/FormatTestJS.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 75ab08de42ea0e8..6673b5c703b835f 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -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;
     }
 

diff  --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index 309326569143df6..51543d0a54d8561 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -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"


        


More information about the cfe-commits mailing list