aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-07-23 13:11:01 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2021-07-23 16:34:55 +0200
commite8121d93003f621a6d91e32c1539945a0779745a (patch)
tree4087d497bf482a364ac98dbba6ff009f98e17781
parent4dc893bb7daf82c8198f7ebba0fbbb328eba9ca8 (diff)
Treat substitution free template string literals as string bindings
Before this change, they were treated as script bindings, which are less efficient, and could not be used in ListElement. Fixes: QTBUG-95139 Pick-to: 6.2 Change-Id: Ic66052c7f58b3ffdf1b7c0c169f42b4f99df62a1 Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r--src/qml/compiler/qqmlirbuilder.cpp6
-rw-r--r--src/qml/parser/qqmljs.g9
-rw-r--r--src/qml/parser/qqmljsast_p.h1
-rw-r--r--tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp17
-rw-r--r--tests/auto/quick/examples/BLACKLIST4
5 files changed, 32 insertions, 5 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp
index c623fcfd6e..e213f5dbe9 100644
--- a/src/qml/compiler/qqmlirbuilder.cpp
+++ b/src/qml/compiler/qqmlirbuilder.cpp
@@ -1125,6 +1125,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]
*