mirror of
https://github.com/systemjs/systemjs.git
synced 2026-01-25 14:57:38 +00:00
amd and commonjs support updates
This commit is contained in:
parent
cb4b3e08d0
commit
a6d3097faf
44
loader.js
44
loader.js
@ -178,6 +178,13 @@
|
||||
var pluginRegEx = /(\.[^\/\.]+)?!(.+)/;
|
||||
|
||||
// -- /helpers --
|
||||
var nodeGlobal = {
|
||||
process: {
|
||||
nextTick: function(fn) {
|
||||
setTimeout(fn, 7);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
window.jspm = new Loader({
|
||||
normalize: function(name, referer) {
|
||||
@ -297,7 +304,7 @@
|
||||
|
||||
// check if this module uses AMD form
|
||||
// define([.., .., ..], ...)
|
||||
if (match = source.match(amdDefineRegEx)) {
|
||||
if (match = source.match(amdDefineRegEx) && (match[2] || match[1])) {
|
||||
var _imports = match[2] || '[]';
|
||||
// just eval to get the array.. we know it is an array.
|
||||
eval('_imports = ' + _imports);
|
||||
@ -340,7 +347,15 @@
|
||||
output = factory.apply(window, deps);
|
||||
}
|
||||
define.amd = true;
|
||||
eval('var require = jspm.import; ' + source + (options.address ? '\n//# sourceURL=' + options.address : ''));
|
||||
var require = function(deps, callback, errback) {
|
||||
jspm.import(deps, function() {
|
||||
var out = [];
|
||||
for (var i = 0; i < arguments.length; i++)
|
||||
out.push(arguments[i].default);
|
||||
callback.apply(null, out);
|
||||
}, errback);
|
||||
}
|
||||
eval(source + (options.address ? '\n//# sourceURL=' + options.address : ''));
|
||||
return new Module({ 'default': output, 'type': 'AMD' });
|
||||
}
|
||||
};
|
||||
@ -369,7 +384,22 @@
|
||||
var output;
|
||||
var exports = {};
|
||||
var module = {};
|
||||
eval('var define = function(factory) { output = typeof factory == "function" ? factory.call(window, function(d) { return depMap[d]; }, exports) : factory; }; define.amd = true; ' + source + (options.address ? '\n//# sourceURL=' + options.address : ''));
|
||||
depMap.exports = exports;
|
||||
var define = function(factory) {
|
||||
output = typeof factory == "function" ? factory.call(window, function(d) {
|
||||
return depMap[d];
|
||||
}, exports) : factory;
|
||||
};
|
||||
define.amd = true;
|
||||
var require = function(deps, callback, errback) {
|
||||
jspm.import(deps, function() {
|
||||
var out = [];
|
||||
for (var i = 0; i < arguments.length; i++)
|
||||
out.push(arguments[i].default);
|
||||
callback.apply(null, out);
|
||||
}, errback);
|
||||
}
|
||||
eval(source + (options.address ? '\n//# sourceURL=' + options.address : ''));
|
||||
return new Module({ 'default': output || module.exports || exports, type: 'AMD' });
|
||||
}
|
||||
};
|
||||
@ -394,13 +424,7 @@
|
||||
return depMap[d];
|
||||
}
|
||||
var module = { exports: exports };
|
||||
var global = {
|
||||
process: {
|
||||
nextTick: function(fn) {
|
||||
setTimeout(fn, 7);
|
||||
}
|
||||
}
|
||||
};
|
||||
var global = nodeGlobal;
|
||||
eval(source + (options.address ? '\n//# sourceURL=' + options.address : ''));
|
||||
return new Module({ 'default': module.exports, 'type': 'CommonJS' });
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user