From e839129b6020795483d1f9ba0b3bcfde9f881bab Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 8 Aug 2018 17:49:59 +0200 Subject: 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 --- src/qml/compiler/qv4compilerscanfunctions.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/qml/compiler/qv4compilerscanfunctions.cpp') 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(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. -- cgit v1.2.3