diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 8 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 3 |
2 files changed, 8 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)) diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 2a929563f75..47886521008 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -1157,6 +1157,9 @@ TEST_F(FormatTestJS, WrapRespectsAutomaticSemicolonInsertion) { "foo() {}", getGoogleJSStyleWithColumns(10)); verifyFormat("await theReckoning;", getGoogleJSStyleWithColumns(10)); + verifyFormat("some['a']['b']", getGoogleJSStyleWithColumns(10)); + verifyFormat("x = (a['a']\n" + " ['b']);", getGoogleJSStyleWithColumns(10)); } TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) { |