diff options
-rw-r--r-- | tests/auto/qml/qmlformat/data/forOf.formatted.qml | 9 | ||||
-rw-r--r-- | tests/auto/qml/qmlformat/data/forOf.qml | 12 | ||||
-rw-r--r-- | tests/auto/qml/qmlformat/tst_qmlformat.cpp | 2 | ||||
-rw-r--r-- | tools/qmlformat/dumpastvisitor.cpp | 5 |
4 files changed, 27 insertions, 1 deletions
diff --git a/tests/auto/qml/qmlformat/data/forOf.formatted.qml b/tests/auto/qml/qmlformat/data/forOf.formatted.qml new file mode 100644 index 0000000000..fa29f16b81 --- /dev/null +++ b/tests/auto/qml/qmlformat/data/forOf.formatted.qml @@ -0,0 +1,9 @@ +import QtQml 2.0 + +QtObject { + Component.onCompleted: { + var list = [[1, 2], [3, 4], [5, 6]]; + for (const [x, y] of list) console.log("X: " + x + "; Y: " + y) + for (let [x, y] of list) console.log("X: " + x + "; Y: " + y) + } +} diff --git a/tests/auto/qml/qmlformat/data/forOf.qml b/tests/auto/qml/qmlformat/data/forOf.qml new file mode 100644 index 0000000000..0c3be0d2a2 --- /dev/null +++ b/tests/auto/qml/qmlformat/data/forOf.qml @@ -0,0 +1,12 @@ +import QtQml 2.0 + +QtObject { + Component.onCompleted: { + var list = [[1,2],[3,4],[5,6]]; + + for (const [x,y] of list) + console.log("X: "+x+"; Y: "+y); + for (let [x,y] of list) + console.log("X: "+x+"; Y: "+y); + } +} diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp index c1c248e413..34ce8597e3 100644 --- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp +++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp @@ -231,6 +231,8 @@ void TestQmlformat::testFormat_data() << "nestedFunctions.formatted.qml" << false << true; QTest::newRow("multiline comments") << "multilineComment.qml" << "multilineComment.formatted.qml" << false << true; + QTest::newRow("for of") << "forOf.qml" + << "forOf.formatted.qml" << false << true; } void TestQmlformat::testFormat() diff --git a/tools/qmlformat/dumpastvisitor.cpp b/tools/qmlformat/dumpastvisitor.cpp index 008f10ae17..aea4d78d36 100644 --- a/tools/qmlformat/dumpastvisitor.cpp +++ b/tools/qmlformat/dumpastvisitor.cpp @@ -236,7 +236,10 @@ QString DumpAstVisitor::parsePatternElement(PatternElement *element, bool scope) } } - result += element->bindingIdentifier.toString(); + if (element->bindingIdentifier.isEmpty()) + result += parseExpression(element->bindingTarget); + else + result += element->bindingIdentifier.toString(); if (element->typeAnnotation != nullptr) result += ": " + parseType(element->typeAnnotation->type); |