diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/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?) {...} diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -2221,6 +2221,7 @@ " aaaaaaaaaaaaaaa?: boolean,\n" " aaaaaa?: List\n" "}) {}"); + verifyFormat("type X = [y?];"); } TEST_F(FormatTestJS, IndexSignature) {