clang-format: [JS] Support comments in dict literals.

Before:
  var stuff = {
    // comment for update
    update : false,
             // comment for update
    modules : false,
              // comment for update
    tasks : false
  };

After:
  var stuff = {
    // comment for update
    update : false,
    // comment for update
    modules : false,
    // comment for update
    tasks : false
  };

llvm-svn: 217157
This commit is contained in:
Daniel Jasper 2014-09-04 14:58:30 +00:00
parent 2132b704ff
commit 94e11d02d8
2 changed files with 16 additions and 4 deletions

View File

@ -1100,7 +1100,7 @@ public:
++OperatorIndex;
}
next();
next(/*SkipPastLeadingComments=*/false);
}
}
}
@ -1113,7 +1113,9 @@ private:
if (Current->Type == TT_ConditionalExpr)
return prec::Conditional;
else if (Current->is(tok::semi) || Current->Type == TT_InlineASMColon ||
Current->Type == TT_SelectorName)
Current->Type == TT_SelectorName ||
(Current->is(tok::comment) && Current->getNextNonComment() &&
Current->getNextNonComment()->Type == TT_SelectorName))
return 0;
else if (Current->Type == TT_RangeBasedForLoopColon)
return prec::Comma;
@ -1166,10 +1168,12 @@ private:
addFakeParenthesis(Start, prec::Conditional);
}
void next() {
void next(bool SkipPastLeadingComments = true) {
if (Current)
Current = Current->Next;
while (Current && Current->isTrailingComment())
while (Current &&
(Current->NewlinesBefore == 0 || SkipPastLeadingComments) &&
Current->isTrailingComment())
Current = Current->Next;
}

View File

@ -111,6 +111,14 @@ TEST_F(FormatTestJS, ContainerLiterals) {
" f(); //\n"
" }\n"
"};");
verifyFormat("var stuff = {\n"
" // comment for update\n"
" update: false,\n"
" // comment for modules\n"
" modules: false,\n"
" // comment for tasks\n"
" tasks: false\n"
"};");
}
TEST_F(FormatTestJS, SpacesInContainerLiterals) {