aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4compilerscanfunctions.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-08-15 14:53:28 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-08-15 18:56:05 +0000
commitd4ca7f779d85b01a7e650abefeb8cd6502eff8e2 (patch)
treecb9e961e795cbafb6bbfeb1d17e4be604cd7411d /src/qml/compiler/qv4compilerscanfunctions.cpp
parent263b1f5f2acdc7e652e7c3aa332e2a53bd136295 (diff)
Fix initialization of default exported functions and generators
When registering a default export, make sure that the local name points either to an entry that we've entered into the environment or the synthetic entry we create. Change-Id: I37e160dc1e3231214bb68f72d6bb0746d7aee3b3 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compilerscanfunctions.cpp')
-rw-r--r--src/qml/compiler/qv4compilerscanfunctions.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp
index a3bdce05d4..7a8622dc02 100644
--- a/src/qml/compiler/qv4compilerscanfunctions.cpp
+++ b/src/qml/compiler/qv4compilerscanfunctions.cpp
@@ -170,6 +170,8 @@ bool ScanFunctions::visit(ExportDeclaration *declaration)
_context->moduleRequests << module;
}
+ QString localNameForDefaultExport = QStringLiteral("*default*");
+
if (declaration->exportAll) {
Compiler::ExportEntry entry;
entry.moduleRequest = declaration->fromClause->moduleSpecifier.toString();
@@ -209,25 +211,35 @@ bool ScanFunctions::visit(ExportDeclaration *declaration)
entry.localName = name;
entry.exportName = name;
_context->exportEntries << entry;
+ if (declaration->exportDefault)
+ localNameForDefaultExport = entry.localName;
}
} else if (auto *fdef = declaration->variableStatementOrDeclaration->asFunctionDefinition()) {
- QString name = fdef->name.toString();
- // Our parser gives `export default (function() {}` the name "default", which
- // we don't want to export here.
- if (!name.isEmpty() && name != QStringLiteral("default")) {
+ QString functionName;
+
+ // Only function definitions for which we enter their name into the local environment
+ // can result in exports. Nested expressions such as (function foo() {}) are not accessible
+ // as locals and can only be exported as default exports (further down).
+ auto ast = declaration->variableStatementOrDeclaration;
+ if (AST::cast<AST::ExpressionStatement*>(ast) || AST::cast<AST::FunctionDeclaration*>(ast))
+ functionName = fdef->name.toString();
+
+ if (!functionName.isEmpty()) {
Compiler::ExportEntry entry;
- entry.localName = name;
- entry.exportName = name;
+ entry.localName = functionName;
+ entry.exportName = functionName;
_context->exportEntries << entry;
+ if (declaration->exportDefault)
+ localNameForDefaultExport = entry.localName;
}
}
if (declaration->exportDefault) {
Compiler::ExportEntry entry;
- entry.localName = QStringLiteral("*default*");
+ entry.localName = localNameForDefaultExport;
+ _context->localNameForDefaultExport = localNameForDefaultExport;
entry.exportName = QStringLiteral("default");
_context->exportEntries << entry;
- _context->hasDefaultExport = true;
}
return true; // scan through potential assignment expression code, etc.