117 lines
3.0 KiB
JavaScript
117 lines
3.0 KiB
JavaScript
// SystemJS Loader Class and Extension helpers
|
|
|
|
function SystemJSLoader() {
|
|
SystemLoader.call(this);
|
|
|
|
systemJSConstructor.call(this);
|
|
}
|
|
|
|
// inline Object.create-style class extension
|
|
function SystemProto() {};
|
|
SystemProto.prototype = SystemLoader.prototype;
|
|
SystemJSLoader.prototype = new SystemProto();
|
|
SystemJSLoader.prototype.constructor = SystemJSLoader;
|
|
|
|
// remove ESML instantiate
|
|
SystemJSLoader.prototype.instantiate = function() {};
|
|
|
|
var systemJSConstructor;
|
|
|
|
function hook(name, hook) {
|
|
SystemJSLoader.prototype[name] = hook(SystemJSLoader.prototype[name] || function() {});
|
|
}
|
|
function hookConstructor(hook) {
|
|
systemJSConstructor = hook(systemJSConstructor || function() {});
|
|
}
|
|
|
|
function dedupe(deps) {
|
|
var newDeps = [];
|
|
for (var i = 0, l = deps.length; i < l; i++)
|
|
if (indexOf.call(newDeps, deps[i]) == -1)
|
|
newDeps.push(deps[i])
|
|
return newDeps;
|
|
}
|
|
|
|
function group(deps) {
|
|
var names = [];
|
|
var indices = [];
|
|
for (var i = 0, l = deps.length; i < l; i++) {
|
|
var index = indexOf.call(names, deps[i]);
|
|
if (index === -1) {
|
|
names.push(deps[i]);
|
|
indices.push([i]);
|
|
}
|
|
else {
|
|
indices[index].push(i);
|
|
}
|
|
}
|
|
return { names: names, indices: indices };
|
|
}
|
|
|
|
var getOwnPropertyDescriptor = true;
|
|
try {
|
|
Object.getOwnPropertyDescriptor({ a: 0 }, 'a');
|
|
}
|
|
catch(e) {
|
|
getOwnPropertyDescriptor = false;
|
|
}
|
|
|
|
// converts any module.exports object into an object ready for SystemJS.newModule
|
|
function getESModule(exports) {
|
|
var esModule = {};
|
|
// don't trigger getters/setters in environments that support them
|
|
if (typeof exports == 'object' || typeof exports == 'function') {
|
|
if (getOwnPropertyDescriptor) {
|
|
var d;
|
|
for (var p in exports)
|
|
if (d = Object.getOwnPropertyDescriptor(exports, p))
|
|
defineProperty(esModule, p, d);
|
|
}
|
|
else {
|
|
var hasOwnProperty = exports && exports.hasOwnProperty;
|
|
for (var p in exports) {
|
|
if (!hasOwnProperty || exports.hasOwnProperty(p))
|
|
esModule[p] = exports[p];
|
|
}
|
|
}
|
|
}
|
|
esModule['default'] = exports;
|
|
defineProperty(esModule, '__useDefault', {
|
|
value: true
|
|
});
|
|
return esModule;
|
|
}
|
|
|
|
function extend(a, b, prepend) {
|
|
for (var p in b) {
|
|
if (!prepend || !(p in a))
|
|
a[p] = b[p];
|
|
}
|
|
return a;
|
|
}
|
|
|
|
// package configuration options
|
|
var packageProperties = ['main', 'format', 'defaultExtension', 'meta', 'map', 'basePath', 'depCache'];
|
|
|
|
// meta first-level extends where:
|
|
// array + array appends
|
|
// object + object extends
|
|
// other properties replace
|
|
function extendMeta(a, b, prepend) {
|
|
for (var p in b) {
|
|
var val = b[p];
|
|
if (!(p in a))
|
|
a[p] = val;
|
|
else if (val instanceof Array && a[p] instanceof Array)
|
|
a[p] = [].concat(prepend ? val : a[p]).concat(prepend ? a[p] : val);
|
|
else if (typeof val == 'object' && val !== null && typeof a[p] == 'object')
|
|
a[p] = extend(extend({}, a[p]), val, prepend);
|
|
else if (!prepend)
|
|
a[p] = val;
|
|
}
|
|
}
|
|
|
|
function warn(msg) {
|
|
if (this.warnings && typeof console != 'undefined' && console.warn)
|
|
console.warn(msg);
|
|
} |