aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/parser
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-08-14 13:01:51 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-08-14 17:45:51 +0000
commit929ef25efd402368a9f154b61aa96b4b01a02ce2 (patch)
treec7e3c3a57bb0f27c354a83d797b0d53af8719f9a /src/qml/parser
parent859b78e063947309932c0d7c154736227ed903ae (diff)
Fix module dependency handling
The evaluation of a module can have side-effects by modifying the global object or objects in it. Therefore even a seemingly empty import such as import "./foo.js" needs to be listed in the module requests. It's also important that they are evaluated in the order of declaration. Therefore we collect all module requests separately - even those that don't have import variables to process. This patch also ensures that the export and import declarations are visited in the correct order, by unifying both AST nodes to be hooked into the statement list. The fact that we connect the module list items into a statement list is solely an artifact of re-using defineFunction() which takes a StatementList as body. Change-Id: I75dc357b2aecfc324d9a9fe66952eff1ec1dfd8a Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/parser')
-rw-r--r--src/qml/parser/qqmljsast.cpp32
-rw-r--r--src/qml/parser/qqmljsast_p.h4
-rw-r--r--src/qml/parser/qqmljsastvisitor_p.h3
3 files changed, 13 insertions, 26 deletions
diff --git a/src/qml/parser/qqmljsast.cpp b/src/qml/parser/qqmljsast.cpp
index 0b1b97a41a..ca4317a9a6 100644
--- a/src/qml/parser/qqmljsast.cpp
+++ b/src/qml/parser/qqmljsast.cpp
@@ -1162,26 +1162,10 @@ void ExportDeclaration::accept0(Visitor *visitor)
visitor->endVisit(this);
}
-void ModuleItemList::accept0(Visitor *visitor)
-{
- if (visitor->visit(this)) {
- for (ModuleItemList *it = this; it; it = it->next) {
- if (it->item) {
- // The statement list is concatenated together between module list
- // items and stored in the ESModule, thus not visited from there.
- if (it->item->kind == Kind_StatementList)
- continue;
- // Export declaration are also injected into the statement list for
- // processing of declarations an variable statements, so don't visit
- // it here to avoid double visits.
- if (it->item->kind == Kind_ExportDeclaration)
- continue;
- }
- accept(it->item, visitor);
- }
- }
-
- visitor->endVisit(this);
+void ModuleItemList::accept0(Visitor *)
+{
+ // See ESModule::accept0
+ Q_UNREACHABLE();
}
StatementList *ModuleItemList::buildStatementList(MemoryPool *pool) const
@@ -1192,6 +1176,8 @@ StatementList *ModuleItemList::buildStatementList(MemoryPool *pool) const
if (!listItem) {
if (AST::ExportDeclaration *exportDecl = AST::cast<AST::ExportDeclaration*>(item->item))
listItem = new (pool) AST::StatementList(exportDecl);
+ else if (AST::ImportDeclaration *importDecl = AST::cast<AST::ImportDeclaration*>(item->item))
+ listItem = new (pool) AST::StatementList(importDecl);
else
continue;
}
@@ -1209,7 +1195,11 @@ StatementList *ModuleItemList::buildStatementList(MemoryPool *pool) const
void ESModule::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
- accept(body, visitor);
+ // We don't accept the ModuleItemList (body) as instead the statement list items
+ // as well as the import/export declarations are linked together in the statement
+ // list. That way they are processed in correct order and can be used with the codegen's
+ // defineFunction() that expects a statement list.
+ // accept(body, visitor);
accept(statements, visitor);
}
diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h
index e344dd4a28..1429d784c6 100644
--- a/src/qml/parser/qqmljsast_p.h
+++ b/src/qml/parser/qqmljsast_p.h
@@ -2539,7 +2539,7 @@ public:
QStringRef moduleSpecifier;
};
-class QML_PARSER_EXPORT ImportDeclaration: public Node
+class QML_PARSER_EXPORT ImportDeclaration: public Statement
{
public:
QQMLJS_DECLARE_AST_NODE(ImportDeclaration)
@@ -2755,7 +2755,7 @@ public:
StatementList *buildStatementList(MemoryPool *pool) const;
- void accept0(Visitor *visitor) override;
+ void accept0(Visitor *) override;
SourceLocation firstSourceLocation() const override
{ return item->firstSourceLocation(); }
diff --git a/src/qml/parser/qqmljsastvisitor_p.h b/src/qml/parser/qqmljsastvisitor_p.h
index 3162bb1630..c925096de6 100644
--- a/src/qml/parser/qqmljsastvisitor_p.h
+++ b/src/qml/parser/qqmljsastvisitor_p.h
@@ -369,9 +369,6 @@ public:
virtual bool visit(ModuleItem *) { return true; }
virtual void endVisit(ModuleItem *) {}
- virtual bool visit(ModuleItemList *) { return true; }
- virtual void endVisit(ModuleItemList *) {}
-
virtual bool visit(ESModule *) { return true; }
virtual void endVisit(ESModule *) {}