summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorMartin Probst <martin@probst.io>2018-01-26 15:07:49 +0000
committerMartin Probst <martin@probst.io>2018-01-26 15:07:49 +0000
commitf8e1f5c7d38d0298d7b078838b22ef24ec98aa45 (patch)
tree058a21dee85877c58ead61b59712e861a2674eaa /clang/lib
parent65ec923805d94cc503b9ca185d619928a3adb133 (diff)
downloadbcm5719-llvm-f8e1f5c7d38d0298d7b078838b22ef24ec98aa45.tar.gz
bcm5719-llvm-f8e1f5c7d38d0298d7b078838b22ef24ec98aa45.zip
clang-format: [JS] Prevent ASI before [ and (.
Summary: JavaScript automatic semicolon insertion can trigger before [ and (, so avoid breaking before them if the previous token is likely to terminate an expression. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D42570 llvm-svn: 323532
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 19f2ddae6cf..9287cbc3a9b 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2710,9 +2710,11 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
Keywords.kw_readonly, Keywords.kw_abstract, Keywords.kw_get,
Keywords.kw_set, Keywords.kw_async, Keywords.kw_await))
return false; // Otherwise automatic semicolon insertion would trigger.
- if (Left.Tok.getIdentifierInfo() &&
- Right.startsSequence(tok::l_square, tok::r_square))
- return false; // breaking in "foo[]" creates illegal TS type syntax.
+ if (Right.NestingLevel == 0 &&
+ (Left.Tok.getIdentifierInfo() ||
+ Left.isOneOf(tok::r_square, tok::r_paren)) &&
+ Right.isOneOf(tok::l_square, tok::l_paren))
+ return false; // Otherwise automatic semicolon insertion would trigger.
if (Left.is(TT_JsFatArrow) && Right.is(tok::l_brace))
return false;
if (Left.is(TT_JsTypeColon))
OpenPOWER on IntegriCloud