summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2016-01-04 13:11:41 +0000
committerDaniel Jasper <djasper@google.com>2016-01-04 13:11:41 +0000
commitebcb71fb875647de31cc0de5b446b72703a212bb (patch)
tree62bbf5beded3805ef5657490249430d4a1605bb9 /clang
parent11d14314cc3e9cc90c45de273496a369433b78aa (diff)
downloadbcm5719-llvm-ebcb71fb875647de31cc0de5b446b72703a212bb.tar.gz
bcm5719-llvm-ebcb71fb875647de31cc0de5b446b72703a212bb.zip
clang-format: [JS] Improve empty array literal detection.
Previously, the [] in the following example were recognized as an array subscript leading to weird indentation. Before: var aaaa = aaaaa || // wrap []; After: var aaaa = aaaaa || // wrap []; llvm-svn: 256753
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp6
-rw-r--r--clang/unittests/Format/FormatTestJS.cpp2
2 files changed, 5 insertions, 3 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index badba16a891..da0fdb91704 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -287,9 +287,9 @@ private:
Left->Type = TT_JsComputedPropertyName;
} else if (Style.Language == FormatStyle::LK_Proto ||
(Parent &&
- Parent->isOneOf(tok::at, tok::equal, tok::comma, tok::l_paren,
- tok::l_square, tok::question, tok::colon,
- tok::kw_return))) {
+ Parent->isOneOf(TT_BinaryOperator, tok::at, tok::comma,
+ tok::l_paren, tok::l_square, tok::question,
+ tok::colon, tok::kw_return))) {
Left->Type = TT_ArrayInitializerLSquare;
} else {
BindingIncrease = 10;
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index cba2ce3370c..d42eed6048f 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -310,6 +310,8 @@ TEST_F(FormatTestJS, ArrayLiterals) {
" ccccccccccccccccccccccccccc\n"
" ],\n"
" aaaa);");
+ verifyFormat("var aaaa = aaaaa || // wrap\n"
+ " [];");
verifyFormat("someFunction([], {a: a});");
}
OpenPOWER on IntegriCloud