From c671211390b1fd9fe19e04f531817c58d3616c19 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 13 Aug 2018 13:27:11 +0200 Subject: Implement star re-exports An export such as export * from "./foo.js" allows re-directing imports. Change-Id: I359ce7d4516ed4a7b95e6fcefb4725d854f9c2ce Reviewed-by: Lars Knoll --- src/qml/compiler/qv4compileddata.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/qml/compiler/qv4compileddata.cpp') diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp index 33e463c76a..10799f70da 100644 --- a/src/qml/compiler/qv4compileddata.cpp +++ b/src/qml/compiler/qv4compileddata.cpp @@ -394,6 +394,11 @@ QStringList CompilationUnit::moduleRequests() const requests << stringAt(entry.moduleRequest); } + for (uint i = 0; i < data->starExportEntryTableSize; ++i) { + const ExportEntry &entry = data->starExportEntryTable()[i]; + requests << stringAt(entry.moduleRequest); + } + return requests; } @@ -490,7 +495,31 @@ const Value *CompilationUnit::resolveExportRecursively(QV4::String *exportName, return dependentModuleUnit->resolveExportRecursively(importName, resolveSet); } - return nullptr; + + if (exportName->toQString() == QLatin1String("default")) + return nullptr; + + const Value *starResolution = nullptr; + + for (uint i = 0; i < data->starExportEntryTableSize; ++i) { + const CompiledData::ExportEntry &entry = data->starExportEntryTable()[i]; + auto dependentModuleUnit = engine->loadModule(QUrl(stringAt(entry.moduleRequest)), this); + if (!dependentModuleUnit) + return nullptr; + + const Value *resolution = dependentModuleUnit->resolveExportRecursively(exportName, resolveSet); + // ### handle ambiguous + if (resolution) { + if (!starResolution) { + starResolution = resolution; + continue; + } + if (resolution != starResolution) + return nullptr; + } + } + + return starResolution; } const ExportEntry *CompilationUnit::lookupNameInExportTable(const ExportEntry *firstExportEntry, int tableSize, QV4::String *name) const -- cgit v1.2.3