OSDN Git Service

QmlJS indenter: Fix hang when using 'else (a==a) {}'.
authorChristian Kamm <christian.d.kamm@nokia.com>
Wed, 19 Oct 2011 07:21:48 +0000 (09:21 +0200)
committerChristian Kamm <christian.d.kamm@nokia.com>
Wed, 19 Oct 2011 07:40:12 +0000 (09:40 +0200)
Change-Id: Id7b8fba6707b1eaabf8065854f357cf600c809c5
Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com>
src/libs/qmljs/qmljscodeformatter.cpp
tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp

index 782e0f3..fa5ef50 100644 (file)
@@ -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;
index 046540b..938f20d 100644 (file)
@@ -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"