diff options
-rw-r--r-- | src/qmldom/qqmldomreformatter.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qml/qmlformat/data/dontRemoveComments.formatted.qml | 13 | ||||
-rw-r--r-- | tests/auto/qml/qmlformat/data/dontRemoveComments.qml | 13 | ||||
-rw-r--r-- | tests/auto/qml/qmlformat/tst_qmlformat.cpp | 3 |
4 files changed, 31 insertions, 0 deletions
diff --git a/src/qmldom/qqmldomreformatter.cpp b/src/qmldom/qqmldomreformatter.cpp index bb76f8f772..3dfacfc84e 100644 --- a/src/qmldom/qqmldomreformatter.cpp +++ b/src/qmldom/qqmldomreformatter.cpp @@ -301,6 +301,7 @@ protected: for (PatternPropertyList *it = ast; it; it = it->next) { PatternProperty *assignment = AST::cast<PatternProperty *>(it->property); if (assignment) { + preVisit(assignment); bool isStringLike = AST::cast<StringLiteralPropertyName *>(assignment->name) || cast<IdentifierPropertyName *>(assignment->name); if (isStringLike) @@ -316,6 +317,7 @@ protected: accept(assignment->initializer); if (it->next) newLine(); + postVisit(assignment); continue; } PatternPropertyList *getterSetter = AST::cast<PatternPropertyList *>(it->next); diff --git a/tests/auto/qml/qmlformat/data/dontRemoveComments.formatted.qml b/tests/auto/qml/qmlformat/data/dontRemoveComments.formatted.qml new file mode 100644 index 0000000000..0c7a2829c9 --- /dev/null +++ b/tests/auto/qml/qmlformat/data/dontRemoveComments.formatted.qml @@ -0,0 +1,13 @@ +Item { + property var test: [{ + // Testing + "foo": "bar" + }] + + onTestChanged: { + fooBar(test, { + // Testing + "foo": "bar" + }); + } +} diff --git a/tests/auto/qml/qmlformat/data/dontRemoveComments.qml b/tests/auto/qml/qmlformat/data/dontRemoveComments.qml new file mode 100644 index 0000000000..1797834879 --- /dev/null +++ b/tests/auto/qml/qmlformat/data/dontRemoveComments.qml @@ -0,0 +1,13 @@ +Item { + property var test: [{ +// Testing + "foo": "bar" + }] + + onTestChanged: { + fooBar(test, { + // Testing + "foo": "bar" + }); + } +} diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp index e95673221a..bc59b8dce1 100644 --- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp +++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp @@ -276,6 +276,9 @@ void TestQmlformat::testFormat_data() QTest::newRow("forWithLet") << "forWithLet.qml" << "forWithLet.formatted.qml" << QStringList {} << RunOption::OnCopy; + QTest::newRow("dontRemoveComments") + << "dontRemoveComments.qml" + << "dontRemoveComments.formatted.qml" << QStringList {} << RunOption::OnCopy; } void TestQmlformat::testFormat() |