diff options
-rw-r--r-- | src/imports/builtins/builtins.qmltypes | 9 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljsimporter.cpp | 16 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/qjsroot.qml | 20 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/tst_qmllint.cpp | 1 | ||||
-rw-r--r-- | tools/qmllint/checkidentifiers.cpp | 10 |
5 files changed, 41 insertions, 15 deletions
diff --git a/src/imports/builtins/builtins.qmltypes b/src/imports/builtins/builtins.qmltypes index a9cc4ea4d7..f1a57cfab3 100644 --- a/src/imports/builtins/builtins.qmltypes +++ b/src/imports/builtins/builtins.qmltypes @@ -88,6 +88,7 @@ Module { Component { name: "number" + extension: "Number" accessSemantics: "value" } @@ -115,6 +116,7 @@ Module { Component { name: "QString" + extension: "String" exports: ["QML/string 1.0"] exportMetaObjectRevisions: [256] accessSemantics: "value" @@ -129,6 +131,7 @@ Module { Component { name: "QDateTime" + extension: "Date" exports: ["QML/date 1.0"] exportMetaObjectRevisions: [256] accessSemantics: "value" @@ -151,4 +154,10 @@ Module { name: "QVariantMap" accessSemantics: "value" } + + Component { + name: "QRegularExpression" + extension: "RegExp" + accessSemantics: "value" + } } diff --git a/src/qmlcompiler/qqmljsimporter.cpp b/src/qmlcompiler/qqmljsimporter.cpp index 0f184c4419..c8107ecd4d 100644 --- a/src/qmlcompiler/qqmljsimporter.cpp +++ b/src/qmlcompiler/qqmljsimporter.cpp @@ -271,7 +271,7 @@ void QQmlJSImporter::processImport(const QQmlJSImporter::Import &import, } /*! - * Imports builtins.qmltypes found in any of the import paths. + * Imports builtins.qmltypes and jsroot.qmltypes found in any of the import paths. */ QQmlJSImporter::ImportedTypes QQmlJSImporter::importBuiltins() { @@ -284,16 +284,22 @@ QQmlJSImporter::AvailableTypes QQmlJSImporter::builtinImportHelper() if (!m_builtins.qmlNames.isEmpty() || !m_builtins.cppNames.isEmpty()) return m_builtins; + Import result; for (auto const &dir : m_importPaths) { - Import result; - QDirIterator it { dir, QStringList() << QLatin1String("builtins.qmltypes"), QDir::NoFilter, - QDirIterator::Subdirectories }; + QDirIterator it { dir, + QStringList() << QStringLiteral("builtins.qmltypes") + << QStringLiteral("jsroot.qmltypes"), + QDir::NoFilter, QDirIterator::Subdirectories }; while (it.hasNext()) readQmltypes(it.next(), &result.objects, &result.dependencies); + importDependencies(result, &m_builtins); - processImport(result, &m_builtins); } + // Process them together since there they have interdependencies that wouldn't get resolved + // otherwise + processImport(result, &m_builtins); + return m_builtins; } diff --git a/tests/auto/qml/qmllint/data/qjsroot.qml b/tests/auto/qml/qmllint/data/qjsroot.qml new file mode 100644 index 0000000000..c5995b9576 --- /dev/null +++ b/tests/auto/qml/qmllint/data/qjsroot.qml @@ -0,0 +1,20 @@ +import QtQuick + +QtObject { + property var locale: Qt.locale() + property date currentDate: new Date() + property RegularExpressionValidator validator: RegularExpressionValidator { regularExpression: /20([0-9]+)/ }; + property double pi: 3.14 + + // Test date + property string dateString: currentDate.toLocaleDateString(); + + // Test string + property int dateStringDotIndex: dateString.indexOf(".") + + // Test regularExpression + property var dateStringReplace: validator.regularExpression.exec(dateString) + + // Test double + property string fixedPi: pi.toFixed(1) +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index df303088bf..d6f5088a9d 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -747,6 +747,7 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("aliasToList") << QStringLiteral("aliasToList.qml"); QTest::newRow("QVariant") << QStringLiteral("qvariant.qml"); QTest::newRow("Accessible") << QStringLiteral("accessible.qml"); + QTest::newRow("qjsroot") << QStringLiteral("qjsroot.qml"); } void TestQmllint::cleanQmlCode() diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp index 66903c29a8..72e0d6fd7d 100644 --- a/tools/qmllint/checkidentifiers.cpp +++ b/tools/qmllint/checkidentifiers.cpp @@ -87,9 +87,6 @@ void CheckIdentifiers::checkMemberAccess(const QVector<FieldMember> &members, if (prop != nullptr && prop->isList()) { detectedRestrictiveKind = QLatin1String("list"); expectedNext.append(QLatin1String("length")); - } else if (outerScope->internalName() == QLatin1String("QString")) { - detectedRestrictiveKind = QLatin1String("QString"); - expectedNext.append(QLatin1String("length")); } QQmlJSScope::ConstPtr scope = outerScope; @@ -136,13 +133,6 @@ void CheckIdentifiers::checkMemberAccess(const QVector<FieldMember> &members, continue; } - if (typeName == QLatin1String("QString")) { - detectedRestrictiveKind = typeName; - detectedRestrictiveName = access.m_name; - expectedNext.append(QLatin1String("length")); - continue; - } - if (access.m_parentType.isEmpty()) { if (binding.hasValue()) scope = binding.value(); |