Commit ff58b310 authored by Robert Loehning's avatar Robert Loehning Committed by Eike Ziller
Browse files

QmlJS indenter: Fix hang with invalid code.

Task-number: QTCREATORBUG-7005

(cherry picked from commit 0c597a6f

)

Change-Id: I2e343fbcc6931530e7db142bf6e268dac696970f
Reviewed-by: default avatarChristian Kamm <christian.d.kamm@nokia.com>
parent cb6e3247
......@@ -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:
......
......@@ -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"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment