diff --git a/src/libs/qmljs/qmljscodeformatter.cpp b/src/libs/qmljs/qmljscodeformatter.cpp
index 782e0f36a5961ead080992ffb7b7ce46cce6e3e2..fa5ef50eeac8e58b1ce2f6ab887e2312d221a30f 100644
--- a/src/libs/qmljs/qmljscodeformatter.cpp
+++ b/src/libs/qmljs/qmljscodeformatter.cpp
@@ -255,8 +255,13 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
 
         case expression_or_label:
             switch (kind) {
-            case Colon:         turnInto(labelled_statement); break;
-            default:            enter(expression); continue;
+            case Colon:             turnInto(labelled_statement); break;
+
+            // propagate 'leave' from expression state
+            case RightBracket:
+            case RightParenthesis:  leave(); continue;
+
+            default:                enter(expression); continue;
             } break;
 
         case ternary_op:
@@ -756,6 +761,7 @@ bool CodeFormatter::tryStatement()
     case Function:
     case Number:
     case String:
+    case LeftParenthesis:
         enter(expression);
         // look at the token again
         m_tokenIndex -= 1;
diff --git a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp
index 046540befebcfbb062c9cb79c80688bb62512b7c..938f20df715a3079f56d96a8b3ac7c3fd100189d 100644
--- a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp
+++ b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp
@@ -97,6 +97,7 @@ private Q_SLOTS:
     void labelledStatements3();
     void json1();
     void multilineTernaryInProperty();
+    void bug1();
 };
 
 struct Line {
@@ -1277,6 +1278,20 @@ void tst_QMLCodeFormatter::multilineTernaryInProperty()
     checkIndent(data);
 }
 
+void tst_QMLCodeFormatter::bug1()
+{
+    QList<Line> data;
+    data << Line("Item {")
+         << Line("    x: {")
+         << Line("        if (a==a) {}")
+         << Line("        else (b==b) {}")
+         << Line("        foo()")
+         << Line("    }")
+         << Line("}")
+         ;
+    checkIndent(data);
+}
+
 QTEST_APPLESS_MAIN(tst_QMLCodeFormatter)
 #include "tst_qmlcodeformatter.moc"