Fix AMD loader arguments for define()

smf-sdk
Alex Brausewetter 2015-12-11 15:39:49 +01:00
rodzic a2dac7050b
commit e8ee1210b9
1 zmienionych plików z 18 dodań i 28 usunięć

46
node_modules/amd-loader/amd-loader.js wygenerowano vendored
Wyświetl plik

@ -15,34 +15,26 @@ module.constructor.prototype._compile = function(content, filename){
}; };
global.define = function (id, injects, factory) { global.define = function (id, injects, factory) {
var DEFAULT_INJECTS = ["require", "exports", "module"];
// infere the module // infer the module
var currentModule = moduleStack[moduleStack.length-1]; var currentModule = moduleStack[moduleStack.length-1];
var mod = currentModule || module.parent || require.main; var mod = currentModule || module.parent || require.main;
// parse arguments // assign arguments
if (!factory) { if (arguments.length === 1) {
// two or less arguments factory = id;
injects = DEFAULT_INJECTS;
id = null;
}
else if (arguments.length === 2) {
factory = injects; factory = injects;
if (factory) { injects = id;
// two args id = null;
if (typeof id === "string") { }
if (id !== mod.id) {
throw new Error("Can not assign module to a different id than the current file"); if (typeof id === "string" && id !== mod.id) {
} throw new Error("Can not assign module to a different id than the current file");
// default injects
injects = [];
}
else{
// anonymous, deps included
injects = id;
}
}
else {
// only one arg, just the factory
factory = id;
injects = [];
}
} }
var req = function(module, relativeId, callback) { var req = function(module, relativeId, callback) {
@ -63,12 +55,10 @@ global.define = function (id, injects, factory) {
fileName = fileName[0]; fileName = fileName[0];
if (prefix && prefix.indexOf("text") !== -1) { if (prefix && prefix.indexOf("text") !== -1) {
return fs.readFileSync(fileName, "utf8"); return fs.readFileSync(fileName);
} else } else
return require(fileName); return require(fileName);
}.bind(this, mod); }.bind(this, mod);
injects.unshift("require", "exports", "module");
id = mod.id; id = mod.id;
if (typeof factory !== "function") { if (typeof factory !== "function") {
@ -92,4 +82,4 @@ global.define = function (id, injects, factory) {
// since AMD encapsulates a function/callback, it can allow the factory to return the exports. // since AMD encapsulates a function/callback, it can allow the factory to return the exports.
mod.exports = returned; mod.exports = returned;
} }
}; };