diff options
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 6 | ||||
-rw-r--r-- | src/qml/parser/qqmljs.g | 9 | ||||
-rw-r--r-- | src/qml/parser/qqmljsast_p.h | 1 | ||||
-rw-r--r-- | tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp | 17 | ||||
-rw-r--r-- | tests/auto/quick/examples/BLACKLIST | 4 |
5 files changed, 32 insertions, 5 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index e2e9d15479..3b1d9f4595 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -1114,6 +1114,12 @@ void IRBuilder::setBindingValue(QV4::CompiledData::Binding *binding, QQmlJS::AST if (QQmlJS::AST::StringLiteral *lit = QQmlJS::AST::cast<QQmlJS::AST::StringLiteral *>(expr)) { binding->type = QV4::CompiledData::Binding::Type_String; binding->stringIndex = registerString(lit->value.toString()); + } else if (QQmlJS::AST::TemplateLiteral *templateLit = QQmlJS::AST::cast<QQmlJS::AST::TemplateLiteral *>(expr); + templateLit && templateLit->hasNoSubstitution) { + // A template literal without substitution is just a string. + // With substitution, it could however be an arbitrarily complex expression + binding->type = QV4::CompiledData::Binding::Type_String; + binding->stringIndex = registerString(templateLit->value.toString()); } else if (expr->kind == QQmlJS::AST::Node::Kind_TrueLiteral) { binding->type = QV4::CompiledData::Binding::Type_Boolean; binding->value.b = true; diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g index eb082b77c2..670564fea5 100644 --- a/src/qml/parser/qqmljs.g +++ b/src/qml/parser/qqmljs.g @@ -2246,7 +2246,14 @@ InitializerOpt: Initializer; InitializerOpt_In: Initializer_In; TemplateLiteral: T_NO_SUBSTITUTION_TEMPLATE; -/. case $rule_number: Q_FALLTHROUGH(); ./ +/. + case $rule_number: { + AST::TemplateLiteral *node = new (pool) AST::TemplateLiteral(stringRef(1), rawStringRef(1), nullptr); + node->literalToken = loc(1); + node->hasNoSubstitution = true; + sym(1).Node = node; + } break; +./ TemplateSpans: T_TEMPLATE_TAIL; /. diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h index d7b4f2a8be..bd4e225412 100644 --- a/src/qml/parser/qqmljsast_p.h +++ b/src/qml/parser/qqmljsast_p.h @@ -735,6 +735,7 @@ public: void accept0(BaseVisitor *visitor) override; + bool hasNoSubstitution = false; QStringView value; QStringView rawValue; ExpressionNode *expression; diff --git a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp index 150fb82ca6..a9b6ec03a4 100644 --- a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp +++ b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp @@ -135,6 +135,7 @@ private slots: void objectDestroyed(); void destroyObject(); void emptyStringNotUndefined(); + void listElementWithTemplateString(); }; bool tst_qqmllistmodel::compareVariantList(const QVariantList &testList, QVariant object) @@ -1839,6 +1840,22 @@ void tst_qqmllistmodel::emptyStringNotUndefined() QCOMPARE(val.toString(), QString()); } +void tst_qqmllistmodel::listElementWithTemplateString() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData(R"( + import QtQuick + ListModel { + ListElement { + prop: `test` + } + })", QUrl()); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + QScopedPointer<QObject> root(component.create()); + QVERIFY(!root.isNull()); +} + QTEST_MAIN(tst_qqmllistmodel) #include "tst_qqmllistmodel.moc" diff --git a/tests/auto/quick/examples/BLACKLIST b/tests/auto/quick/examples/BLACKLIST index 14abb3099a..a4e374347e 100644 --- a/tests/auto/quick/examples/BLACKLIST +++ b/tests/auto/quick/examples/BLACKLIST @@ -1,7 +1,3 @@ -# QTBUG-95139 -[sgexamples:examples/quick/views/listview/expandingdelegates.qml] -* - # The following rely on qtquickcontrols2, and can be unblacklisted once QTBUG-95173 is done. [sgexamples:examples/quick/canvas/bezierCurve/bezierCurve.qml] * |