default: enter(expression); continue;
} break;
+ case ternary_op:
+ if (kind == Colon) {
+ enter(ternary_op_after_colon);
+ enter(expression_continuation);
+ break;
+ }
+ // fallthrough
+ case ternary_op_after_colon:
case expression:
if (tryInsideExpression())
break;
default: leave(); continue;
} break;
- case ternary_op:
- if (tryInsideExpression())
- break;
- switch (kind) {
- case RightParenthesis:
- case RightBracket:
- case RightBrace:
- case Comma:
- case Semicolon: leave(); continue;
- case Colon: enter(expression); break; // entering expression makes maybe_continuation work
- } break;
-
case jsblock_open:
case substatement_open:
if (tryStatement())
// some states might be continued on the next line
if (topState == expression
|| topState == expression_or_objectdefinition
- || topState == objectliteral_assignment) {
+ || topState == objectliteral_assignment
+ || topState == ternary_op_after_colon) {
enter(expression_maybe_continuation);
}
// multi-line comment start?
bracket_element_maybe_objectdefinition, // after an identifier in bracket_element_start
ternary_op, // The ? : operator
+ ternary_op_after_colon, // after the : in a ternary
jsblock_open,
if (*indentDepth == tokenPosition) {
// expression_or_objectdefinition doesn't want the indent
// expression_or_label already has it
- // ternary already adjusts indents nicely
if (parentState.type != expression_or_objectdefinition
&& parentState.type != expression_or_label
- && parentState.type != binding_assignment
- && parentState.type != ternary_op) {
+ && parentState.type != binding_assignment) {
*indentDepth += 2*m_indentSize;
}
}
// expression_or_objectdefinition and expression_or_label have already consumed the first token
else if (parentState.type != expression_or_objectdefinition
- && parentState.type != expression_or_label
- && parentState.type != ternary_op) {
+ && parentState.type != expression_or_label) {
*indentDepth = tokenPosition;
}
break;
void labelledStatements1();
void labelledStatements2();
void labelledStatements3();
+ void multilineTernaryInProperty();
};
struct Line {
checkIndent(data);
}
+void tst_QMLCodeFormatter::multilineTernaryInProperty()
+{
+ QList<Line> data;
+ data << Line("Item {")
+ << Line(" property int a: 1 ?")
+ << Line(" 2 :")
+ << Line(" 3 +")
+ << Line(" 4")
+ << Line(" property int a: 1 ? 2")
+ << Line(" : 3 +")
+ << Line(" 4")
+ << Line(" a: 1 ?")
+ << Line(" 2 :")
+ << Line(" 3")
+ << Line(" a: 1 ? 2")
+ << Line(" : 3 +")
+ << Line(" 4")
+ << Line(" ba: 1")
+ << Line("}")
+ ;
+ checkIndent(data);
+}
+
QTEST_APPLESS_MAIN(tst_QMLCodeFormatter)
#include "tst_qmlcodeformatter.moc"