summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2011-10-19 09:21:48 +0200
committerEike Ziller <eike.ziller@nokia.com>2011-11-22 13:52:39 +0100
commitfad5cc01669bd892b6c30362732c62f5c55c5ba2 (patch)
tree666b158d7b7a7a9d079d66bc24177db076213658
parentd530e8ddb888fde70863f303843b512aa3f7762a (diff)
downloadqt-creator-fad5cc01669bd892b6c30362732c62f5c55c5ba2.tar.gz
QmlJS indenter: Fix hang when using 'else (a==a) {}'.
Change-Id: Id7b8fba6707b1eaabf8065854f357cf600c809c5 Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com> (cherry picked from commit 567e68a42a0a57f6dc83d39cf664e48c1dee6f9b) Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
-rw-r--r--src/libs/qmljs/qmljscodeformatter.cpp10
-rw-r--r--tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp15
2 files changed, 23 insertions, 2 deletions
diff --git a/src/libs/qmljs/qmljscodeformatter.cpp b/src/libs/qmljs/qmljscodeformatter.cpp
index c09ddbee14..484c0ddc32 100644
--- a/src/libs/qmljs/qmljscodeformatter.cpp
+++ b/src/libs/qmljs/qmljscodeformatter.cpp
@@ -254,8 +254,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 af48a113e5..fa0c58b211 100644
--- a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp
+++ b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp
@@ -96,6 +96,7 @@ private Q_SLOTS:
void labelledStatements3();
void multilineTernaryInProperty();
void multilineString();
+ void bug1();
};
enum { DontCheck = -2, DontIndent = -1 };
@@ -1242,6 +1243,20 @@ void tst_QMLCodeFormatter::multilineString()
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"