diff options
author | Martin Probst <martin@probst.io> | 2017-11-25 09:24:33 +0000 |
---|---|---|
committer | Martin Probst <martin@probst.io> | 2017-11-25 09:24:33 +0000 |
commit | 6c38ef90fdd12917d9401bbaff95ebfc12a08491 (patch) | |
tree | 2036498f17295e9a8b1b44c28ece9d4dcfec59fb /clang | |
parent | 7e0f25b28d56ee2c568c7bcdc3fcc90182800eab (diff) | |
download | bcm5719-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.cpp | 4 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 5 |
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) { |