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) {
var DEFAULT_INJECTS = ["require", "exports", "module"];
// infere the module
// infer the module
var currentModule = moduleStack[moduleStack.length-1];
var mod = currentModule || module.parent || require.main;
// parse arguments
if (!factory) {
// two or less arguments
// assign arguments
if (arguments.length === 1) {
factory = id;
injects = DEFAULT_INJECTS;
id = null;
}
else if (arguments.length === 2) {
factory = injects;
if (factory) {
// two args
if (typeof id === "string") {
if (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 = [];
}
injects = id;
id = null;
}
if (typeof id === "string" && id !== mod.id) {
throw new Error("Can not assign module to a different id than the current file");
}
var req = function(module, relativeId, callback) {
@ -63,12 +55,10 @@ global.define = function (id, injects, factory) {
fileName = fileName[0];
if (prefix && prefix.indexOf("text") !== -1) {
return fs.readFileSync(fileName, "utf8");
return fs.readFileSync(fileName);
} else
return require(fileName);
}.bind(this, mod);
injects.unshift("require", "exports", "module");
id = mod.id;
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.
mod.exports = returned;
}
};
};