Properly mark composite singletons in QQmlJSImporter

Change-Id: I9063765b37528489a8e350fe63b2babdd038fe1a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Ulf Hermann 2021-03-25 14:27:35 +01:00
parent d009c0088b
commit 213adb6692
7 changed files with 49 additions and 2 deletions

View File

@ -152,8 +152,12 @@ QQmlJSImporter::Import QQmlJSImporter::readQmldir(const QString &path)
} }
auto mo = qmlComponents.find(it.key()); auto mo = qmlComponents.find(it.key());
if (mo == qmlComponents.end()) if (mo == qmlComponents.end()) {
mo = qmlComponents.insert(it.key(), localFile2ScopeTree(filePath)); QQmlJSScope::Ptr imported = localFile2ScopeTree(filePath);
if (it->singleton)
imported->setIsSingleton(true);
mo = qmlComponents.insert(it.key(), imported);
}
(*mo)->addExport(it.key(), reader.typeNamespace(), it->version); (*mo)->addExport(it.key(), reader.typeNamespace(), it->version);
} }

View File

@ -0,0 +1,10 @@
pragma Singleton
import QtQuick 2.0
QtObject {
readonly property string stringProp: "stringValue"
readonly property int intProp: 10
readonly property real realProp: 4.5
readonly property color colorProp: "green"
readonly property bool boolProp: true
}

View File

@ -0,0 +1,9 @@
import QtQuick 2.0
QtObject {
readonly property string stringProp: "stringValue"
readonly property int intProp: 10
readonly property real realProp: 4.5
readonly property color colorProp: "green"
readonly property bool boolProp: true
}

View File

@ -0,0 +1,3 @@
module QmlBench
singleton Globals 1.0 Globals.qml
Locals 1.0 Locals.qml

View File

@ -0,0 +1,8 @@
import QtQml
import QmlBench
QtObject {
property real x: Globals.realProp
property real y: Globals.intProp
property bool smooth: Globals.boolProp
}

View File

@ -0,0 +1,6 @@
import QtQml
import QmlBench
QtObject {
property real x: Locals.realProp
}

View File

@ -520,6 +520,11 @@ void TestQmllint::dirtyQmlCode_data()
<< QStringLiteral("Unused import at %1:1:1") << QStringLiteral("Unused import at %1:1:1")
<< QString() << QString()
<< true; << true;
QTest::newRow("TypePropertAccess")
<< QStringLiteral("typePropertyAccess.qml")
<< QString()
<< QString()
<< false;
} }
void TestQmllint::dirtyQmlCode() void TestQmllint::dirtyQmlCode()
@ -537,6 +542,7 @@ void TestQmllint::dirtyQmlCode()
QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitStatus(), QProcess::NormalExit);
QEXPECT_FAIL("anchors3", "We don't see that QQuickItem cannot be assigned to QQuickAnchorLine", Abort); QEXPECT_FAIL("anchors3", "We don't see that QQuickItem cannot be assigned to QQuickAnchorLine", Abort);
QEXPECT_FAIL("nanchors1", "Invalid grouped properties are not always detected", Abort); QEXPECT_FAIL("nanchors1", "Invalid grouped properties are not always detected", Abort);
QEXPECT_FAIL("TypePropertAccess", "We cannot discern between types and instances", Abort);
if (exitsNormally) if (exitsNormally)
QVERIFY(process.exitCode() == 0); QVERIFY(process.exitCode() == 0);
@ -600,6 +606,7 @@ void TestQmllint::cleanQmlCode_data()
QTest::newRow("duplicateQmldirImport") << QStringLiteral("qmldirImport/duplicate.qml"); QTest::newRow("duplicateQmldirImport") << QStringLiteral("qmldirImport/duplicate.qml");
QTest::newRow("Used imports") << QStringLiteral("used.qml"); QTest::newRow("Used imports") << QStringLiteral("used.qml");
QTest::newRow("Unused imports (multi)") << QStringLiteral("unused_multi.qml"); QTest::newRow("Unused imports (multi)") << QStringLiteral("unused_multi.qml");
QTest::newRow("compositeSingleton") << QStringLiteral("compositesingleton.qml");
} }
void TestQmllint::cleanQmlCode() void TestQmllint::cleanQmlCode()