aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2020-10-07 10:24:29 +0200
committerMaximilian Goldstein <max.goldstein@qt.io>2020-10-07 13:03:04 +0200
commitb0ad53347fdb26c52c6c0456adf19b049a78ea3d (patch)
tree65b08e83439f6aad039be9f8145cb03faa1fe569
parent209209e6fddce1b8f8a1837a2e9f40b81f540158 (diff)
qmlformat: Fix computed property names
Fixes: QTBUG-87222 Change-Id: If1da02d503041009b82651e1087fb4a1bdd79d59 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 49391fcc41d871836868452b8300938d0b94f00e) Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--tests/auto/qml/qmlformat/data/propertyNames.formatted.qml14
-rw-r--r--tests/auto/qml/qmlformat/data/propertyNames.qml13
-rw-r--r--tests/auto/qml/qmlformat/tst_qmlformat.cpp7
-rw-r--r--tools/qmlformat/dumpastvisitor.cpp6
4 files changed, 39 insertions, 1 deletions
diff --git a/tests/auto/qml/qmlformat/data/propertyNames.formatted.qml b/tests/auto/qml/qmlformat/data/propertyNames.formatted.qml
new file mode 100644
index 0000000000..c7d50abb32
--- /dev/null
+++ b/tests/auto/qml/qmlformat/data/propertyNames.formatted.qml
@@ -0,0 +1,14 @@
+Item {
+ function x() {
+ var copiedItem = "copied value";
+ var computedItem = "computedName";
+ var obj = {
+ "identifierName": "identifier value",
+ "string name": "string value",
+ "Infinity": "numeric value",
+ [computedItem]: "computed value",
+ "copiedItem": copiedItem
+ };
+ }
+
+}
diff --git a/tests/auto/qml/qmlformat/data/propertyNames.qml b/tests/auto/qml/qmlformat/data/propertyNames.qml
new file mode 100644
index 0000000000..9214014889
--- /dev/null
+++ b/tests/auto/qml/qmlformat/data/propertyNames.qml
@@ -0,0 +1,13 @@
+Item {
+ function x() {
+ var copiedItem = "copied value";
+ var computedItem = "computedName";
+ var obj = {
+ identifierName: "identifier value",
+ "string name": "string value",
+ Infinity: "numeric value",
+ [computedItem]: "computed value",
+ copiedItem
+ };
+ }
+}
diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp
index 03b320c5c8..413dc5f8a5 100644
--- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp
+++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp
@@ -62,6 +62,7 @@ private Q_SLOTS:
void testNestedFunctions();
void testForOf();
+ void testPropertyNames();
#if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled
void testExample();
@@ -293,6 +294,12 @@ void TestQmlformat::testForOf()
readTestFile("forOf.formatted.qml"));
}
+void TestQmlformat::testPropertyNames()
+{
+ QCOMPARE(runQmlformat(testFile("propertyNames.qml"), false, true),
+ readTestFile("propertyNames.formatted.qml"));
+}
+
#if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled
void TestQmlformat::testExample_data()
{
diff --git a/tools/qmlformat/dumpastvisitor.cpp b/tools/qmlformat/dumpastvisitor.cpp
index 15777984d2..9b4449df31 100644
--- a/tools/qmlformat/dumpastvisitor.cpp
+++ b/tools/qmlformat/dumpastvisitor.cpp
@@ -298,7 +298,11 @@ QString DumpAstVisitor::parsePatternProperty(PatternProperty *property)
case PatternElement::Setter:
return "set "+parseFunctionExpression(cast<FunctionExpression *>(property->initializer), true);
default:
- return escapeString(property->name->asString())+": "+parsePatternElement(property, false);
+ if (property->name->kind == Node::Kind_ComputedPropertyName) {
+ return "["+parseExpression(cast<ComputedPropertyName *>(property->name)->expression)+"]: "+parsePatternElement(property, false);
+ } else {
+ return escapeString(property->name->asString())+": "+parsePatternElement(property, false);
+ }
}
}