aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-07-23 13:11:01 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-07-23 17:53:48 +0000
commit1d0ef3135fdb1c0d0f6577afde3f31476ae0cb7f (patch)
tree1a8213c6414817f5b55c7c1659980da8d01d078a
parentf17866815548cce413aa2848635a68164270160c (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 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> (cherry picked from commit e8121d93003f621a6d91e32c1539945a0779745a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_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 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]
*