QtQml: Respect import namespaces when importing scripts
Pick-to: 6.5 6.6 Fixes: QTBUG-113991 Change-Id: I47651f303bcb53dc214d5f6bc70f65bac32f1b09 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
8b1ee76623
commit
1c2ef41a88
|
@ -1053,12 +1053,14 @@ bool QQmlTypeData::resolveType(const QString &typeName, QTypeRevision &version,
|
|||
return true;
|
||||
}
|
||||
|
||||
void QQmlTypeData::scriptImported(const QQmlRefPointer<QQmlScriptBlob> &blob, const QV4::CompiledData::Location &location, const QString &qualifier, const QString &/*nameSpace*/)
|
||||
void QQmlTypeData::scriptImported(
|
||||
const QQmlRefPointer<QQmlScriptBlob> &blob, const QV4::CompiledData::Location &location,
|
||||
const QString &nameSpace, const QString &qualifier)
|
||||
{
|
||||
ScriptReference ref;
|
||||
ref.script = blob;
|
||||
ref.location = location;
|
||||
ref.qualifier = qualifier;
|
||||
ref.qualifier = qualifier.isEmpty() ? nameSpace : qualifier + QLatin1Char('.') + nameSpace;
|
||||
|
||||
m_scripts << ref;
|
||||
}
|
||||
|
|
|
@ -103,7 +103,9 @@ private:
|
|||
QQmlType::RegistrationType registrationType = QQmlType::AnyRegistrationType,
|
||||
bool *typeRecursionDetected = nullptr);
|
||||
|
||||
void scriptImported(const QQmlRefPointer<QQmlScriptBlob> &blob, const QV4::CompiledData::Location &location, const QString &qualifier, const QString &nameSpace) override;
|
||||
void scriptImported(
|
||||
const QQmlRefPointer<QQmlScriptBlob> &blob, const QV4::CompiledData::Location &location,
|
||||
const QString &nameSpace, const QString &qualifier) override;
|
||||
|
||||
SourceCodeData m_backupSourceCode; // used when cache verification fails.
|
||||
QScopedPointer<QmlIR::Document> m_document;
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
.pragma library
|
||||
.import QtQuick as QtQuick
|
||||
|
||||
var exampleVar = 12;
|
|
@ -0,0 +1,2 @@
|
|||
module MyModuleName
|
||||
Font 0.1 Font.js
|
|
@ -0,0 +1,8 @@
|
|||
import QtQuick
|
||||
import 'MyModuleName' as MyModuleName
|
||||
|
||||
Item {
|
||||
property var a: MyModuleName.Font.exampleVar
|
||||
property var b: Font.SmallCaps
|
||||
property var c: Font.exampleVar
|
||||
}
|
|
@ -38,6 +38,7 @@ private slots:
|
|||
void invalidFileImport_data();
|
||||
void invalidFileImport();
|
||||
void implicitWithDependencies();
|
||||
void qualifiedScriptImport();
|
||||
};
|
||||
|
||||
void tst_QQmlImport::cleanup()
|
||||
|
@ -123,6 +124,19 @@ void tst_QQmlImport::implicitWithDependencies()
|
|||
QCOMPARE(o->objectName(), QStringLiteral("notARectangle"));
|
||||
}
|
||||
|
||||
void tst_QQmlImport::qualifiedScriptImport()
|
||||
{
|
||||
QQmlEngine engine;
|
||||
QQmlComponent component(&engine, testFileUrl("qualifiedScriptImport.qml"));
|
||||
QVERIFY2(component.isReady(), qPrintable(component.errorString()));
|
||||
QScopedPointer<QObject> o(component.create());
|
||||
QVERIFY(!o.isNull());
|
||||
|
||||
QCOMPARE(o->property("a"), QVariant::fromValue<double>(12));
|
||||
QCOMPARE(o->property("b"), QVariant::fromValue<int>(3));
|
||||
QCOMPARE(o->property("c"), QVariant());
|
||||
}
|
||||
|
||||
void tst_QQmlImport::testDesignerSupported()
|
||||
{
|
||||
QQuickView *window = new QQuickView();
|
||||
|
|
Loading…
Reference in New Issue