aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOlivier De Cannière <olivier.decanniere@qt.io>2026-09-30 10:52:13 +0200
committerOlivier De Cannière <olivier.decanniere@qt.io>2026-10-01 16:09:38 +0000
commit31d3946adb7ed34bf89eaf0843ceef00c7ad71f5 (patch)
tree33d304591559fee74d46ac2a70c0cbad6f531b33 /tests
parent420703a10d5990151ba5608eda74086eda351dce (diff)
qmlformat: Don't add extra commas to holed arrays
`[1, 2, 3, 4, , ,]` is parsed with the comma that comes before the trailing holes stored on two different nodes: on the ArrayPattern, and on the list element that wraps those holes. The formatter wrote both, so every pass over the file appended another hole to the array. That changes the semantics of the expression. Store the comma on the ArrayPattern only if it isn't already part of the elision. This also ensures missing spaces between commas in the array. Amends d41f97e86702d8c5ac81a4246e1aab8dd965cbe4 Task-number: QTBUG-151040 Pick-to: 6.12 Change-Id: Ied05c0100210b0b2d06cf69a4fe55ee565239730 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qmlformat/data/holedArrayExtraCommas.formatted.js1
-rw-r--r--tests/auto/qml/qmlformat/data/holedArrayExtraCommas.js3
-rw-r--r--tests/auto/qml/qmlformat/tst_qmlformat.cpp2
3 files changed, 6 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlformat/data/holedArrayExtraCommas.formatted.js b/tests/auto/qml/qmlformat/data/holedArrayExtraCommas.formatted.js
new file mode 100644
index 0000000000..7b79ac117c
--- /dev/null
+++ b/tests/auto/qml/qmlformat/data/holedArrayExtraCommas.formatted.js
@@ -0,0 +1 @@
+[1, , , , [1, 2, 3], ,];
diff --git a/tests/auto/qml/qmlformat/data/holedArrayExtraCommas.js b/tests/auto/qml/qmlformat/data/holedArrayExtraCommas.js
new file mode 100644
index 0000000000..78b5ed7b8a
--- /dev/null
+++ b/tests/auto/qml/qmlformat/data/holedArrayExtraCommas.js
@@ -0,0 +1,3 @@
+
+
+[1, , , , [1, 2, 3], ,];
diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp
index 0305a2018e..17a2b1cbdc 100644
--- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp
+++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp
@@ -119,6 +119,8 @@ void TestQmlformat::plainJS_data()
<< "longStatementList.formatted.js";
QTest::newRow("elisionCommaConfusion") << "elisionCommaConfusion.js"
<< "elisionCommaConfusion.formatted.js";
+ QTest::newRow("holedArrayExtraCommas") << "holedArrayExtraCommas.js"
+ << "holedArrayExtraCommas.formatted.js";
}
void TestQmlformat::plainJS()