summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp3
-rw-r--r--clang/unittests/Format/FormatTestJS.cpp2
2 files changed, 5 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index d8d8bcbfc17..4e055210598 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2706,6 +2706,9 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
Keywords.kw_readonly, Keywords.kw_abstract,
Keywords.kw_get, Keywords.kw_set))
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 (Left.is(TT_JsFatArrow) && Right.is(tok::l_brace))
return false;
if (Left.is(TT_JsTypeColon))
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index 2665c8b428e..a1075991885 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -1426,6 +1426,8 @@ TEST_F(FormatTestJS, TypeAnnotations) {
verifyFormat(
"var someValue = (v as aaaaaaaaaaaaaaaaaaaa<T>[])\n"
" .someFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
+ verifyFormat("const xIsALongIdent:\n"" YJustBarelyFitsLinex[];",
+ getGoogleJSStyleWithColumns(20));
}
TEST_F(FormatTestJS, UnionIntersectionTypes) {
OpenPOWER on IntegriCloud