kopia lustrzana https://github.com/c9/core
Fix AMD loader arguments for define()
rodzic
a2dac7050b
commit
e8ee1210b9
|
@ -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;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
Ładowanie…
Reference in New Issue