From: Martin Probst Date: Wed, 22 Jun 2016 14:35:14 +0000 (+0000) Subject: clang-format: [JS] Do not break before 'as'. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5e89d2b26c5a3179ad4649d7b7a23a785a5d75fd;p=clang clang-format: [JS] Do not break before 'as'. Summary: 'as' is a pseudo operator, so automatic semicolon insertion kicks in and the code fails to part. Reviewers: djasper Subscribers: klimek Differential Revision: http://reviews.llvm.org/D21576 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@273422 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index fe7e001daa..9c4a6268ab 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -2373,6 +2373,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, return Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None; if (Right.is(Keywords.kw_in)) return Style.BreakBeforeBinaryOperators != FormatStyle::BOS_None; + if (Right.is(Keywords.kw_as)) + return false; // must not break before as in 'x as type' casts } if (Left.is(tok::at)) diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index f71571c16a..4feb55dae2 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -1051,8 +1051,8 @@ TEST_F(FormatTestJS, Modules) { // ... but not if from is just an identifier. verifyFormat("export {\n" " from as from,\n" - " someSurprisinglyLongVariable\n" - " as from\n" + " someSurprisinglyLongVariable as\n" + " from\n" "};", getGoogleJSStyleWithColumns(20)); verifyFormat("export class C {\n" @@ -1205,6 +1205,9 @@ TEST_F(FormatTestJS, TemplateStrings) { TEST_F(FormatTestJS, CastSyntax) { verifyFormat("var x = foo;"); verifyFormat("var x = foo as type;"); + verifyFormat("let x = (a + b) as\n" + " LongTypeIsLong;", + getGoogleJSStyleWithColumns(20)); verifyFormat("foo = [\n" " 1, //\n" " 2\n"