aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4compilerscanfunctions.cpp
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/compiler/qv4compilerscanfunctions.cpp
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/compiler/qv4compilerscanfunctions.cpp')
-rw-r--r--src/qml/compiler/qv4compilerscanfunctions.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp
index f47643826f..6ca46fd362 100644
--- a/src/qml/compiler/qv4compilerscanfunctions.cpp
+++ b/src/qml/compiler/qv4compilerscanfunctions.cpp
@@ -164,8 +164,11 @@ void ScanFunctions::endVisit(ESModule *)
bool ScanFunctions::visit(ExportDeclaration *declaration)
{
QString module;
- if (declaration->fromClause)
+ if (declaration->fromClause) {
module = declaration->fromClause->moduleSpecifier.toString();
+ if (!module.isEmpty())
+ _context->moduleRequests << module;
+ }
if (declaration->exportAll) {
Compiler::ExportEntry entry;
@@ -233,8 +236,14 @@ bool ScanFunctions::visit(ExportDeclaration *declaration)
bool ScanFunctions::visit(ImportDeclaration *declaration)
{
QString module;
- if (declaration->fromClause)
+ if (declaration->fromClause) {
module = declaration->fromClause->moduleSpecifier.toString();
+ if (!module.isEmpty())
+ _context->moduleRequests << module;
+ }
+
+ if (!declaration->moduleSpecifier.isEmpty())
+ _context->moduleRequests << declaration->moduleSpecifier.toString();
if (ImportClause *import = declaration->importClause) {
if (!import->importedDefaultBinding.isEmpty()) {