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.6 6.5 Change-Id: I2bc82f65d95c3cd09ad846c60dd7561ac03efad3 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
This commit is contained in:
parent
38c941bc55
commit
640ff3d812
|
@ -1046,17 +1046,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue