From: Daniel Jasper Date: Wed, 3 Jun 2015 08:43:18 +0000 (+0000) Subject: clang-format: [JS] Fix bug in type colon detection. X-Git-Tag: llvmorg-3.7.0-rc1~3135 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=81dbb564a14ff7a162ae920456f064e865294ed0;p=platform%2Fupstream%2Fllvm.git clang-format: [JS] Fix bug in type colon detection. Before, this couldn't be formatted at all: class X { subs = { 'b': { 'c': 1, }, }; } llvm-svn: 238907 --- diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 3c1c9a1..6b59cb3 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -448,7 +448,8 @@ private: !Line.First->isOneOf(tok::kw_enum, tok::kw_case)) || Contexts.back().ContextKind == tok::l_paren || // function params Contexts.back().ContextKind == tok::l_square || // array type - Line.MustBeDeclaration) { // method/property declaration + (Contexts.size() == 1 && + Line.MustBeDeclaration)) { // method/property declaration Tok->Type = TT_JsTypeColon; break; } diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 80a3e0a..3ed3cde 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -631,6 +631,15 @@ TEST_F(FormatTestJS, ClassDeclarations) { verifyFormat("class C {\n static x(): string { return 'asd'; }\n}"); verifyFormat("class C extends P implements I {}"); verifyFormat("class C extends p.P implements i.I {}"); + + // ':' is not a type declaration here. + verifyFormat("class X {\n" + " subs = {\n" + " 'b': {\n" + " 'c': 1,\n" + " },\n" + " };\n" + "}"); } TEST_F(FormatTestJS, InterfaceDeclarations) {