llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-format
            
<details>
<summary>Changes</summary>
See the discussion
[here](https://github.com/llvm/llvm-project/pull/66168#issuecomment-1719038797).

The functionality is not mature enough.
--
Full diff: https://github.com/llvm/llvm-project/pull/66372.diff

4 Files Affected:

- (modified) clang/docs/ClangFormatStyleOptions.rst (+5-5) 
- (modified) clang/include/clang/Format/Format.h (+5-5) 
- (modified) clang/lib/Format/ContinuationIndenter.cpp (+4-9) 
- (modified) clang/unittests/Format/FormatTestJS.cpp (+2-112) 


<pre>
diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index d5d9faa5c78cffb..4ab0b3a207270dc 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2783,17 +2783,17 @@ the configuration (without a prefix: ``Auto``).
      const char* x =
          
&amp;quot;veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString&amp;quot;;
 
-  In C#, Java, and JavaScript:
+  In C# and Java:
 
   .. code-block:: c++
 
      true:
-     var x = &amp;quot;veryVeryVeryVeryVeryVe&amp;quot; +
-             &amp;quot;ryVeryVeryVeryVeryVery&amp;quot; +
-             &amp;quot;VeryLongString&amp;quot;;
+     string x = &amp;quot;veryVeryVeryVeryVeryVe&amp;quot; +
+                &amp;quot;ryVeryVeryVeryVeryVery&amp;quot; +
+                &amp;quot;VeryLongString&amp;quot;;
 
      false:
-     var x =
+     string x =
          
&amp;quot;veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString&amp;quot;;
 
   C# and JavaScript interpolated strings are not broken.
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index c7bd356b7faeded..3bf70838d059086 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2062,15 +2062,15 @@ struct FormatStyle {
   ///        
&amp;quot;veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString&amp;quot;;
   /// \endcode
   ///
-  /// In C#, Java, and JavaScript:
+  /// In C# and Java:
   /// \code
   ///    true:
-  ///    var x = &amp;quot;veryVeryVeryVeryVeryVe&amp;quot; +
-  ///            &amp;quot;ryVeryVeryVeryVeryVery&amp;quot; +
-  ///            &amp;quot;VeryLongString&amp;quot;;
+  ///    string x = &amp;quot;veryVeryVeryVeryVeryVe&amp;quot; +
+  ///               &amp;quot;ryVeryVeryVeryVeryVery&amp;quot; +
+  ///               &amp;quot;VeryLongString&amp;quot;;
   ///
   ///    false:
-  ///    var x =
+  ///    string x =
   ///        
&amp;quot;veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString&amp;quot;;
   /// \endcode
   ///
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 6673b5c703b835f..15b9ad41a37af59 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -2237,15 +2237,10 @@ ContinuationIndenter::createBreakableToken(const 
FormatToken &amp;amp;Current,
                                            LineState &amp;amp;State, bool 
AllowBreak) {
   unsigned StartColumn = State.Column - Current.ColumnWidth;
   if (Current.isStringLiteral()) {
-    // Strings in JSON can not be broken.
-    if (Style.isJson() || !Style.BreakStringLiterals || !AllowBreak)
-      return nullptr;
-
-    // Strings in TypeScript types and dictionary keys can not be broken.
-    if (Style.isJavaScript() &amp;amp;&amp;amp;
-        (Current.is(TT_SelectorName) ||
-         State.Line-&amp;gt;startsWith(Keywords.kw_type) ||
-         State.Line-&amp;gt;startsWith(tok::kw_export, Keywords.kw_type))) {
+    // Strings in JSON can not be broken. Breaking strings in JavaScript is
+    // disabled for now.
+    if (Style.isJson() || Style.isJavaScript() || !Style.BreakStringLiterals ||
+        !AllowBreak) {
       return nullptr;
     }
 
diff --git a/clang/unittests/Format/FormatTestJS.cpp 
b/clang/unittests/Format/FormatTestJS.cpp
index 51543d0a54d8561..23b010dbc982684 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -1506,121 +1506,11 @@ TEST_F(FormatTestJS, StringLiteralConcatenation) {
   verifyFormat(&amp;quot;var literal = &amp;#x27;hello &amp;#x27; +\n&amp;quot;
                &amp;quot;    &amp;#x27;world&amp;#x27;;&amp;quot;);
 
-  // Long strings should be broken.
+  // String breaking is disabled for now.
   verifyFormat(&amp;quot;var literal =\n&amp;quot;
-               &amp;quot;    &amp;#x27;xxxxxxxx &amp;#x27; +\n&amp;quot;
-               &amp;quot;    &amp;#x27;xxxxxxxx&amp;#x27;;&amp;quot;,
+               &amp;quot;    &amp;#x27;xxxxxxxx xxxxxxxx&amp;#x27;;&amp;quot;,
                &amp;quot;var literal = &amp;#x27;xxxxxxxx 
xxxxxxxx&amp;#x27;;&amp;quot;,
                getGoogleJSStyleWithColumns(17));
-  verifyFormat(&amp;quot;var literal =\n&amp;quot;
-               &amp;quot;    &amp;#x27;xxxxxxxx &amp;#x27; +\n&amp;quot;
-               &amp;quot;    &amp;#x27;xxxxxxxx&amp;#x27;;&amp;quot;,
-               &amp;quot;var literal = &amp;#x27;xxxxxxxx 
xxxxxxxx&amp;#x27;;&amp;quot;,
-               getGoogleJSStyleWithColumns(18));
-  verifyFormat(&amp;quot;var literal =\n&amp;quot;
-               &amp;quot;    &amp;#x27;xxxxxxxx&amp;#x27; +\n&amp;quot;
-               &amp;quot;    &amp;#x27; xxxxxxxx&amp;#x27;;&amp;quot;,
-               &amp;quot;var literal = &amp;#x27;xxxxxxxx 
xxxxxxxx&amp;#x27;;&amp;quot;,
-               getGoogleJSStyleWithColumns(16));
-  // The quotes should be correct.
-  for (char OriginalQuote : {&amp;#x27;\&amp;#x27;&amp;#x27;, 
&amp;#x27;&amp;quot;&amp;#x27;}) {
-    auto VerifyQuotes = [=](FormatStyle::JavaScriptQuoteStyle StyleQuote,
-                            char TargetQuote) {
-      auto Style = getGoogleJSStyleWithColumns(17);
-      Style.JavaScriptQuotes = StyleQuote;
-      std::string Target{&amp;quot;var literal =\n&amp;quot;
-                         &amp;quot;    \&amp;quot;xxxxxxxx \&amp;quot; 
+\n&amp;quot;
-                         &amp;quot;    
\&amp;quot;xxxxxxxx\&amp;quot;;&amp;quot;};
-      std::string Original{&amp;quot;var literal = \&amp;quot;xxxxxxxx 
xxxxxxxx\&amp;quot;;&amp;quot;};
-      std::replace(Target.begin(), Target.end(), 
&amp;#x27;&amp;quot;&amp;#x27;, TargetQuote);
-      std::replace(Original.begin(), Original.end(), 
&amp;#x27;&amp;quot;&amp;#x27;, OriginalQuote);
-      verifyFormat(Target, Original, Style);
-    };
-    VerifyQuotes(FormatStyle::JSQS_Leave, OriginalQuote);
-    VerifyQuotes(FormatStyle::JSQS_Single, &amp;#x27;\&amp;#x27;&amp;#x27;);
-    VerifyQuotes(FormatStyle::JSQS_Double, &amp;#x27;&amp;quot;&amp;#x27;);
-  }
-  // Parentheses should be added when necessary.
-  verifyFormat(&amp;quot;var literal =\n&amp;quot;
-               &amp;quot;    (&amp;#x27;xxxxxxxx &amp;#x27; +\n&amp;quot;
-               &amp;quot;     &amp;#x27;xxxxxx&amp;#x27;)[0];&amp;quot;,
-               &amp;quot;var literal = &amp;#x27;xxxxxxxx 
xxxxxx&amp;#x27;[0];&amp;quot;,
-               getGoogleJSStyleWithColumns(18));
-  auto Style = getGoogleJSStyleWithColumns(20);
-  Style.SpacesInParens = FormatStyle::SIPO_Custom;
-  Style.SpacesInParensOptions.Other = true;
-  verifyFormat(&amp;quot;var literal =\n&amp;quot;
-               &amp;quot;    ( &amp;#x27;xxxxxxxx &amp;#x27; +\n&amp;quot;
-               &amp;quot;      &amp;#x27;xxxxxx&amp;#x27; )[0];&amp;quot;,
-               &amp;quot;var literal = &amp;#x27;xxxxxxxx 
xxxxxx&amp;#x27;[0];&amp;quot;, Style);
-  // FIXME: When the part before the string literal is shorter than the
-  // continuation indentation, and the option AlignAfterOpenBracket is set to
-  // AlwaysBreak which is the default for the Google style, the unbroken string
-  // does not get to a new line while the broken string does due to the added
-  // parentheses. The formatter does not do it in one pass.
-  EXPECT_EQ(
-      &amp;quot;x = (&amp;#x27;xxxxxxxx &amp;#x27; +\n&amp;quot;
-      &amp;quot;     &amp;#x27;xxxxxx&amp;#x27;)[0];&amp;quot;,
-      format(&amp;quot;x = &amp;#x27;xxxxxxxx xxxxxx&amp;#x27;[0];&amp;quot;, 
getGoogleJSStyleWithColumns(18)));
-  verifyFormat(&amp;quot;x =\n&amp;quot;
-               &amp;quot;    (&amp;#x27;xxxxxxxx &amp;#x27; +\n&amp;quot;
-               &amp;quot;     &amp;#x27;xxxxxx&amp;#x27;)[0];&amp;quot;,
-               getGoogleJSStyleWithColumns(18));
-  // Breaking of template strings and regular expressions is not implemented.
-  verifyFormat(&amp;quot;var literal =\n&amp;quot;
-               &amp;quot;    `xxxxxxxx xxxxxxxx`;&amp;quot;,
-               getGoogleJSStyleWithColumns(18));
-  verifyFormat(&amp;quot;var literal =\n&amp;quot;
-               &amp;quot;    /xxxxxxxx xxxxxxxx/;&amp;quot;,
-               getGoogleJSStyleWithColumns(18));
-  // There can be breaks in the code inside a template string.
-  verifyFormat(&amp;quot;var literal = `xxxxxx ${\n&amp;quot;
-               &amp;quot;    xxxxxxxxxx} xxxxxx`;&amp;quot;,
-               &amp;quot;var literal = `xxxxxx ${xxxxxxxxxx} 
xxxxxx`;&amp;quot;,
-               getGoogleJSStyleWithColumns(14));
-  verifyFormat(&amp;quot;var literal = `xxxxxx ${\n&amp;quot;
-               &amp;quot;    xxxxxxxxxx} xxxxxx`;&amp;quot;,
-               &amp;quot;var literal = `xxxxxx ${xxxxxxxxxx} 
xxxxxx`;&amp;quot;,
-               getGoogleJSStyleWithColumns(15));
-  // Identifiers inside the code inside a template string should not be broken
-  // even if the column limit is exceeded.  This following behavior is not
-  // optimal.  The part after the closing brace which exceeds the column limit
-  // can be put on a new line.  Change this test when it is implemented.
-  verifyFormat(&amp;quot;var literal = `xxxxxx ${\n&amp;quot;
-               &amp;quot;    xxxxxxxxxxxxxxxxxxxxxx} xxxxxx`;&amp;quot;,
-               &amp;quot;var literal = `xxxxxx ${xxxxxxxxxxxxxxxxxxxxxx} 
xxxxxx`;&amp;quot;,
-               getGoogleJSStyleWithColumns(14));
-  verifyFormat(&amp;quot;var literal = `xxxxxx ${\n&amp;quot;
-               &amp;quot;    xxxxxxxxxxxxxxxxxxxxxx +\n&amp;quot;
-               &amp;quot;    xxxxxxxxxxxxxxxxxxxxxx} xxxxxx`;&amp;quot;,
-               &amp;quot;var literal = `xxxxxx ${xxxxxxxxxxxxxxxxxxxxxx + 
&amp;quot;
-               &amp;quot;xxxxxxxxxxxxxxxxxxxxxx} xxxxxx`;&amp;quot;,
-               getGoogleJSStyleWithColumns(14));
-
-  // Strings in a TypeScript type declaration can&amp;#x27;t be broken.
-  verifyFormat(&amp;quot;type x =\n&amp;quot;
-               &amp;quot;    
&amp;#x27;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&amp;#x27;;&amp;quot;,
-               getGoogleJSStyleWithColumns(20));
-  verifyFormat(&amp;quot;/* type */ type x =\n&amp;quot;
-               &amp;quot;    
&amp;#x27;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&amp;#x27;;&amp;quot;,
-               getGoogleJSStyleWithColumns(20));
-  verifyFormat(&amp;quot;export type x =\n&amp;quot;
-               &amp;quot;    
&amp;#x27;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&amp;#x27;;&amp;quot;,
-               getGoogleJSStyleWithColumns(20));
-  // Dictionary keys can&amp;#x27;t be broken. Values can be broken.
-  verifyFormat(&amp;quot;var w = {\n&amp;quot;
-               &amp;quot;  
&amp;#x27;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&amp;#x27;:\n&amp;quot;
-               &amp;quot;      &amp;#x27;xxxxxxxxxx&amp;#x27; +\n&amp;quot;
-               &amp;quot;      &amp;#x27;xxxxxxxxxx&amp;#x27; +\n&amp;quot;
-               &amp;quot;      &amp;#x27;xxxxxxxxxx&amp;#x27; +\n&amp;quot;
-               &amp;quot;      &amp;#x27;xxxxxxxxxx&amp;#x27; +\n&amp;quot;
-               &amp;quot;      &amp;#x27;xxx&amp;#x27;,\n&amp;quot;
-               &amp;quot;};&amp;quot;,
-               &amp;quot;var w = {\n&amp;quot;
-               &amp;quot;  
&amp;#x27;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&amp;#x27;:\n&amp;quot;
-               &amp;quot;      
&amp;#x27;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&amp;#x27;,\n&amp;quot;
-               &amp;quot;};&amp;quot;,
-               getGoogleJSStyleWithColumns(20));
 }
 
 TEST_F(FormatTestJS, RegexLiteralClassification) {
</pre>
</details>


https://github.com/llvm/llvm-project/pull/66372
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to