aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljsimporter.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-10-14 12:55:08 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-10-15 10:44:20 +0200
commitf98c961da6d039621ae40ab6c1a79c4b06efb83f (patch)
tree0eca1d6c2e19e54795da143ecb65279acd972572 /src/qmlcompiler/qqmljsimporter.cpp
parented9ffa109eb2f242b59443ad430204a90c8028c4 (diff)
qmllint: Defer resolution of types read from QML files
When importing a directory we most likely don't need all of the files in the directory. Therefore we now parse them only when they are accessed. This speeds up the execution and will allow us to process imports recursively without running into infinite recursion. Change-Id: I0c79313de792249e6bb86144b5014a7787dbdc5b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsimporter.cpp')
-rw-r--r--src/qmlcompiler/qqmljsimporter.cpp26
1 files changed, 8 insertions, 18 deletions
diff --git a/src/qmlcompiler/qqmljsimporter.cpp b/src/qmlcompiler/qqmljsimporter.cpp
index 717b559c44..0f334eabd3 100644
--- a/src/qmlcompiler/qqmljsimporter.cpp
+++ b/src/qmlcompiler/qqmljsimporter.cpp
@@ -303,21 +303,11 @@ QQmlJSScope::Ptr QQmlJSImporter::localFile2ScopeTree(const QString &filePath)
if (seen != m_importedFiles.end())
return *seen;
- QQmlJSTypeReader typeReader(filePath);
- QQmlJSScope::Ptr result = typeReader();
- m_importedFiles.insert(filePath, result);
-
- m_warnings.append(typeReader.errors());
-
- AvailableTypes types;
- types.qmlNames.insert(importDirectory(QFileInfo(filePath).canonicalPath()));
-
- const auto imports = typeReader.imports();
- for (const auto &import : imports)
- importHelper(import.module, &types, import.prefix, import.version);
-
- result->resolveTypes(types.qmlNames);
- return result;
+ return *m_importedFiles.insert(filePath, {
+ QQmlJSScope::create(),
+ QSharedPointer<QDeferredFactory<QQmlJSScope>>(
+ new QDeferredFactory<QQmlJSScope>(this, filePath))
+ });
}
QQmlJSScope::Ptr QQmlJSImporter::importFile(const QString &file)
@@ -339,9 +329,9 @@ QQmlJSImporter::ImportedTypes QQmlJSImporter::importDirectory(
it.next();
if (!it.fileName().front().isUpper())
continue; // Non-uppercase names cannot be imported anyway.
- QQmlJSScope::Ptr scope(localFile2ScopeTree(it.filePath()));
- if (!scope->internalName().isEmpty())
- qmlNames.insert(prefixedName(prefix, scope->internalName()), scope);
+
+ qmlNames.insert(prefixedName(prefix, QFileInfo(it.filePath()).baseName()),
+ localFile2ScopeTree(it.filePath()));
}
return qmlNames;