From e8ee1210b9b824cd19150fec31e311edeaa39bbc Mon Sep 17 00:00:00 2001 From: Alex Brausewetter Date: Fri, 11 Dec 2015 15:39:49 +0100 Subject: [PATCH] Fix AMD loader arguments for define() --- node_modules/amd-loader/amd-loader.js | 46 +++++++++++---------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/node_modules/amd-loader/amd-loader.js b/node_modules/amd-loader/amd-loader.js index 1a8add0a..c4a76a8b 100644 --- a/node_modules/amd-loader/amd-loader.js +++ b/node_modules/amd-loader/amd-loader.js @@ -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; } -}; \ No newline at end of file +};