Skip to content

Commit

Permalink
clang-format: [JS] handle for as object label.
Browse files Browse the repository at this point in the history
Summary: Previously, clang-format would fail formatting `{for: 1}`.

Reviewers: djasper

Subscribers: klimek

Differential Revision: https://reviews.llvm.org/D40441

llvm-svn: 318974
mprobst committed Nov 25, 2017
1 parent 7e0f25b commit 6c38ef9
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
@@ -617,7 +617,9 @@ class AnnotatingParser {
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))
5 changes: 5 additions & 0 deletions clang/unittests/Format/FormatTestJS.cpp
Original file line number Diff line number Diff line change
@@ -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) {

0 comments on commit 6c38ef9

Please sign in to comment.