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) {
|
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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Ładowanie…
Reference in New Issue