[PATCH] D146247: [clang-format] Support TypeScript satisfies operator

2023-03-17 Thread Taymon A. Beal via Phabricator via cfe-commits
taymonbeal added a comment.

I don't have commit access; can someone who does commit this?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146247/new/

https://reviews.llvm.org/D146247

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146247: [clang-format] Support TypeScript satisfies operator

2023-03-17 Thread Taymon A. Beal via Phabricator via cfe-commits
taymonbeal updated this revision to Diff 506153.
taymonbeal added a comment.

Add release notes and unit test in TokenAnnotatorTest.cpp


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146247/new/

https://reviews.llvm.org/D146247

Files:
  clang/docs/ReleaseNotes.rst
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1434,6 +1434,20 @@
   EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsTypeScriptSatisfiesOperator) {
+  auto Tokens = annotate("let x = foo satisfies Type;",
+ getGoogleStyle(FormatStyle::LK_JavaScript));
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[1], tok::identifier, TT_StartOfName);
+  EXPECT_TOKEN(Tokens[2], tok::equal, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_StartOfName);
+  EXPECT_TOKEN(Tokens[5], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[6], tok::semi, TT_Unknown);
+  EXPECT_TOKEN(Tokens[7], tok::eof, TT_Unknown);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -326,6 +326,7 @@
   Compared to ``NextLine`` style, ``NextLineOnly`` style will not try to
   put the initializers on the current line first, instead, it will try to
   put the initializers on the next line only.
+- Add support for the ``satisfies`` operator introduced in TypeScript 4.9.
 
 libclang
 


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1434,6 +1434,20 @@
   EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsTypeScriptSatisfiesOperator) {
+  auto Tokens = annotate("let x = foo satisfies Type;",
+ getGoogleStyle(FormatStyle::LK_JavaScript));
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[1], tok::identifier, TT_StartOfName);
+  EXPECT_TOKEN(Tokens[2], tok::equal, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_StartOfName);
+  EXPECT_TOKEN(Tokens[5], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[6], tok::semi, TT_Unknown);
+  EXPECT_TOKEN(Tokens[7], tok::eof, TT_Unknown);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -326,6 +326,7 @@
   Compared to ``NextLine`` style, ``NextLineOnly`` style will not try to
   put the initializers on the current line first, instead, it will try to
   put the initializers on the next line only.
+- Add support for the ``satisfies`` operator introduced in TypeScript 4.9.
 
 libclang
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146247: [clang-format] Support TypeScript satisfies operator

2023-03-16 Thread Taymon A. Beal via Phabricator via cfe-commits
taymonbeal created this revision.
taymonbeal added reviewers: MyDeveloperDay, owenpan.
Herald added a project: All.
taymonbeal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The satisfies operator was added in TypeScript 4.9.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146247

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestJS.cpp

Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2182,6 +2182,21 @@
getGoogleJSStyleWithColumns(40));
 }
 
+TEST_F(FormatTestJS, SatisfiesSyntax) {
+  verifyFormat("let x = foo satisfies Type;");
+  verifyFormat("let x = (a + b) satisfies\n"
+   "LongTypeIsLong;",
+   getGoogleJSStyleWithColumns(30));
+  verifyFormat("let x = [{x: 1} satisfies Type];");
+  verifyFormat("x = x satisfies [A, B];");
+  verifyFormat("x = x satisfies {a: string};");
+  verifyFormat("x = x satisfies (string);");
+  verifyFormat("x = x! satisfies (string);");
+  verifyFormat("let x = something.someFunction() satisfies\n"
+   "LongTypeIsLong;",
+   getGoogleJSStyleWithColumns(50));
+}
+
 TEST_F(FormatTestJS, TypeArguments) {
   verifyFormat("class X {}");
   verifyFormat("new X();");
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -556,10 +556,11 @@
   // must also be part of it.
   ProbablyBracedList = LBraceStack.back()->is(TT_BracedListLBrace);
 
-  ProbablyBracedList = ProbablyBracedList ||
+  ProbablyBracedList =
+  ProbablyBracedList ||
(Style.isJavaScript() &&
-NextTok->isOneOf(Keywords.kw_of, Keywords.kw_in,
- Keywords.kw_as));
+   NextTok->isOneOf(Keywords.kw_of, Keywords.kw_in, Keywords.kw_as,
+Keywords.kw_satisfies));
   ProbablyBracedList = ProbablyBracedList ||
(Style.isCpp() && NextTok->is(tok::l_paren));
 
@@ -1213,7 +1214,8 @@
   Keywords.kw_let, Keywords.kw_var, tok::kw_const,
   Keywords.kw_abstract, Keywords.kw_extends, Keywords.kw_implements,
   Keywords.kw_instanceof, Keywords.kw_interface,
-  Keywords.kw_override, Keywords.kw_throws, Keywords.kw_from));
+  Keywords.kw_override, Keywords.kw_satisfies, Keywords.kw_throws,
+  Keywords.kw_from));
 }
 
 static bool mustBeJSIdentOrValue(const AdditionalKeywords ,
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1882,7 +1882,8 @@
 }
   }
   if (Current.Next &&
-  Current.Next->isOneOf(TT_BinaryOperator, Keywords.kw_as)) {
+  Current.Next->isOneOf(TT_BinaryOperator, Keywords.kw_as,
+Keywords.kw_satisfies)) {
 Current.setType(TT_NonNullAssertion);
 return;
   }
@@ -2074,7 +2075,7 @@
   return false;
 
 if (Tok.Previous->isOneOf(TT_LeadingJavaAnnotation, Keywords.kw_instanceof,
-  Keywords.kw_as)) {
+  Keywords.kw_as, Keywords.kw_satisfies)) {
   return false;
 }
 if (Style.isJavaScript() && Tok.Previous->is(Keywords.kw_in))
@@ -2725,7 +2726,8 @@
 return prec::Relational;
   }
   if (Style.isJavaScript() &&
-  Current->isOneOf(Keywords.kw_in, Keywords.kw_as)) {
+  Current->isOneOf(Keywords.kw_in, Keywords.kw_as,
+   Keywords.kw_satisfies)) {
 return prec::Relational;
   }
   if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))
@@ -4268,11 +4270,12 @@
 (!Left.Previous || !Left.Previous->is(tok::period))) {
   return true;
 }
-if (Left.isOneOf(tok::kw_for, Keywords.kw_as) && Left.Previous &&
-Left.Previous->is(tok::period) && Right.is(tok::l_paren)) {
+if (Left.isOneOf(tok::kw_for, Keywords.kw_as, Keywords.kw_satisfies) &&
+Left.Previous && Left.Previous->is(tok::period) &&
+Right.is(tok::l_paren)) {
   return false;
 }
-if (Left.is(Keywords.kw_as) &&
+if (Left.isOneOf(Keywords.kw_as, Keywords.kw_satisfies) &&
 Right.isOneOf(tok::l_square, tok::l_brace, tok::l_paren)) {
   return true;
 }
@@ -4303,8 +4306,8 @@
 if (Right.is(TT_NonNullAssertion))
   return false;
 if (Left.is(TT_NonNullAssertion) 

[PATCH] D144317: [clang-format] Fix handling of TypeScript tuples with optional last member

2023-02-20 Thread Taymon A. Beal via Phabricator via cfe-commits
taymonbeal added a comment.

Can anyone please commit this? I don't have commit access. Thanks.

Name: Taymon A. Beal
Email: tay...@google.com


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144317/new/

https://reviews.llvm.org/D144317

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144317: [clang-format] Fix handling of TypeScript tuples with optional last member

2023-02-19 Thread Taymon A. Beal via Phabricator via cfe-commits
taymonbeal updated this revision to Diff 498692.
taymonbeal added a comment.

Merge unit test into existing test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144317/new/

https://reviews.llvm.org/D144317

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestJS.cpp


Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2221,6 +2221,7 @@
"  aaa?: boolean,\n"
"  aa?: List\n"
"}) {}");
+  verifyFormat("type X = [y?];");
 }
 
 TEST_F(FormatTestJS, IndexSignature) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1248,7 +1248,7 @@
 case tok::question:
   if (Style.isJavaScript() && Tok->Next &&
   Tok->Next->isOneOf(tok::semi, tok::comma, tok::colon, tok::r_paren,
- tok::r_brace)) {
+ tok::r_brace, tok::r_square)) {
 // Question marks before semicolons, colons, etc. indicate optional
 // types (fields, parameters), e.g.
 //   function(x?: string, y?) {...}


Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2221,6 +2221,7 @@
"  aaa?: boolean,\n"
"  aa?: List\n"
"}) {}");
+  verifyFormat("type X = [y?];");
 }
 
 TEST_F(FormatTestJS, IndexSignature) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1248,7 +1248,7 @@
 case tok::question:
   if (Style.isJavaScript() && Tok->Next &&
   Tok->Next->isOneOf(tok::semi, tok::comma, tok::colon, tok::r_paren,
- tok::r_brace)) {
+ tok::r_brace, tok::r_square)) {
 // Question marks before semicolons, colons, etc. indicate optional
 // types (fields, parameters), e.g.
 //   function(x?: string, y?) {...}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144317: [clang-format] Fix handling of TypeScript tuples with optional last member

2023-02-17 Thread Taymon A. Beal via Phabricator via cfe-commits
taymonbeal created this revision.
taymonbeal added reviewers: MyDeveloperDay, owenpan.
Herald added a project: All.
taymonbeal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

These were previously incorrectly treated as syntax errors.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144317

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestJS.cpp


Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2822,5 +2822,9 @@
Style);
 }
 
+TEST_F(FormatTestJS, TupleTypeWithOptionalLastElement) {
+  verifyFormat("type T = [number?];");
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1248,7 +1248,7 @@
 case tok::question:
   if (Style.isJavaScript() && Tok->Next &&
   Tok->Next->isOneOf(tok::semi, tok::comma, tok::colon, tok::r_paren,
- tok::r_brace)) {
+ tok::r_brace, tok::r_square)) {
 // Question marks before semicolons, colons, etc. indicate optional
 // types (fields, parameters), e.g.
 //   function(x?: string, y?) {...}


Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2822,5 +2822,9 @@
Style);
 }
 
+TEST_F(FormatTestJS, TupleTypeWithOptionalLastElement) {
+  verifyFormat("type T = [number?];");
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1248,7 +1248,7 @@
 case tok::question:
   if (Style.isJavaScript() && Tok->Next &&
   Tok->Next->isOneOf(tok::semi, tok::comma, tok::colon, tok::r_paren,
- tok::r_brace)) {
+ tok::r_brace, tok::r_square)) {
 // Question marks before semicolons, colons, etc. indicate optional
 // types (fields, parameters), e.g.
 //   function(x?: string, y?) {...}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits