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

Taymon A. Beal via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 17 18:35:37 PST 2023


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?) {...}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144317.498549.patch
Type: text/x-patch
Size: 1047 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230218/5449b678/attachment-0001.bin>


More information about the cfe-commits mailing list