diff options
-rw-r--r-- | src/qmlcompiler/qqmljstypereader.cpp | 27 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/jsmoduleimport.qml | 6 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/script.mjs | 4 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/tst_qmllint.cpp | 1 |
4 files changed, 36 insertions, 2 deletions
diff --git a/src/qmlcompiler/qqmljstypereader.cpp b/src/qmlcompiler/qqmljstypereader.cpp index 2c45bb01d6..789166a301 100644 --- a/src/qmlcompiler/qqmljstypereader.cpp +++ b/src/qmlcompiler/qqmljstypereader.cpp @@ -40,6 +40,26 @@ QT_BEGIN_NAMESPACE +static QQmlJSScope::Ptr parseModule(QQmlJS::AST::ESModule *module, const QString &name) +{ + using namespace QQmlJS::AST; + QQmlJSScope::Ptr result = QQmlJSScope::create(QQmlJSScope::JSLexicalScope); + result->setInternalName(name); + for (auto *statement = module->body; statement; statement = statement->next) { + if (auto *exp = cast<ExportDeclaration *>(statement->statement)) { + // TODO: There are a number of other things we could find here + if (auto *function = cast<FunctionDeclaration *>(exp->variableStatementOrDeclaration)) { + QQmlJSMetaMethod method(function->name.toString()); + method.setMethodType(QQmlJSMetaMethod::Method); + for (auto *argument = function->formals; argument; argument = argument->next) + method.addParameter(argument->element->bindingIdentifier.toString(), QString()); + result->addOwnMethod(method); + } + } + } + return result; +} + static QQmlJSScope::Ptr parseProgram(QQmlJS::AST::Program *program, const QString &name) { using namespace QQmlJS::AST; @@ -105,8 +125,11 @@ QQmlJSScope::Ptr QQmlJSTypeReader::operator()() return membersVisitor.result(); } - // TODO: Anything special to do with ES modules here? - return parseProgram(QQmlJS::AST::cast<QQmlJS::AST::Program *>(parser.rootNode()), scopeName); + + if (isESModule) + return parseModule(cast<ESModule *>(parser.rootNode()), scopeName); + else + return parseProgram(cast<Program *>(parser.rootNode()), scopeName); } QT_END_NAMESPACE diff --git a/tests/auto/qml/qmllint/data/jsmoduleimport.qml b/tests/auto/qml/qmllint/data/jsmoduleimport.qml new file mode 100644 index 0000000000..c1fad7fee2 --- /dev/null +++ b/tests/auto/qml/qmllint/data/jsmoduleimport.qml @@ -0,0 +1,6 @@ +import QtQml 2.0 +import "script.mjs" as Script + +QtObject { + property bool ok: Script.ok() +} diff --git a/tests/auto/qml/qmllint/data/script.mjs b/tests/auto/qml/qmllint/data/script.mjs new file mode 100644 index 0000000000..459c336125 --- /dev/null +++ b/tests/auto/qml/qmllint/data/script.mjs @@ -0,0 +1,4 @@ + +export function ok() { + return true +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 7ad5ee136e..7e21c8d437 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -290,6 +290,7 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("anchors2") << QStringLiteral("anchors2.qml"); QTest::newRow("optionalImport") << QStringLiteral("optionalImport.qml"); QTest::newRow("goodAliasObject") << QStringLiteral("goodAliasObject.qml"); + QTest::newRow("jsmoduleimport") << QStringLiteral("jsmoduleimport.qml"); } void TestQmllint::cleanQmlCode() |