[clang] 801bd32 - [clalng-format] Fix handling of TypeScript tuples with optional last member

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 21 02:52:23 PST 2023


Author: Taymon A. Beal
Date: 2023-02-21T02:51:56-08:00
New Revision: 801bd3265362389a7125051128fdd3e6e85cc37b

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

LOG: [clalng-format] Fix handling of TypeScript tuples with optional last member

These were previously incorrectly treated as syntax errors.

Differential Revision: https://reviews.llvm.org/D144317

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 0461531c32b1..3592862c2885 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1248,7 +1248,7 @@ class AnnotatingParser {
     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?) {...}

diff  --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index 5291cb7adaaf..6f07d8b084f5 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -2221,6 +2221,7 @@ TEST_F(FormatTestJS, OptionalTypes) {
                "  aaaaaaaaaaaaaaa?: boolean,\n"
                "  aaaaaa?: List<string>\n"
                "}) {}");
+  verifyFormat("type X = [y?];");
 }
 
 TEST_F(FormatTestJS, IndexSignature) {


        


More information about the cfe-commits mailing list