summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorMartin Probst <martin@probst.io>2017-11-25 09:24:33 +0000
committerMartin Probst <martin@probst.io>2017-11-25 09:24:33 +0000
commit6c38ef90fdd12917d9401bbaff95ebfc12a08491 (patch)
tree2036498f17295e9a8b1b44c28ece9d4dcfec59fb /clang
parent7e0f25b28d56ee2c568c7bcdc3fcc90182800eab (diff)
downloadbcm5719-llvm-6c38ef90fdd12917d9401bbaff95ebfc12a08491.tar.gz
bcm5719-llvm-6c38ef90fdd12917d9401bbaff95ebfc12a08491.zip
clang-format: [JS] handle `for` as object label.
Summary: Previously, clang-format would fail formatting `{for: 1}`. Reviewers: djasper Subscribers: klimek Differential Revision: https://reviews.llvm.org/D40441 llvm-svn: 318974
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp4
-rw-r--r--clang/unittests/Format/FormatTestJS.cpp5
2 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 4e055210598..4463f89755f 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -617,7 +617,9 @@ private:
break;
case tok::kw_for:
if (Style.Language == FormatStyle::LK_JavaScript) {
- if (Tok->Previous && Tok->Previous->is(tok::period))
+ // x.for and {for: ...}
+ if ((Tok->Previous && Tok->Previous->is(tok::period)) ||
+ (Tok->Next && Tok->Next->is(tok::colon)))
break;
// JS' for await ( ...
if (CurrentToken && CurrentToken->is(Keywords.kw_await))
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index 97ec843a56a..cfdd4b375b6 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -323,6 +323,11 @@ TEST_F(FormatTestJS, ReservedWords) {
" case: string;\n"
" default: string;\n"
"}\n");
+ verifyFormat("const Axis = {\n"
+ " for: 'for',\n"
+ " x: 'x'\n"
+ "};",
+ "const Axis = {for: 'for', x: 'x'};");
}
TEST_F(FormatTestJS, ReservedWordsMethods) {
OpenPOWER on IntegriCloud