]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] handle object literals with casts.
authorMartin Probst <martin@probst.io>
Fri, 19 Aug 2016 14:35:01 +0000 (14:35 +0000)
committerMartin Probst <martin@probst.io>
Fri, 19 Aug 2016 14:35:01 +0000 (14:35 +0000)
Summary: E.g. `{a: 1} as b`.

Reviewers: djasper

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D23714

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@279250 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestJS.cpp

index 9f79ba60f39febef6e7728700d5dcee74931369b..94dccc6e02b04fdd36560bf318e70d2e74b01d7a 100644 (file)
@@ -364,7 +364,8 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
           // We exclude + and - as they can be ObjC visibility modifiers.
           ProbablyBracedList =
               (Style.Language == FormatStyle::LK_JavaScript &&
-               NextTok->isOneOf(Keywords.kw_of, Keywords.kw_in)) ||
+               NextTok->isOneOf(Keywords.kw_of, Keywords.kw_in,
+                                Keywords.kw_as)) ||
               NextTok->isOneOf(tok::comma, tok::period, tok::colon,
                                tok::r_paren, tok::r_square, tok::l_brace,
                                tok::l_square, tok::l_paren, tok::ellipsis) ||
index 2819383a35851b214079ecd1d6abb7fb674e9e99..838caffc7087b1befdd532b1452aa2f3c8e8d34a 100644 (file)
@@ -1218,6 +1218,7 @@ TEST_F(FormatTestJS, CastSyntax) {
                "  1,  //\n"
                "  2\n"
                "];");
+  verifyFormat("var x = [{x: 1} as type];");
 }
 
 TEST_F(FormatTestJS, TypeArguments) {