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/qv4codegen.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/qv4codegen.cpp')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 7b059b3fb4..fc43031c5c 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -789,6 +789,36 @@ bool Codegen::visit(PatternPropertyList *) return false; } +bool Codegen::visit(ExportDeclaration *ast) +{ + if (!ast->exportDefault) + return true; + + Reference exportedValue; + + if (auto *fdecl = AST::cast<FunctionDeclaration*>(ast->variableStatementOrDeclaration)) { + Result r; + qSwap(_expr, r); + visit(static_cast<FunctionExpression*>(fdecl)); + qSwap(_expr, r); + exportedValue = r.result(); + } else if (auto *classDecl = AST::cast<ClassDeclaration*>(ast->variableStatementOrDeclaration)) { + Result r; + qSwap(_expr, r); + visit(static_cast<ClassExpression*>(classDecl)); + qSwap(_expr, r); + exportedValue = r.result(); + } else if (ExpressionNode *expr = ast->variableStatementOrDeclaration->expressionCast()) { + exportedValue = expression(expr); + } + + exportedValue.loadInAccumulator(); + Reference defaultExportSlot = Reference::fromScopedLocal(this, 0, /*scope*/0); + defaultExportSlot.storeConsumeAccumulator(); + + return false; +} + bool Codegen::visit(StatementList *) { Q_UNREACHABLE(); |