qmllint: fix import java scripts from module
Fixes: QTBUG-86183 Change-Id: I4809cb5a408eb4e668f802cf0d7b7a872d1ed4b7 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
parent
538f1b7dd6
commit
a29eb1c152
|
@ -0,0 +1,6 @@
|
|||
.pragma library
|
||||
|
||||
function somefunc(name)
|
||||
{
|
||||
return "Hi, " + name;
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
module ModuleWithJS
|
||||
Foo 1.0 Foo.js
|
|
@ -0,0 +1,6 @@
|
|||
import QtQml 2.0
|
||||
import ModuleWithJS
|
||||
|
||||
QtObject {
|
||||
objectName: Foo.unknownFunc()
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
import QtQml 2.0
|
||||
import ModuleWithJS
|
||||
|
||||
QtObject {
|
||||
objectName: Foo.somefunc()
|
||||
}
|
|
@ -187,6 +187,9 @@ void TestQmllint::dirtyQmlCode_data()
|
|||
<< QStringLiteral("qmldirImportAndDepend/bad.qml")
|
||||
<< QString("warning: Item was not found. Did you add all import paths?")
|
||||
<< QString();
|
||||
QTest::newRow("javascriptMethodsInModule")
|
||||
<< QStringLiteral("javascriptMethodsInModuleBad.qml")
|
||||
<< QString("Warning: Property \"unknownFunc\" not found on type \"Foo\"") << QString();
|
||||
}
|
||||
|
||||
void TestQmllint::dirtyQmlCode()
|
||||
|
@ -231,6 +234,8 @@ void TestQmllint::cleanQmlCode_data()
|
|||
QTest::newRow("qmldirImportAndDepend") << QStringLiteral("qmldirImportAndDepend/good.qml");
|
||||
QTest::newRow("ParentEnum") << QStringLiteral("parentEnum.qml");
|
||||
QTest::newRow("Signals") << QStringLiteral("Signal.qml");
|
||||
QTest::newRow("javascriptMethodsInModule")
|
||||
<< QStringLiteral("javascriptMethodsInModuleGood.qml");
|
||||
}
|
||||
|
||||
void TestQmllint::cleanQmlCode()
|
||||
|
|
|
@ -129,6 +129,12 @@ FindWarningVisitor::Import FindWarningVisitor::readQmldir(const QString &path)
|
|||
if (!reader.plugins().isEmpty() && QFile::exists(path + SlashPluginsDotQmltypes))
|
||||
readQmltypes(path + SlashPluginsDotQmltypes, &result.objects);
|
||||
|
||||
const auto scripts = reader.scripts();
|
||||
for (const auto &script : scripts) {
|
||||
const QString filePath = path + QLatin1Char('/') + script.fileName;
|
||||
result.scripts.push_back(
|
||||
{ script.nameSpace, ScopeTree::ConstPtr(localFile2ScopeTree(filePath)) });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -146,6 +152,10 @@ void FindWarningVisitor::processImport(
|
|||
import.isAutoImport ? version : import.version);
|
||||
}
|
||||
|
||||
for (const auto &it : qAsConst(import.scripts)) {
|
||||
m_exportedName2Scope.insert(it.first, it.second);
|
||||
}
|
||||
|
||||
// add objects
|
||||
for (auto it = import.objects.begin(); it != import.objects.end(); ++it) {
|
||||
const auto &val = it.value();
|
||||
|
|
|
@ -64,6 +64,7 @@ private:
|
|||
QHash<QString, ScopeTree::ConstPtr> objects;
|
||||
QList<QQmlDirParser::Import> imports;
|
||||
QList<QQmlDirParser::Component> dependencies;
|
||||
QList<QPair<QString, ScopeTree::ConstPtr>> scripts;
|
||||
};
|
||||
|
||||
ScopeTree::Ptr m_rootScope;
|
||||
|
|
Loading…
Reference in New Issue