diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2020-10-07 11:23:33 +0200 |
---|---|---|
committer | Maximilian Goldstein <max.goldstein@qt.io> | 2020-10-07 13:08:19 +0200 |
commit | 26fa3d2cef8ec55dfb276e999d41e01e9a846093 (patch) | |
tree | 25156d4c3cccc770399fb2dddea82ff376b788d3 | |
parent | 6857ad3e686a5e2b45d28a7f47dca3210608da50 (diff) |
qmlformat: Make empty objects one liners
Fixes: QTBUG-87181
Change-Id: Ic8b7f69b4f9faf907ec75f27b689ba3686eb013f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-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++; |