From: Daniel Jasper Date: Mon, 13 Apr 2015 15:03:30 +0000 (+0000) Subject: clang-format: [JS] Support index signature types. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e439d2940a9dca8d22b5e38b9a38f6d0d84c72c7;p=clang clang-format: [JS] Support index signature types. Patch by Martin Probst. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234754 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 0ea67b288d..0c11c88221 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -413,7 +413,8 @@ private: if (Contexts.back().ColonIsForRangeExpr || (Contexts.size() == 1 && !Line.First->isOneOf(tok::kw_enum, tok::kw_case)) || - Contexts.back().ContextKind == tok::l_paren) { + Contexts.back().ContextKind == tok::l_paren || + Contexts.back().ContextKind == tok::l_square) { Tok->Type = TT_JsTypeColon; break; } diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index eb587f2769..3c8c14d2ba 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -670,5 +670,9 @@ TEST_F(FormatTestJS, OptionalTypes) { "}"); } +TEST_F(FormatTestJS, IndexSignature) { + verifyFormat("var x: {[k: string]: v};"); +} + } // end namespace tooling } // end namespace clang