diff options
| author | Sami Shalayel <sami.shalayel@qt.io> | 2025-03-14 15:17:39 +0100 |
|---|---|---|
| committer | Sami Shalayel <sami.shalayel@qt.io> | 2025-05-20 16:04:51 +0100 |
| commit | e0c4a35a10ef50f44955f9c0ae2ae30eace5cb21 (patch) | |
| tree | 5817751c46533baf4322fb3f281ce98ce9493b89 /src/qmlcompiler/qqmljsimportvisitor.cpp | |
| parent | 6864d9a1b8326bc031d3736a9a9d637698e0ebc5 (diff) | |
QQmlSA: extend ScriptBindingValueType for function bindings
In QtC, ErrBlocksNotSupportedInQmlUi is supposed to warn about function
blocks when used in bindings. We can't detect function blocks with the
QQmlSA infrastructure because we don't have access to the AST, but we
still can actually detect bindings to function blocks.
Extend ScriptBindingValueType to be able to recognize bindings that
contain functions (JS blocks, arrow functions and lambdas). Extend the
QQmlSA interface to find out if a binding contains a function so that
qdslintplugin can use it in a later commit.
Task-number: QTBUG-129308
Change-Id: Ic46ad6faf7a04d805084db2d9353b009e881d4dd
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsimportvisitor.cpp')
| -rw-r--r-- | src/qmlcompiler/qqmljsimportvisitor.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp index 58b685435e..85b67d474c 100644 --- a/src/qmlcompiler/qqmljsimportvisitor.cpp +++ b/src/qmlcompiler/qqmljsimportvisitor.cpp @@ -2079,7 +2079,7 @@ QQmlJSImportVisitor::parseBindingExpression(const QString &name, QQmlJSMetaPropertyBinding binding(location, name); binding.setScriptBinding(addFunctionOrExpression(m_currentScope, name), - QQmlSA::ScriptBindingKind::PropertyBinding); + QQmlSA::ScriptBindingKind::PropertyBinding, ScriptValue_Function); m_bindings.append(UnfinishedBinding { m_currentScope, [binding = std::move(binding)]() { return binding; } @@ -2092,7 +2092,7 @@ QQmlJSImportVisitor::parseBindingExpression(const QString &name, combine(expr->firstSourceLocation(), expr->lastSourceLocation()), name); - bool isUndefinedBinding = false; + ScriptBindingValueType scriptBindingValuetype = ScriptValue_Unknown; switch (expr->kind) { case Node::Kind_TrueLiteral: @@ -2107,7 +2107,14 @@ QQmlJSImportVisitor::parseBindingExpression(const QString &name, case Node::Kind_IdentifierExpression: { auto idExpr = QQmlJS::AST::cast<QQmlJS::AST::IdentifierExpression *>(expr); Q_ASSERT(idExpr); - isUndefinedBinding = (idExpr->name == u"undefined"); + if (idExpr->name == u"undefined") + scriptBindingValuetype = ScriptValue_Undefined; + break; + } + case Node::Kind_FunctionDeclaration: + case Node::Kind_FunctionExpression: + case Node::Kind_Block: { + scriptBindingValuetype = ScriptValue_Function; break; } case Node::Kind_NumericLiteral: @@ -2149,8 +2156,7 @@ QQmlJSImportVisitor::parseBindingExpression(const QString &name, // consider this to be a script binding (see IRBuilder::setBindingValue) binding.setScriptBinding(addFunctionOrExpression(m_currentScope, name), QQmlSA::ScriptBindingKind::PropertyBinding, - isUndefinedBinding ? ScriptBindingValueType::ScriptValue_Undefined - : ScriptBindingValueType::ScriptValue_Unknown); + scriptBindingValuetype); } m_bindings.append(UnfinishedBinding { m_currentScope, [=]() { return binding; } }); @@ -2369,7 +2375,7 @@ bool QQmlJSImportVisitor::visit(UiScriptBinding *scriptBinding) } QQmlJSMetaPropertyBinding binding(firstSourceLocation, name); - binding.setScriptBinding(index, kind); + binding.setScriptBinding(index, kind, ScriptValue_Function); return binding; }; m_bindings.append(UnfinishedBinding { m_currentScope, createBinding }); |
