From d33ed93fccc6cd187534736113b5c5df5cb48080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20De=20Canni=C3=A8re?= Date: Wed, 30 Sep 2026 10:50:55 +0200 Subject: 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 --- src/qmldom/qqmldomreformatter.cpp | 4 ++-- tests/auto/qml/qmlformat/data/elisionCommaConfusion.formatted.js | 1 + tests/auto/qml/qmlformat/data/elisionCommaConfusion.js | 3 +++ tests/auto/qml/qmlformat/tst_qmlformat.cpp | 2 ++ 4 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 tests/auto/qml/qmlformat/data/elisionCommaConfusion.formatted.js create mode 100644 tests/auto/qml/qmlformat/data/elisionCommaConfusion.js 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() -- cgit v1.2.3