r279250 - clang-format: [JS] handle object literals with casts.

Martin Probst via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 19 07:35:02 PDT 2016


Author: mprobst
Date: Fri Aug 19 09:35:01 2016
New Revision: 279250

URL: http://llvm.org/viewvc/llvm-project?rev=279250&view=rev
Log:
clang-format: [JS] handle object literals with casts.

Summary: E.g. `{a: 1} as b`.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

Modified:
    cfe/trunk/lib/Format/UnwrappedLineParser.cpp
    cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=279250&r1=279249&r2=279250&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Fri Aug 19 09:35:01 2016
@@ -364,7 +364,8 @@ void UnwrappedLineParser::calculateBrace
           // 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) ||

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=279250&r1=279249&r2=279250&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Fri Aug 19 09:35:01 2016
@@ -1218,6 +1218,7 @@ TEST_F(FormatTestJS, CastSyntax) {
                "  1,  //\n"
                "  2\n"
                "];");
+  verifyFormat("var x = [{x: 1} as type];");
 }
 
 TEST_F(FormatTestJS, TypeArguments) {




More information about the cfe-commits mailing list