diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-08-08 17:49:59 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-08-10 20:33:59 +0000 |
commit | e839129b6020795483d1f9ba0b3bcfde9f881bab (patch) | |
tree | 6b04478a2077d939635e70971720bcc0643ddbb1 /src/qml/compiler/qv4compilerscanfunctions.cpp | |
parent | 0bd3c9cda678b7e158c6142c1567ac927fde18b9 (diff) |
Fix support for default exports in modules
Default export declarations require a binding setup step at run-time, so
we hook it into the ESModule's statement list to make it visible to the
code gen visitor.
We also reserve local slot zero for the default export.
Change-Id: Ie064caad0422b92cfdadbd7d94db72a05e95c0cc
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compilerscanfunctions.cpp')
-rw-r--r-- | src/qml/compiler/qv4compilerscanfunctions.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp index 63ed748048..8f16f9a362 100644 --- a/src/qml/compiler/qv4compilerscanfunctions.cpp +++ b/src/qml/compiler/qv4compilerscanfunctions.cpp @@ -201,21 +201,30 @@ bool ScanFunctions::visit(ExportDeclaration *declaration) } } else if (auto *classDecl = AST::cast<AST::ClassDeclaration*>(declaration->variableStatementOrDeclaration)) { QString name = classDecl->name.toString(); - Compiler::ExportEntry entry; - entry.localName = name; - entry.exportName = name; - _context->exportEntries << entry; + if (!name.isEmpty()) { + Compiler::ExportEntry entry; + entry.localName = name; + entry.exportName = name; + _context->exportEntries << entry; + } } else if (auto *fdef = declaration->variableStatementOrDeclaration->asFunctionDefinition()) { QString name = fdef->name.toString(); - Compiler::ExportEntry entry; - entry.localName = name; - entry.exportName = name; - _context->exportEntries << entry; - } else if (declaration->exportDefault) { + // Our parser gives `export default (function() {}` the name "default", which + // we don't want to export here. + if (!name.isEmpty() && name != QStringLiteral("default")) { + Compiler::ExportEntry entry; + entry.localName = name; + entry.exportName = name; + _context->exportEntries << entry; + } + } + + if (declaration->exportDefault) { Compiler::ExportEntry entry; entry.localName = QStringLiteral("*default*"); entry.exportName = QStringLiteral("default"); _context->exportEntries << entry; + _context->hasDefaultExport = true; } return true; // scan through potential assignment expression code, etc. |