diff options
-rw-r--r-- | tests/auto/qml/qmlformat/data/propertyNames.formatted.qml | 14 | ||||
-rw-r--r-- | tests/auto/qml/qmlformat/data/propertyNames.qml | 13 | ||||
-rw-r--r-- | tests/auto/qml/qmlformat/tst_qmlformat.cpp | 7 | ||||
-rw-r--r-- | tools/qmlformat/dumpastvisitor.cpp | 6 |
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); + } } } |