diff options
author | Semih Yavuz <semih.yavuz@qt.io> | 2023-01-18 15:36:23 +0100 |
---|---|---|
committer | Semih Yavuz <semih.yavuz@qt.io> | 2023-01-24 11:25:42 +0100 |
commit | a11eeea7bc8c628e33dd6efe28df27724a9b7f77 (patch) | |
tree | ef5ebbd2c12c6fd66b852fa2d191fa247f39bf66 | |
parent | 2135f6b2aa816b57b43a0863d4d284c715433ee8 (diff) |
qmlformat: fix omitting some comments while reformatting
We rewrite comments associated to a node on the preVisit call
(if they were marked as preComment), or postVisit( if comments were
marked as postComments) of the reformatter. If the comment
associated with a patternProperty kind of node, neither of these
functions are called. Add missing call to previsit/postVist
in the pattern property node visit.
Fixes: QTBUG-109074
Change-Id: If57968b3f5dbd83aa23dc2cd2bca3608ee841d49
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit 444d4f1f3f27a81996d9cbcc0642040b68728260)
-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() |