State.Stack.back().FirstLessLess == 0)
return true;
- if (Current.Type == TT_ObjCSelectorName &&
+ if (Current.Type == TT_SelectorName &&
State.Stack.back().ObjCSelectorNameFound &&
State.Stack.back().BreakBeforeParameter)
return true;
Whitespaces.replaceWhitespace(Current, /*Newlines=*/0, /*IndentLevel=*/0,
Spaces, State.Column + Spaces);
- if (Current.Type == TT_ObjCSelectorName &&
+ if (Current.Type == TT_SelectorName &&
!State.Stack.back().ObjCSelectorNameFound) {
if (Current.LongestObjCSelectorName == 0)
State.Stack.back().AlignColons = false;
if (NextNonComment->isMemberAccess()) {
if (State.Stack.back().CallContinuation == 0)
State.Stack.back().CallContinuation = State.Column;
- } else if (NextNonComment->Type == TT_ObjCSelectorName) {
+ } else if (NextNonComment->Type == TT_SelectorName) {
if (!State.Stack.back().ObjCSelectorNameFound) {
if (NextNonComment->LongestObjCSelectorName == 0) {
State.Stack.back().AlignColons = false;
(!Style.IndentFunctionDeclarationAfterType ||
State.Line->StartsDefinition)))
return std::max(State.Stack.back().LastSpace, State.Stack.back().Indent);
- if (NextNonComment->Type == TT_ObjCSelectorName) {
+ if (NextNonComment->Type == TT_SelectorName) {
if (!State.Stack.back().ObjCSelectorNameFound) {
if (NextNonComment->LongestObjCSelectorName == 0) {
return State.Stack.back().Indent;
if (Current.isMemberAccess())
State.Stack.back().StartOfFunctionCall =
Current.LastOperator ? 0 : State.Column + Current.ColumnWidth;
- if (Current.Type == TT_ObjCSelectorName)
+ if (Current.Type == TT_SelectorName)
State.Stack.back().ObjCSelectorNameFound = true;
if (Current.Type == TT_CtorInitializerColon) {
// Indent 2 from the column, so:
TT_ObjCMethodExpr,
TT_ObjCMethodSpecifier,
TT_ObjCProperty,
- TT_ObjCSelectorName,
TT_OverloadedOperator,
TT_OverloadedOperatorLParen,
TT_PointerOrReference,
TT_PureVirtualSpecifier,
TT_RangeBasedForLoopColon,
TT_RegexLiteral,
+ TT_SelectorName,
TT_StartOfName,
TT_TemplateCloser,
TT_TemplateOpener,
return false;
updateParameterCount(Left, CurrentToken);
if (CurrentToken->is(tok::colon) &&
- Style.Language != FormatStyle::LK_Proto)
+ Style.Language != FormatStyle::LK_Proto) {
+ if (CurrentToken->getPreviousNonComment()->is(tok::identifier))
+ CurrentToken->getPreviousNonComment()->Type = TT_SelectorName;
Left->Type = TT_DictLiteral;
+ }
if (!consumeToken())
return false;
}
} else if (Contexts.back().ColonIsObjCMethodExpr ||
Line.First->Type == TT_ObjCMethodSpecifier) {
Tok->Type = TT_ObjCMethodExpr;
- Tok->Previous->Type = TT_ObjCSelectorName;
+ Tok->Previous->Type = TT_SelectorName;
if (Tok->Previous->ColumnWidth >
Contexts.back().LongestObjCSelectorName) {
Contexts.back().LongestObjCSelectorName = Tok->Previous->ColumnWidth;
// expression.
while (Current &&
(Current->is(tok::kw_return) ||
- (Current->is(tok::colon) && Current->Type == TT_ObjCMethodExpr)))
+ (Current->is(tok::colon) && (Current->Type == TT_ObjCMethodExpr ||
+ Current->Type == TT_DictLiteral))))
next();
if (!Current || Precedence > PrecedenceArrowAndPeriod)
int CurrentPrecedence = getCurrentPrecedence();
- if (Current && Current->Type == TT_ObjCSelectorName &&
+ if (Current && Current->Type == TT_SelectorName &&
Precedence == CurrentPrecedence) {
if (LatestOperator)
addFakeParenthesis(Start, prec::Level(Precedence));
if (Current->Type == TT_ConditionalExpr)
return prec::Conditional;
else if (Current->is(tok::semi) || Current->Type == TT_InlineASMColon ||
- Current->Type == TT_ObjCSelectorName)
+ Current->Type == TT_SelectorName)
return 0;
else if (Current->Type == TT_RangeBasedForLoopColon)
return prec::Comma;
// In Objective-C method expressions, prefer breaking before "param:" over
// breaking after it.
- if (Right.Type == TT_ObjCSelectorName)
+ if (Right.Type == TT_SelectorName)
return 0;
if (Left.is(tok::colon) && Left.Type == TT_ObjCMethodExpr)
return Line.MightBeFunctionDecl ? 50 : 500;
if (Left.is(tok::colon) &&
(Left.Type == TT_DictLiteral || Left.Type == TT_ObjCMethodExpr))
return true;
- if (Right.Type == TT_ObjCSelectorName)
+ if (Right.Type == TT_SelectorName)
return true;
if (Left.is(tok::r_paren) && Line.Type == LT_ObjCProperty)
return true;
llvm::errs() << " M=" << Tok->MustBreakBefore
<< " C=" << Tok->CanBreakBefore << " T=" << Tok->Type
<< " S=" << Tok->SpacesRequiredBefore
+ << " B=" << Tok->BlockParameterCount
<< " P=" << Tok->SplitPenalty << " Name=" << Tok->Tok.getName()
<< " L=" << Tok->TotalLength << " PPK=" << Tok->PackingKind
<< " FakeLParens=";
verifyFormat("var {a, b} = {a: 1, b: 2};");
}
+TEST_F(FormatTestJS, ContainerLiterals) {
+ verifyFormat("return {\n"
+ " link: function() {\n"
+ " f(); //\n"
+ " }\n"
+ "};");
+ verifyFormat("return {\n"
+ " a: a,\n"
+ " link: function() {\n"
+ " f(); //\n"
+ " }\n"
+ "};");
+ verifyFormat("return {\n"
+ " a: a,\n"
+ " link:\n"
+ " function() {\n"
+ " f(); //\n"
+ " },\n"
+ " link:\n"
+ " function() {\n"
+ " f(); //\n"
+ " }\n"
+ "};");
+}
+
TEST_F(FormatTestJS, SpacesInContainerLiterals) {
verifyFormat("var arr = [1, 2, 3];");
verifyFormat("var obj = {a: 1, b: 2, c: 3};");