qmlformat: Handle pragma directive correctly
Dom representation for pragma used to be created by leaving out pragma directive value list. That caused qmlformat to remove the corresponding list. Fix it by including value list while creating dom for pragma. Fixes: QTBUG-114364 Pick-to: 6.5 6.6 Change-Id: I87f6e324452f196c147f5606f15c01e22caa39a5 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
This commit is contained in:
parent
ca307bd9a7
commit
38da583642
|
@ -311,7 +311,11 @@ void QQmlDomAstCreator::endVisit(AST::UiProgram *)
|
|||
|
||||
bool QQmlDomAstCreator::visit(UiPragma *el)
|
||||
{
|
||||
createMap(DomType::Pragma, qmlFilePtr->addPragma(Pragma(el->name.toString())), el);
|
||||
QStringList valueList;
|
||||
for (auto t = el->values; t; t = t->next)
|
||||
valueList << t->value.toString();
|
||||
|
||||
createMap(DomType::Pragma, qmlFilePtr->addPragma(Pragma(el->name.toString(), valueList)), el);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1902,6 +1902,19 @@ void Pragma::writeOut(DomItem &, OutWriter &ow) const
|
|||
{
|
||||
ow.ensureNewline();
|
||||
ow.writeRegion(u"pragma").space().writeRegion(u"name", name);
|
||||
|
||||
bool isFirst = true;
|
||||
for (const auto &value : values) {
|
||||
if (isFirst) {
|
||||
isFirst = false;
|
||||
ow.writeRegion(u"colon", u": ");
|
||||
ow.writeRegion(u"values", value);
|
||||
continue;
|
||||
}
|
||||
|
||||
ow.writeRegion(u"comma", u", ");
|
||||
ow.writeRegion(u"values", value);
|
||||
}
|
||||
ow.ensureNewline();
|
||||
}
|
||||
|
||||
|
|
|
@ -337,11 +337,15 @@ class QMLDOM_EXPORT Pragma
|
|||
public:
|
||||
constexpr static DomType kindValue = DomType::Pragma;
|
||||
|
||||
Pragma(QString pragmaName = QString()) : name(pragmaName) { }
|
||||
Pragma(QString pragmaName = QString(), const QStringList &pragmaValues = {})
|
||||
: name(pragmaName), values{ pragmaValues }
|
||||
{
|
||||
}
|
||||
|
||||
bool iterateDirectSubpaths(DomItem &self, DirectVisitor visitor)
|
||||
{
|
||||
bool cont = self.dvValueField(visitor, Fields::name, name);
|
||||
cont = cont && self.dvValueField(visitor, Fields::values, values);
|
||||
cont = cont && self.dvWrapField(visitor, Fields::comments, comments);
|
||||
return cont;
|
||||
}
|
||||
|
@ -349,6 +353,7 @@ public:
|
|||
void writeOut(DomItem &self, OutWriter &ow) const;
|
||||
|
||||
QString name;
|
||||
QStringList values;
|
||||
RegionComments comments;
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
pragma Singleton
|
||||
pragma ComponentBehavior: Bound
|
||||
pragma FunctionSignatureBehavior: Enforced
|
||||
pragma ValueTypeBehavior: Copy, Addressable
|
||||
import QtQml
|
||||
|
||||
QtObject {
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
pragma Singleton
|
||||
pragma ComponentBehavior: Bound
|
||||
pragma FunctionSignatureBehavior: Enforced
|
||||
pragma ValueTypeBehavior: Copy, Addressable
|
||||
|
||||
import QtQml
|
||||
|
||||
QtObject {}
|
Loading…
Reference in New Issue