diff options
| author | Olivier De Cannière <olivier.decanniere@qt.io> | 2026-09-30 10:50:55 +0200 |
|---|---|---|
| committer | Olivier De Cannière <olivier.decanniere@qt.io> | 2026-10-01 10:56:05 +0000 |
| commit | d33ed93fccc6cd187534736113b5c5df5cb48080 (patch) | |
| tree | f349be09c04dafee8c6f40ef8f86fed3ad1e2f9a | |
| parent | 0be90e31adc05fd34680e9629cbc8e2372c8a54a (diff) | |
qmlformat: Write the comma of each hole of an array, not the first one's
Task-number: QTBUG-151040
Pick-to: 6.12 6.8
Change-Id: I57586956dff6f83dfc947c1bd23eac5391b710d7
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
4 files changed, 8 insertions, 2 deletions
diff --git a/src/qmldom/qqmldomreformatter.cpp b/src/qmldom/qqmldomreformatter.cpp index 944bcea9de..d1c70d47c5 100644 --- a/src/qmldom/qqmldomreformatter.cpp +++ b/src/qmldom/qqmldomreformatter.cpp @@ -897,8 +897,8 @@ bool ScriptFormatter::visit(FunctionExpression *ast) bool ScriptFormatter::visit(Elision *ast) { for (Elision *it = ast; it; it = it->next) { - if (ast->commaToken.isValid()) { - outWithComments(ast->commaToken, ast); + if (it->commaToken.isValid()) { + outWithComments(it->commaToken, it); ensureSpaceIfNoComment(); } } diff --git a/tests/auto/qml/qmlformat/data/elisionCommaConfusion.formatted.js b/tests/auto/qml/qmlformat/data/elisionCommaConfusion.formatted.js new file mode 100644 index 0000000000..49f266ae3c --- /dev/null +++ b/tests/auto/qml/qmlformat/data/elisionCommaConfusion.formatted.js @@ -0,0 +1 @@ +[ /*1*/ , /*2*/ , /*3*/ , /*4*/ ]; diff --git a/tests/auto/qml/qmlformat/data/elisionCommaConfusion.js b/tests/auto/qml/qmlformat/data/elisionCommaConfusion.js new file mode 100644 index 0000000000..e5b01a5381 --- /dev/null +++ b/tests/auto/qml/qmlformat/data/elisionCommaConfusion.js @@ -0,0 +1,3 @@ + + +[ /*1*/ , /*2*/ , /*3*/ , /*4*/ ]; diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp index c882d58f20..0305a2018e 100644 --- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp +++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp @@ -117,6 +117,8 @@ void TestQmlformat::plainJS_data() << "caseWithComment.formatted.js"; QTest::newRow("longStatementList") << "longStatementList.js" << "longStatementList.formatted.js"; + QTest::newRow("elisionCommaConfusion") << "elisionCommaConfusion.js" + << "elisionCommaConfusion.formatted.js"; } void TestQmlformat::plainJS() |
