default: enter(expression); continue;
} break;
- // property inits don't take statements
- case property_initializer:
- switch (kind) {
- case Semicolon: leave(true); break;
- case LeftBrace: enter(objectliteral_open); break;
- case On:
- case As:
- case List:
- case Import:
- case Signal:
- case Property:
- case Identifier: enter(expression_or_objectdefinition); break;
- default: enter(expression); continue;
- } break;
-
case objectdefinition_open:
switch (kind) {
case RightBrace: leave(true); break;
case property_maybe_initializer:
switch (kind) {
- case Colon: enter(property_initializer); break;
+ case Colon: turnInto(binding_assignment); break;
default: leave(true); continue;
} break;
switch (newState) {
case objectdefinition_open: {
// special case for things like "gradient: Gradient {"
- if (parentState.type == binding_assignment || parentState.type == property_initializer)
+ if (parentState.type == binding_assignment)
*savedIndentDepth = state(1).savedIndentDepth;
if (firstToken)
break;
case binding_assignment:
- case property_initializer:
case objectliteral_assignment:
if (lastToken)
*indentDepth = *savedIndentDepth + 4;
// ternary already adjusts indents nicely
if (parentState.type != expression_or_objectdefinition
&& parentState.type != binding_assignment
- && parentState.type != property_initializer
&& parentState.type != ternary_op) {
*indentDepth += 2 * m_indentSize;
}
break;
case bracket_open:
- if (parentState.type == expression && (state(1).type == binding_assignment
- || state(1).type == property_initializer)) {
+ if (parentState.type == expression && state(1).type == binding_assignment) {
*savedIndentDepth = state(2).savedIndentDepth;
*indentDepth = *savedIndentDepth + m_indentSize;
} else if (!lastToken) {
}
// fallthrough
case substatement_open:
- // special case for foo: {
- if (parentState.type == binding_assignment && state(1).type == binding_or_objectdefinition)
+ // special case for "foo: {" and "property int foo: {"
+ if (parentState.type == binding_assignment)
*savedIndentDepth = state(1).savedIndentDepth;
*indentDepth = *savedIndentDepth + m_indentSize;
break;
case objectliteral_open:
if (parentState.type == expression
- || parentState.type == objectliteral_assignment
- || parentState.type == property_initializer) {
+ || parentState.type == objectliteral_assignment) {
// undo the continuation indent of the expression
*indentDepth = parentState.savedIndentDepth;
*savedIndentDepth = *indentDepth;
case LeftBrace:
if (topState.type == substatement
|| topState.type == binding_assignment
- || topState.type == property_initializer
|| topState.type == case_cont) {
*indentDepth = topState.savedIndentDepth;
}
void objectLiteral2();
void objectLiteral3();
void objectLiteral4();
- void objectLiteral5();
+ void propertyWithStatement();
void keywordStatement();
void namespacedObjects();
};
checkIndent(data);
}
-void tst_QMLCodeFormatter::objectLiteral5()
+void tst_QMLCodeFormatter::propertyWithStatement()
{
QList<Line> data;
data << Line("Rectangle {")
- << Line(" property int x: { a: 12, b: 13 }")
+ << Line(" property int x: { if (a) break }")
<< Line(" property int y: {")
- << Line(" a: 1 +")
- << Line(" 2 + 3")
- << Line(" + 4")
+ << Line(" if (a)")
+ << Line(" break")
+ << Line(" switch (a) {")
+ << Line(" case 1:")
+ << Line(" case 2:")
+ << Line(" continue")
+ << Line(" }")
<< Line(" }")
- << Line(" property int y: {")
- << Line(" a: 1 +")
- << Line(" 2 + 3")
- << Line(" + 4,")
- << Line(" b: {")
- << Line(" adef: 1 +")
- << Line(" 2 + 3")
- << Line(" + 4,")
+ << Line(" property int y:")
+ << Line(" {")
+ << Line(" if (a)")
+ << Line(" break")
+ << Line(" switch (a) {")
+ << Line(" case 1:")
+ << Line(" case 2:")
+ << Line(" continue")
<< Line(" }")
<< Line(" }")
<< Line("}")