aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljsimportvisitor.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-12-06 14:48:05 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2021-12-07 21:51:52 +0100
commit30251c0781abe8c520978e5e14fe9c5a6119c1a2 (patch)
tree59ac1e76c77f277578d0accbb0dd61d2f896f053 /src/qmlcompiler/qqmljsimportvisitor.cpp
parentb607ae8bdac1392790c3d5f53020a489d23e7ba3 (diff)
qmllint: handle string template literals
A template string is always a string, so we can check it as such. If there are no substitutions, the resulting binding is a string literal binding, otherwise it is a script binding. Change-Id: Iecbaed04bfee517668788552af659c9e81d92f71 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsimportvisitor.cpp')
-rw-r--r--src/qmlcompiler/qqmljsimportvisitor.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp
index 11f46ce0ee..69c40790d9 100644
--- a/src/qmlcompiler/qqmljsimportvisitor.cpp
+++ b/src/qmlcompiler/qqmljsimportvisitor.cpp
@@ -1369,12 +1369,25 @@ void QQmlJSImportVisitor::parseLiteralBinding(const QString name,
value = cast<RegExpLiteral *>(exprStatement->expression)->pattern.toString();
bindingType = QQmlJSMetaPropertyBinding::RegExpLiteral;
break;
+ case Node::Kind_TemplateLiteral: {
+ auto templateLit = QQmlJS::AST::cast<QQmlJS::AST::TemplateLiteral *>(exprStatement->expression);
+ Q_ASSERT(templateLit);
+ value = templateLit->value.toString();
+ if (templateLit->hasNoSubstitution) {
+ literalType = u"string"_qs;
+ bindingType = QQmlJSMetaPropertyBinding::StringLiteral;
+ } else {
+ bindingType = QQmlJSMetaPropertyBinding::Script;
+ }
+ break;
+ }
default:
return;
}
- if (!m_rootScopeImports.contains(literalType))
+ if (!QQmlJSMetaPropertyBinding::isLiteralBinding(bindingType))
return;
+ Q_ASSERT(m_rootScopeImports.contains(literalType)); // built-ins must contain support for all literal bindings
QQmlJSMetaPropertyBinding binding(name);
binding.setLiteral(bindingType, literalType, value, m_rootScopeImports[literalType]);