aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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.cpp2
-rw-r--r--tools/qmlformat/dumpastvisitor.cpp6
4 files changed, 34 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 34ce8597e3..6f2410854a 100644
--- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp
+++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp
@@ -233,6 +233,8 @@ void TestQmlformat::testFormat_data()
<< "multilineComment.formatted.qml" << false << true;
QTest::newRow("for of") << "forOf.qml"
<< "forOf.formatted.qml" << false << true;
+ QTest::newRow("property names") << "propertyNames.qml"
+ << "propertyNames.formatted.qml" << false << true;
}
void TestQmlformat::testFormat()
diff --git a/tools/qmlformat/dumpastvisitor.cpp b/tools/qmlformat/dumpastvisitor.cpp
index aea4d78d36..b3f3d4ce24 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);
+ }
}
}