diff --git a/src/libs/qmljs/qmljscodeformatter.cpp b/src/libs/qmljs/qmljscodeformatter.cpp index 3213cf31e2f..7ec947b4525 100644 --- a/src/libs/qmljs/qmljscodeformatter.cpp +++ b/src/libs/qmljs/qmljscodeformatter.cpp @@ -645,6 +645,7 @@ bool CodeFormatter::tryStatement() return true; case Break: case Continue: + enter(breakcontinue_statement); leave(true); return true; case Throw: diff --git a/src/libs/qmljs/qmljscodeformatter.h b/src/libs/qmljs/qmljscodeformatter.h index aad77a5f527..da22601bcfa 100644 --- a/src/libs/qmljs/qmljscodeformatter.h +++ b/src/libs/qmljs/qmljscodeformatter.h @@ -143,7 +143,8 @@ public: // must be public to make Q_GADGET introspection work jsblock_open, - empty_statement, // for a ';', will never linger + empty_statement, // for a ';', will be popped directly + breakcontinue_statement, // for continue/break, will be popped directly if_statement, // After 'if' maybe_else, // after the first substatement in an if diff --git a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp index 5e1f4c29e70..9b0d05d12e6 100644 --- a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp +++ b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp @@ -31,6 +31,7 @@ private Q_SLOTS: void ifStatementWithoutBraces2(); void ifStatementWithBraces1(); void ifStatementWithBraces2(); + void ifStatementWithBraces3(); void ifStatementMixed(); void ifStatementAndComments(); void ifStatementLongCondition(); @@ -543,6 +544,18 @@ void tst_QMLCodeFormatter::ifStatementWithBraces2() checkIndent(data); } +void tst_QMLCodeFormatter::ifStatementWithBraces3() +{ + QList data; + data << Line("function foo() {") + << Line(" if (a) {") + << Line(" continue") + << Line(" }") + << Line(" var foo") + << Line("}"); + checkIndent(data); +} + void tst_QMLCodeFormatter::ifStatementMixed() { QList data;