https://github.com/sstwcw updated https://github.com/llvm/llvm-project/pull/66321:
>From cb479e7d7d6e70748ebeef3b930d7911dc9e4276 Mon Sep 17 00:00:00 2001 From: sstwcw <su3e8a96kzl...@posteo.net> Date: Thu, 14 Sep 2023 03:26:10 +0000 Subject: [PATCH] [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. --- clang/lib/Format/ContinuationIndenter.cpp | 6 ++++-- clang/unittests/Format/FormatTestJS.cpp | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) 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" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits