diff --git a/src/libs/qmljs/qmljscodeformatter.cpp b/src/libs/qmljs/qmljscodeformatter.cpp index 51ffd7f7da1..67d60155f02 100644 --- a/src/libs/qmljs/qmljscodeformatter.cpp +++ b/src/libs/qmljs/qmljscodeformatter.cpp @@ -430,7 +430,7 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block) switch (kind) { case While: break; case LeftParenthesis: enter(do_statement_while_paren_open); break; - default: leave(true); break; + default: leave(true); continue; // error recovery } break; case do_statement_while_paren_open: @@ -788,6 +788,7 @@ bool CodeFormatter::isExpressionEndState(int type) const type == top_js || type == objectdefinition_open || type == if_statement || + type == do_statement || type == else_clause || type == jsblock_open || type == substatement_open || diff --git a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp index 22d69c0f3d7..53326c6c972 100644 --- a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp +++ b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp @@ -77,6 +77,7 @@ private Q_SLOTS: void whileStatement(); void tryStatement(); void doWhile(); + void doWhile2(); void cStyleComments(); void cppStyleComments(); void qmlKeywords(); @@ -858,6 +859,24 @@ void tst_QMLCodeFormatter::doWhile() checkIndent(data); } +void tst_QMLCodeFormatter::doWhile2() +{ + QList data; + data << Line("function foo() {") + << Line(" do { if (c) foo; } while (a)") + << Line(" do {") + << Line(" if (a);") + << Line(" } while (a)") + << Line(" do") + << Line(" foo;") + << Line(" while (a)") + << Line(" do foo; while (a)") + << Line("}") + << Line("var x") + ; + checkIndent(data); +} + void tst_QMLCodeFormatter::cStyleComments() { QList data; @@ -1174,7 +1193,7 @@ void tst_QMLCodeFormatter::labelledStatements1() << Line(" while (1) {") << Line(" break lab") << Line(" }") - << Line(" }") + << Line(" } while (1)") << Line("}") << Line("var x = function() {") << Line(" x + 1;")