From ce2bd4dfd8d56512acd9f4c79f2894703e5977f1 Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Fri, 24 Nov 2017 17:05:56 +0000 Subject: clang-format: [JS] do not break in ArrayType[]. Summary: Wrapping between the type name and the array type indicator creates invalid syntax in TypeScript. Before: const xIsALongIdent: YJustBarelyFitsLinex []; // illegal syntax. After: const xIsALongIdent: YJustBarelyFitsLinex[]; Reviewers: djasper Subscribers: klimek Differential Revision: https://reviews.llvm.org/D40436 llvm-svn: 318959 --- clang/lib/Format/TokenAnnotator.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'clang/lib/Format/TokenAnnotator.cpp') 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)) -- cgit v1.2.3