aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-02-18 10:32:53 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-02-19 13:14:16 +0100
commite59957d2c46bb52ab5fefeb91ace7e192558373a (patch)
tree30d00552dff87d66a376df7f35706c7e7ffd52ab /src
parent33937b28180d8e653e47b9e34c03972553976c6f (diff)
qmllint: Resolve attached property scopes
Previously, all attached property scopes were just ignored. Task-number: QTBUG-84369 Change-Id: I324becf92402eacea9d150e6e51359edae562dde Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit f34ecc8f99522b69d1aaa3d5d233add9ed9b6da9)
Diffstat (limited to 'src')
-rw-r--r--src/qmlcompiler/qqmljsimportvisitor.cpp16
-rw-r--r--src/qmlcompiler/qqmljsscope.cpp39
-rw-r--r--src/qmlcompiler/qqmljsscope_p.h4
3 files changed, 32 insertions, 27 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp
index a1de41e3ca..8b57ac9b54 100644
--- a/src/qmlcompiler/qqmljsimportvisitor.cpp
+++ b/src/qmlcompiler/qqmljsimportvisitor.cpp
@@ -52,7 +52,7 @@ void QQmlJSImportVisitor::enterEnvironment(QQmlJSScope::ScopeType type, const QS
const QQmlJS::SourceLocation &location)
{
m_currentScope = QQmlJSScope::create(type, m_currentScope);
- if (type == QQmlJSScope::GroupedPropertyScope)
+ if (type == QQmlJSScope::GroupedPropertyScope || type == QQmlJSScope::AttachedPropertyScope)
m_currentScope->setInternalName(name);
else
m_currentScope->setBaseTypeName(name);
@@ -136,7 +136,6 @@ bool QQmlJSImportVisitor::visit(UiObjectDefinition *definition)
void QQmlJSImportVisitor::endVisit(UiObjectDefinition *)
{
m_currentScope->resolveTypes(m_rootScopeImports);
- m_currentScope->resolveGroupedScopes();
leaveEnvironment();
}
@@ -261,16 +260,20 @@ bool QQmlJSImportVisitor::visit(UiScriptBinding *scriptBinding)
for (auto group = id; group->next; group = group->next) {
const QString name = group->name.toString();
- if (name.isEmpty() || name.front().isUpper())
- break; // TODO: uppercase grouped scopes are attached properties. Handle them.
+ if (name.isEmpty())
+ break;
- enterEnvironment(QQmlJSScope::GroupedPropertyScope, name, group->firstSourceLocation());
+ enterEnvironment(name.front().isUpper() ? QQmlJSScope::AttachedPropertyScope
+ : QQmlJSScope::GroupedPropertyScope,
+ name, group->firstSourceLocation());
}
// TODO: remember the actual binding, once we can process it.
- while (m_currentScope->scopeType() == QQmlJSScope::GroupedPropertyScope)
+ while (m_currentScope->scopeType() == QQmlJSScope::GroupedPropertyScope
+ || m_currentScope->scopeType() == QQmlJSScope::AttachedPropertyScope) {
leaveEnvironment();
+ }
if (!statement || !statement->expression->asFunctionDefinition()) {
enterEnvironment(QQmlJSScope::JSFunctionScope, QStringLiteral("binding"),
@@ -497,7 +500,6 @@ bool QQmlJSImportVisitor::visit(QQmlJS::AST::UiObjectBinding *uiob)
void QQmlJSImportVisitor::endVisit(QQmlJS::AST::UiObjectBinding *uiob)
{
m_currentScope->resolveTypes(m_rootScopeImports);
- m_currentScope->resolveGroupedScopes();
const QQmlJSScope::ConstPtr childScope = m_currentScope;
leaveEnvironment();
diff --git a/src/qmlcompiler/qqmljsscope.cpp b/src/qmlcompiler/qqmljsscope.cpp
index 1fe22ab5a8..64fa44ef82 100644
--- a/src/qmlcompiler/qqmljsscope.cpp
+++ b/src/qmlcompiler/qqmljsscope.cpp
@@ -237,28 +237,31 @@ void QQmlJSScope::resolveTypes(const QHash<QString, QQmlJSScope::ConstPtr> &cont
it->setParameterTypes(paramTypes);
}
-}
-void QQmlJSScope::resolveGroupedScopes()
-{
for (auto it = m_childScopes.begin(), end = m_childScopes.end(); it != end; ++it) {
QQmlJSScope::Ptr childScope = *it;
- if (childScope->scopeType() != QQmlJSScope::GroupedPropertyScope)
- continue;
-
- const QString propertyName = childScope->internalName();
- auto findProperty = [&](const QQmlJSScope *type) {
- auto propertyIt = type->m_properties.find(propertyName);
- if (propertyIt != type->m_properties.end()) {
- childScope->m_baseType = QQmlJSScope::ConstPtr(propertyIt->type());
- childScope->m_baseTypeName = propertyIt->typeName();
- return true;
+ switch (childScope->scopeType()) {
+ case QQmlJSScope::GroupedPropertyScope:
+ searchBaseAndExtensionTypes(this, [&](const QQmlJSScope *type) {
+ const auto propertyIt = type->m_properties.find(childScope->internalName());
+ if (propertyIt != type->m_properties.end()) {
+ childScope->m_baseType = QQmlJSScope::ConstPtr(propertyIt->type());
+ childScope->m_baseTypeName = propertyIt->typeName();
+ return true;
+ }
+ return false;
+ });
+ break;
+ case QQmlJSScope::AttachedPropertyScope:
+ if (const auto attachedBase = findType(childScope->internalName())) {
+ childScope->m_baseType = attachedBase->attachedType();
+ childScope->m_baseTypeName = attachedBase->attachedTypeName();
}
- return false;
- };
-
- searchBaseAndExtensionTypes(this, findProperty);
- childScope->resolveGroupedScopes();
+ break;
+ default:
+ break;
+ }
+ childScope->resolveTypes(contextualTypes);
}
}
diff --git a/src/qmlcompiler/qqmljsscope_p.h b/src/qmlcompiler/qqmljsscope_p.h
index 9cb08c655e..8f095cffbf 100644
--- a/src/qmlcompiler/qqmljsscope_p.h
+++ b/src/qmlcompiler/qqmljsscope_p.h
@@ -95,7 +95,8 @@ public:
JSFunctionScope,
JSLexicalScope,
QMLScope,
- GroupedPropertyScope
+ GroupedPropertyScope,
+ AttachedPropertyScope
};
enum class AccessSemantics {
@@ -260,7 +261,6 @@ public:
}
void resolveTypes(const QHash<QString, ConstPtr> &contextualTypes);
- void resolveGroupedScopes();
void setSourceLocation(const QQmlJS::SourceLocation &sourceLocation)
{