Skip to content

Commit

Permalink
clang-format: [JS] Do not break before 'as'.
Browse files Browse the repository at this point in the history
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

llvm-svn: 273422
  • Loading branch information
mprobst committed Jun 22, 2016
1 parent c6cacd6 commit dce8e41
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions clang/lib/Format/TokenAnnotator.cpp
Expand Up @@ -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))
Expand Down
7 changes: 5 additions & 2 deletions clang/unittests/Format/FormatTestJS.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -1205,6 +1205,9 @@ TEST_F(FormatTestJS, TemplateStrings) {
TEST_F(FormatTestJS, CastSyntax) {
verifyFormat("var x = <type>foo;");
verifyFormat("var x = foo as type;");
verifyFormat("let x = (a + b) as\n"
" LongTypeIsLong;",
getGoogleJSStyleWithColumns(20));
verifyFormat("foo = <Bar[]>[\n"
" 1, //\n"
" 2\n"
Expand Down

0 comments on commit dce8e41

Please sign in to comment.