aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-11-20 13:13:23 +0100
committerUlf Hermann <ulf.hermann@qt.io>2020-11-20 20:41:13 +0100
commit89636733ba3872b9c29ed712e0723b576f65f3ff (patch)
treee6a955df4b8db878e70438b1c98fbde2a2028fc1 /src/qmlcompiler
parentf1a9c9b4273ec6104a0543b5cf48281141f613e6 (diff)
qmllint: Don't crash when importing ES modules
Change-Id: Ica93a3e3fb0eb99be1498f1fcb94b09c113272d7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler')
-rw-r--r--src/qmlcompiler/qqmljstypereader.cpp27
1 files changed, 25 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