|
|
|
|
@ -53,34 +53,40 @@ HarmonyExportImportedSpecifierDependency.Template.prototype.apply = function(dep
|
|
|
|
|
var active = HarmonyModulesHelpers.isActive(dep.originModule, dep);
|
|
|
|
|
var content;
|
|
|
|
|
var activeExports;
|
|
|
|
|
if(!used) {
|
|
|
|
|
content = "/* unused harmony reexport " + (dep.name || "namespace") + " */";
|
|
|
|
|
} else if(!active) {
|
|
|
|
|
content = "/* inactive harmony reexport " + (dep.name || "namespace") + " */";
|
|
|
|
|
} else if(dep.name === "default" && !(importedModule && importedModule.meta && importedModule.meta.harmonyModule)) {
|
|
|
|
|
content = "/* harmony reexport */ Object.defineProperty(exports, " + JSON.stringify(used) + ", {configurable: false, enumerable: true, get: function() { return " + name + "_default.a; }});";
|
|
|
|
|
} else if(dep.name && dep.id) {
|
|
|
|
|
function getReexportStatement(key, valueKey) {
|
|
|
|
|
return (importIsHarmony || !valueKey ? "" : "if(Object.prototype.hasOwnProperty.call(" + name + ", " + valueKey + ")) ") +
|
|
|
|
|
"Object.defineProperty(exports, " + key + ", "+
|
|
|
|
|
"{configurable: false, enumerable: true, get: function() { return " + name + (valueKey === null ? "_default.a" : valueKey && "[" + valueKey + "]") + "; }});"
|
|
|
|
|
}
|
|
|
|
|
if(!used) { // we want to rexport something, but the export isn't used
|
|
|
|
|
content = "/* unused harmony reexport " + (dep.name || "namespace") + " */\n";
|
|
|
|
|
} else if(!active) { // we want to reexport something but another exports overrides this one
|
|
|
|
|
content = "/* inactive harmony reexport " + (dep.name || "namespace") + " */\n";
|
|
|
|
|
} else if(dep.name && dep.id === "default" && !(importedModule && importedModule.meta && importedModule.meta.harmonyModule)) { // we want to reexport the default export from a non-hamory module
|
|
|
|
|
content = "/* harmony reexport */ " + getReexportStatement(JSON.stringify(used), null) + "\n";
|
|
|
|
|
} else if(dep.name && dep.id) { // we want to reexport a key as new key
|
|
|
|
|
var idUsed = importedModule && importedModule.isUsed(dep.id);
|
|
|
|
|
content = "/* harmony reexport */ Object.defineProperty(exports, " + JSON.stringify(used) + ", {configurable: false, enumerable: true, get: function() { return " + (name + "[" + JSON.stringify(idUsed) + "]") + "; }});";
|
|
|
|
|
} else if(dep.name) {
|
|
|
|
|
content = "/* harmony reexport */ Object.defineProperty(exports, " + JSON.stringify(used) + ", {configurable: false, enumerable: true, get: function() { return " + name + "; }});";
|
|
|
|
|
} else if(Array.isArray(dep.originModule.usedExports)) {
|
|
|
|
|
content = "/* harmony reexport */ " + getReexportStatement(JSON.stringify(used), JSON.stringify(idUsed)) + "\n";
|
|
|
|
|
} else if(dep.name) { // we want to reexport the module object as named export
|
|
|
|
|
content = "/* harmony reexport */ " + getReexportStatement(JSON.stringify(used), "") + "\n";
|
|
|
|
|
} else if(Array.isArray(dep.originModule.usedExports)) { // we now which exports are used
|
|
|
|
|
activeExports = HarmonyModulesHelpers.getActiveExports(dep.originModule);
|
|
|
|
|
var importIsHarmony = importedModule && importedModule.meta.harmonyModule;
|
|
|
|
|
var importActiveExports = importedModule && HarmonyModulesHelpers.getActiveExports(importedModule);
|
|
|
|
|
var items = dep.originModule.usedExports.map(function(id) {
|
|
|
|
|
if(id === "default") return;
|
|
|
|
|
if(activeExports.indexOf(id) >= 0) return;
|
|
|
|
|
if(importIsHarmony && importActiveExports.indexOf(id) < 0) return;
|
|
|
|
|
var exportUsed = dep.originModule.isUsed(id);
|
|
|
|
|
var idUsed = importedModule && importedModule.isUsed(id);
|
|
|
|
|
return [exportUsed, idUsed];
|
|
|
|
|
}).filter(Boolean);
|
|
|
|
|
if(items.length > 1) {
|
|
|
|
|
content = "/* harmony namespace reexport */ " + JSON.stringify(items) + ".forEach(function(i) { " +
|
|
|
|
|
"Object.defineProperty(exports, i[0], {configurable: false, enumerable: true, get: function() { return " + (name + "[i[1]]") + "; }});" +
|
|
|
|
|
"});";
|
|
|
|
|
} else if(items.length === 1) {
|
|
|
|
|
content = "/* harmony namespace reexport */ Object.defineProperty(exports, " + JSON.stringify(items[0][0]) + ", {configurable: false, enumerable: true, get: function() { return " + (name + "[" + JSON.stringify(items[0][1]) + "]") + "; }});";
|
|
|
|
|
} else content = "/* unused harmony namespace reexport */";
|
|
|
|
|
} else if(dep.originModule.usedExports) {
|
|
|
|
|
if(items.length > 0) {
|
|
|
|
|
content = "/* harmony namespace reexport */ " + items.map(function(item) {
|
|
|
|
|
return getReexportStatement(JSON.stringify(item[0]), JSON.stringify(item[1]));
|
|
|
|
|
}).join(" ") + "\n";
|
|
|
|
|
} else content = "/* unused harmony namespace reexport */\n";
|
|
|
|
|
} else if(dep.originModule.usedExports) { // not sure which exports are used
|
|
|
|
|
activeExports = HarmonyModulesHelpers.getActiveExports(dep.originModule);
|
|
|
|
|
content = "/* harmony namespace reexport */ for(var __WEBPACK_IMPORT_KEY__ in " + name + ") ";
|
|
|
|
|
|
|
|
|
|
@ -90,8 +96,8 @@ HarmonyExportImportedSpecifierDependency.Template.prototype.apply = function(dep
|
|
|
|
|
content += "if(" + JSON.stringify(activeExports.concat("default")) + ".indexOf(__WEBPACK_IMPORT_KEY__) < 0) ";
|
|
|
|
|
else
|
|
|
|
|
content += "if(__WEBPACK_IMPORT_KEY__ !== 'default') ";
|
|
|
|
|
content += "(function(key) { Object.defineProperty(exports, key, {configurable: false, enumerable: true, get: function() { return " + name + "[key]; }}) }(__WEBPACK_IMPORT_KEY__));";
|
|
|
|
|
content += "(function(key) { Object.defineProperty(exports, key, {configurable: false, enumerable: true, get: function() { return " + name + "[key]; }}) }(__WEBPACK_IMPORT_KEY__));\n";
|
|
|
|
|
content += "(function(key) { Object.defineProperty(exports, key, {configurable: false, enumerable: true, get: function() { return " + name + "[key]; }}) }(__WEBPACK_IMPORT_KEY__));\n";
|
|
|
|
|
}
|
|
|
|
|
source.insert(dep.position, content);
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|