Skip to content
Snippets Groups Projects
Commit c86e76ef authored by Daniel Jasper's avatar Daniel Jasper
Browse files

clang-format: [JS] Fix spacing in dict literals.

Before:
  someVariable = {'a':[{}]};

After:
  someVariable = {'a': [{}]};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208403 91177308-0d34-0410-b5e6-96231b3b80d8
parent 09a6d705
No related branches found
No related tags found
No related merge requests found
......@@ -225,8 +225,10 @@ private:
FormatToken *Parent = Left->getPreviousNonComment();
bool StartsObjCMethodExpr =
Contexts.back().CanBeExpression && Left->Type != TT_LambdaLSquare &&
(!Parent || Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren,
tok::kw_return, tok::kw_throw) ||
CurrentToken->isNot(tok::l_brace) &&
(!Parent ||
Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren,
tok::kw_return, tok::kw_throw) ||
Parent->isUnaryOperator() || Parent->Type == TT_ObjCForIn ||
Parent->Type == TT_CastRParen ||
getBinOpPrecedence(Parent->Tok.getKind(), true, true) > prec::Unknown);
......@@ -1452,7 +1454,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
return Right.MatchingParen && Style.SpacesInContainerLiterals &&
Right.MatchingParen->Type == TT_ArrayInitializerLSquare;
if (Right.is(tok::l_square) && Right.Type != TT_ObjCMethodExpr &&
Right.Type != TT_LambdaLSquare && Left.isNot(tok::numeric_constant))
Right.Type != TT_LambdaLSquare && Left.isNot(tok::numeric_constant) &&
Left.Type != TT_DictLiteral)
return false;
if (Left.is(tok::colon))
return Left.Type != TT_ObjCMethodExpr;
......
......@@ -85,6 +85,7 @@ TEST_F(FormatTestJS, SpacesInContainerLiterals) {
verifyFormat("var obj = {a: 1, b: 2, c: 3};",
getChromiumStyle(FormatStyle::LK_JavaScript));
verifyFormat("someVariable = {'a': [{}]};");
}
TEST_F(FormatTestJS, SingleQuoteStrings) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment