diff options
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 3 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 9 |
2 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 3c1c9a1defd..6b59cb365cc 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 80a3e0a66a0..3ed3cdeee1a 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) { |

