QmlJS indenter: Fix hang with invalid code.

Task-number: QTCREATORBUG-7005

Change-Id: I095c3714d28b632cf814065c4be2262c8d009d00
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com>
This commit is contained in:
Christian Kamm
2012-02-29 08:03:02 +01:00
committed by Fawzi Mohamed
parent f6870581e4
commit 0c597a6f07
2 changed files with 36 additions and 3 deletions

View File

@@ -167,6 +167,11 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
case Signal:
case Property:
case Identifier: enter(expression_or_objectdefinition); break;
// error recovery
case RightBracket:
case RightParenthesis: leave(true); break;
default: enter(expression); continue;
} break;
@@ -251,9 +256,14 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
case expression_or_objectdefinition:
switch (kind) {
case Dot:
case Identifier: break; // need to become an objectdefinition_open in cases like "width: Qt.Foo {"
case LeftBrace: turnInto(objectdefinition_open); break;
default: enter(expression); continue; // really? identifier and more tokens might already be gone
case Identifier: break; // need to become an objectdefinition_open in cases like "width: Qt.Foo {"
case LeftBrace: turnInto(objectdefinition_open); break;
// propagate 'leave' from expression state
case RightBracket:
case RightParenthesis: leave(); continue;
default: enter(expression); continue; // really? identifier and more tokens might already be gone
} break;
case expression_or_label:

View File

@@ -105,6 +105,7 @@ private Q_SLOTS:
void multilineTernaryInProperty();
void multilineString();
void bug1();
void bug2();
};
enum { DontCheck = -2, DontIndent = -1 };
@@ -1438,6 +1439,28 @@ void tst_QMLCodeFormatter::bug1()
checkIndent(data);
}
void tst_QMLCodeFormatter::bug2()
{
QList<Line> data;
data << Line("Item {")
<< Line(" x: a)")
<< Line(" x: a) + 2")
<< Line(" x: a == b)")
<< Line(" x: a == b) + 5")
<< Line(" x: a == b) ? c : d")
<< Line(" x: 1)")
<< Line(" x: 1) + 2")
<< Line(" x: 1 == 2)")
<< Line(" x: 1 == 2) + 5")
<< Line(" x: 1 == 2) ? c : d")
<< Line(" x: 1")
<< Line("}")
;
checkIndent(data);
}
QTEST_APPLESS_MAIN(tst_QMLCodeFormatter)
#include "tst_qmlcodeformatter.moc"