From ed87d788d610063e7c6e74a12565001ce77a0d73 Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Mon, 22 Aug 2016 14:23:30 +0000 Subject: [PATCH] clang-format: [JS] supports casts to types starting with punctuation ("{[("). Before: x as{x: number} After: x as {x: number} Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D23761 llvm-svn: 279436 --- clang/lib/Format/TokenAnnotator.cpp | 3 +++ clang/unittests/Format/FormatTestJS.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 0599611..081ea98 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2121,6 +2121,9 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, Keywords.kw_of, tok::kw_const) && (!Left.Previous || !Left.Previous->is(tok::period))) return true; + if (Left.is(Keywords.kw_as) && + Right.isOneOf(tok::l_square, tok::l_brace, tok::l_paren)) + return true; if (Left.is(tok::kw_default) && Left.Previous && Left.Previous->is(tok::kw_export)) return true; diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 838caff..f6e8ff2 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -1219,6 +1219,9 @@ TEST_F(FormatTestJS, CastSyntax) { " 2\n" "];"); verifyFormat("var x = [{x: 1} as type];"); + verifyFormat("x = x as [a, b];"); + verifyFormat("x = x as {a: string};"); + verifyFormat("x = x as (string);"); } TEST_F(FormatTestJS, TypeArguments) { -- 2.7.4