aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Shalayel <sami.shalayel@qt.io>2023-09-06 17:07:21 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-09-11 23:36:12 +0000
commit03bd497190c331e27587beb2f324bf8673361aa8 (patch)
tree70b3fec60840040300d48a5f9da06911c99e8be6
parent9c1696bf514a1d31568aabbabf40db5434f8cf97 (diff)
FormalParameterList: prepare for qmlformat
Remove useless arg#0 bindingIdentifier from FormalParameterList. They are used nowhere, are not tested and are not even set correctly: FormalParameterList::finish() sets next to nullptr before its forloop that goes from this to this->next (that was freshly set to nullptr three lines above)... Instead of setting bindingIdentifier to arg#0 when its empty and testing for arg#, just test for bindingIdentifier being empty. That saves some trouble in qmlformat because you dont have to care about the position that the current method parameter has. Apropos position of the current parameter: qmlformat needs some context when doing its reformatting test, to avoid reparsing code in completely wrong contexts. Add missing preCode and postCode to MethodParameter to provide an artificial context for qmlformat, so it knows that it is working on a MethodParameter, and also teach qmlformat how to get the FormalParameter out of the artificial context, by extracting it from the FormalParameterList. Pick-to: 6.5 Change-Id: I2bc82f65d95c3cd09ad846c60dd7561ac03efad3 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> (cherry picked from commit 640ff3d8125264e25bd1826529b9a57cdddf2205) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qml/parser/qqmljsast.cpp9
-rw-r--r--src/qmldom/qqmldomelements.cpp6
-rw-r--r--src/qmldom/qqmldomreformatter.cpp2
3 files changed, 8 insertions, 9 deletions
diff --git a/src/qml/parser/qqmljsast.cpp b/src/qml/parser/qqmljsast.cpp
index e3ed876473..2780a4885d 100644
--- a/src/qml/parser/qqmljsast.cpp
+++ b/src/qml/parser/qqmljsast.cpp
@@ -1049,17 +1049,10 @@ void FormalParameterList::accept0(BaseVisitor *visitor)
}
}
-FormalParameterList *FormalParameterList::finish(QQmlJS::MemoryPool *pool)
+FormalParameterList *FormalParameterList::finish(QQmlJS::MemoryPool *)
{
FormalParameterList *front = next;
next = nullptr;
-
- int i = 0;
- for (const FormalParameterList *it = this; it; it = it->next) {
- if (it->element && it->element->bindingIdentifier.isEmpty())
- it->element->bindingIdentifier = pool->newString(QLatin1String("arg#") + QString::number(i));
- ++i;
- }
return front;
}
diff --git a/src/qmldom/qqmldomelements.cpp b/src/qmldom/qqmldomelements.cpp
index 42e5446637..f1edda137a 100644
--- a/src/qmldom/qqmldomelements.cpp
+++ b/src/qmldom/qqmldomelements.cpp
@@ -1664,6 +1664,9 @@ void ScriptExpression::setCode(QString code, QString preCode, QString postCode)
if (!m_preCode.isEmpty())
m_ast = firstNodeInRange(m_ast, m_preCode.size(),
m_preCode.size() + m_code.size());
+ if (auto *sList = AST::cast<AST::FormalParameterList *>(m_ast)) {
+ m_ast = sList->element;
+ }
if (m_expressionType != ExpressionType::FunctionBody) {
if (AST::StatementList *sList = AST::cast<AST::StatementList *>(m_ast)) {
if (!sList->next)
@@ -1872,6 +1875,9 @@ bool MethodParameter::iterateDirectSubpaths(DomItem &self, DirectVisitor visitor
cont = cont && self.dvWrapField(visitor, Fields::defaultValue, defaultValue);
cont = cont && self.dvWrapField(visitor, Fields::value, value);
+ cont = cont && self.dvValueField(visitor, Fields::preCode, u"function f("_s);
+ cont = cont && self.dvValueField(visitor, Fields::postCode, u") {}"_s);
+
if (!annotations.isEmpty())
cont = cont && self.dvWrapField(visitor, Fields::annotations, annotations);
cont = cont && self.dvWrapField(visitor, Fields::comments, comments);
diff --git a/src/qmldom/qqmldomreformatter.cpp b/src/qmldom/qqmldomreformatter.cpp
index fcc847591d..a925fe3bbe 100644
--- a/src/qmldom/qqmldomreformatter.cpp
+++ b/src/qmldom/qqmldomreformatter.cpp
@@ -983,7 +983,7 @@ protected:
{
for (FormalParameterList *it = ast; it; it = it->next) {
// compare FormalParameterList::finish
- if (auto id = it->element->bindingIdentifier.toString(); !id.startsWith(u"arg#"))
+ if (auto id = it->element->bindingIdentifier.toString(); !id.isEmpty())
out(id);
if (it->element->bindingTarget)
accept(it->element->bindingTarget);