From dba46d908a97897a6a07ba65c2df4003aa9653e0 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 5 Sep 2014 08:29:31 +0000 Subject: [PATCH] clang-format: [JS] Fix indentation in dict literals. Before: return { 'finish': // a }; After: return { 'finish': // a }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@217235 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 8 ++++++-- unittests/Format/FormatTestJS.cpp | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 00c486a3ad..1361328778 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1110,12 +1110,16 @@ private: /// and other tokens that we treat like binary operators. int getCurrentPrecedence() { if (Current) { + const FormatToken *NextNonComment = Current->getNextNonComment(); if (Current->Type == TT_ConditionalExpr) return prec::Conditional; + else if (NextNonComment && NextNonComment->is(tok::colon) && + NextNonComment->Type == TT_DictLiteral) + return prec::Comma; else if (Current->is(tok::semi) || Current->Type == TT_InlineASMColon || Current->Type == TT_SelectorName || - (Current->is(tok::comment) && Current->getNextNonComment() && - Current->getNextNonComment()->Type == TT_SelectorName)) + (Current->is(tok::comment) && NextNonComment && + NextNonComment->Type == TT_SelectorName)) return 0; else if (Current->Type == TT_RangeBasedForLoopColon) return prec::Comma; diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index fcddba72a8..55e7cc6fe1 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -123,6 +123,11 @@ TEST_F(FormatTestJS, ContainerLiterals) { " // comment for tasks\n" " tasks: false\n" "};"); + verifyFormat("return {\n" + " 'finish':\n" + " //\n" + " a\n" + "};"); } TEST_F(FormatTestJS, SpacesInContainerLiterals) { -- 2.40.0