diff options
-rw-r--r-- | tests/auto/qml/qmlformat/data/emptyObject.formatted.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qmlformat/data/emptyObject.qml | 3 | ||||
-rw-r--r-- | tests/auto/qml/qmlformat/tst_qmlformat.cpp | 2 | ||||
-rw-r--r-- | tools/qmlformat/dumpastvisitor.cpp | 4 |
4 files changed, 14 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlformat/data/emptyObject.formatted.qml b/tests/auto/qml/qmlformat/data/emptyObject.formatted.qml new file mode 100644 index 0000000000..a3c345db24 --- /dev/null +++ b/tests/auto/qml/qmlformat/data/emptyObject.formatted.qml @@ -0,0 +1,5 @@ +Item { + binding: { + var emptyObject = {}; + } +} diff --git a/tests/auto/qml/qmlformat/data/emptyObject.qml b/tests/auto/qml/qmlformat/data/emptyObject.qml new file mode 100644 index 0000000000..6855003fcd --- /dev/null +++ b/tests/auto/qml/qmlformat/data/emptyObject.qml @@ -0,0 +1,3 @@ +Item { + binding: { var emptyObject = {}; } +} diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp index 6f2410854a..45a51dec21 100644 --- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp +++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp @@ -235,6 +235,8 @@ void TestQmlformat::testFormat_data() << "forOf.formatted.qml" << false << true; QTest::newRow("property names") << "propertyNames.qml" << "propertyNames.formatted.qml" << false << true; + QTest::newRow("empty object") << "emptyObject.qml" + << "emptyObject.formatted.qml" << false << true; } void TestQmlformat::testFormat() diff --git a/tools/qmlformat/dumpastvisitor.cpp b/tools/qmlformat/dumpastvisitor.cpp index b3f3d4ce24..47ea76b119 100644 --- a/tools/qmlformat/dumpastvisitor.cpp +++ b/tools/qmlformat/dumpastvisitor.cpp @@ -493,6 +493,10 @@ QString DumpAstVisitor::parseExpression(ExpressionNode *expression) } case Node::Kind_ObjectPattern: { auto *objectPattern = cast<ObjectPattern*>(expression); + + if (objectPattern->properties == nullptr) + return "{}"; + QString result = "{\n"; m_indentLevel++; |