2017-05-03 15:35:00 +02:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
class HarmonyModulesHelpers {
|
|
|
|
|
|
|
|
static getModuleVar(state, request) {
|
|
|
|
if(!state.harmonyModules) state.harmonyModules = [];
|
2017-08-14 05:01:11 +02:00
|
|
|
let idx = state.harmonyModules.indexOf(request);
|
2017-05-03 15:35:00 +02:00
|
|
|
if(idx < 0) {
|
|
|
|
idx = state.harmonyModules.length;
|
|
|
|
state.harmonyModules.push(request);
|
|
|
|
}
|
2017-08-14 05:01:11 +02:00
|
|
|
return `__WEBPACK_IMPORTED_MODULE_${idx}_${request.replace(/[^A-Za-z0-9_]/g, "_").replace(/__+/g, "_")}__`;
|
2017-05-03 15:35:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static getNewModuleVar(state, request) {
|
|
|
|
if(state.harmonyModules && state.harmonyModules.indexOf(request) >= 0)
|
|
|
|
return null;
|
|
|
|
return this.getModuleVar(state, request);
|
|
|
|
}
|
|
|
|
|
|
|
|
static checkModuleVar(state, request) {
|
|
|
|
if(!state.harmonyModules || state.harmonyModules.indexOf(request) < 0)
|
|
|
|
return null;
|
|
|
|
return this.getModuleVar(state, request);
|
|
|
|
}
|
|
|
|
|
|
|
|
// checks if an harmony dependency is active in a module according to
|
|
|
|
// precedence rules.
|
|
|
|
static isActive(module, depInQuestion) {
|
2017-08-14 05:01:11 +02:00
|
|
|
const desc = depInQuestion.describeHarmonyExport();
|
2017-05-03 15:35:00 +02:00
|
|
|
if(!desc.exportedName) return true;
|
2017-08-14 05:01:11 +02:00
|
|
|
let before = true;
|
|
|
|
for(const moduleDependency of module.dependencies) {
|
|
|
|
const dep = moduleDependency;
|
2017-05-03 15:35:00 +02:00
|
|
|
if(dep === depInQuestion) {
|
|
|
|
before = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(!dep.describeHarmonyExport) continue;
|
2017-08-14 05:01:11 +02:00
|
|
|
const d = dep.describeHarmonyExport();
|
2017-05-03 15:35:00 +02:00
|
|
|
if(!d || !d.exportedName) continue;
|
|
|
|
if(d.exportedName === desc.exportedName) {
|
|
|
|
if(d.precedence < desc.precedence) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(d.precedence === desc.precedence && !before) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get a list of named exports defined in a module
|
|
|
|
// doesn't include * reexports.
|
|
|
|
static getActiveExports(module, currentDependency) {
|
2017-08-14 05:01:11 +02:00
|
|
|
const desc = currentDependency && currentDependency.describeHarmonyExport();
|
2017-05-03 15:35:00 +02:00
|
|
|
var currentIndex = currentDependency ? module.dependencies.indexOf(currentDependency) : -1;
|
|
|
|
return module.dependencies.map((dep, idx) => {
|
|
|
|
return {
|
|
|
|
dep: dep,
|
|
|
|
idx: idx
|
|
|
|
};
|
|
|
|
}).reduce((arr, data) => {
|
2017-08-14 05:01:11 +02:00
|
|
|
const dep = data.dep;
|
2017-05-03 15:35:00 +02:00
|
|
|
if(!dep.describeHarmonyExport) return arr;
|
2017-08-14 05:01:11 +02:00
|
|
|
const d = dep.describeHarmonyExport();
|
2017-05-03 15:35:00 +02:00
|
|
|
if(!d) return arr;
|
|
|
|
if(!desc || (d.precedence < desc.precedence) || (d.precedence === desc.precedence && data.idx < currentIndex)) {
|
|
|
|
var names = [].concat(d.exportedName);
|
|
|
|
names.forEach(function(name) {
|
|
|
|
if(name && arr.indexOf(name) < 0)
|
|
|
|
arr.push(name);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
}, []);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = HarmonyModulesHelpers;
|