diff options
author | Pushkar Joshi | 2012-03-12 15:26:10 -0700 |
---|---|---|
committer | Pushkar Joshi | 2012-03-12 15:26:10 -0700 |
commit | 46b2e561fa6ca054cad58e4c372a598bbb7ee2c9 (patch) | |
tree | 38d1c8666098a10078834c1eaac3d455135bee12 /node_modules/montage/require/node.js | |
parent | 7b4b068cadc0af8ec7e930e1c2b429e945f96984 (diff) | |
parent | 69d90467865a1384725b2301901be2180c5a841f (diff) | |
download | ninja-46b2e561fa6ca054cad58e4c372a598bbb7ee2c9.tar.gz |
Merge branch 'master' into brushtool
Diffstat (limited to 'node_modules/montage/require/node.js')
-rw-r--r-- | node_modules/montage/require/node.js | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/node_modules/montage/require/node.js b/node_modules/montage/require/node.js index 9fcea3f5..3ba5a322 100644 --- a/node_modules/montage/require/node.js +++ b/node_modules/montage/require/node.js | |||
@@ -40,10 +40,13 @@ Require.Compiler = function (config) { | |||
40 | var names = ["require", "exports", "module"]; | 40 | var names = ["require", "exports", "module"]; |
41 | var scopeNames = Object.keys(config.scope); | 41 | var scopeNames = Object.keys(config.scope); |
42 | names.push.apply(names, scopeNames); | 42 | names.push.apply(names, scopeNames); |
43 | return function(module) { | 43 | return function (module) { |
44 | if (module.factory) | 44 | if (module.factory) { |
45 | return module; | 45 | return module; |
46 | if (!module.factory && module.text !== void 0) { | 46 | } else if ( |
47 | module.text !== void 0 && | ||
48 | module.type === "javascript" | ||
49 | ) { | ||
47 | var factory = globalEval( | 50 | var factory = globalEval( |
48 | "(function(" + names.join(",") + "){" + | 51 | "(function(" + names.join(",") + "){" + |
49 | module.text + | 52 | module.text + |
@@ -59,18 +62,41 @@ Require.Compiler = function (config) { | |||
59 | // https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope | 62 | // https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope |
60 | //module.factory = new Function("require", "exports", "module", module.text + "\n//*/\n//@ sourceURL="+module.path); | 63 | //module.factory = new Function("require", "exports", "module", module.text + "\n//*/\n//@ sourceURL="+module.path); |
61 | } | 64 | } |
62 | return module; | ||
63 | }; | 65 | }; |
64 | }; | 66 | }; |
65 | 67 | ||
66 | Require.DefaultLoaderConstructor = function(config) { | 68 | Require.Loader = function (config, load) { |
69 | return function (url, module) { | ||
70 | return Require.read(url) | ||
71 | .then(function (text) { | ||
72 | module.type = "javascript"; | ||
73 | module.text = text; | ||
74 | module.location = url; | ||
75 | }, function (reason, error, rejection) { | ||
76 | return load(url, module); | ||
77 | }); | ||
78 | }; | ||
79 | }; | ||
80 | |||
81 | Require.NodeLoader = function (config) { | ||
82 | return function (url, module) { | ||
83 | var id = url.slice(config.location.length); | ||
84 | return { | ||
85 | type: "native", | ||
86 | exports: require(id), | ||
87 | location: url | ||
88 | } | ||
89 | }; | ||
90 | }; | ||
91 | |||
92 | Require.makeLoader = function(config) { | ||
67 | return Require.MappingsLoader( | 93 | return Require.MappingsLoader( |
68 | config, | 94 | config, |
69 | Require.ExtensionsLoader( | 95 | Require.ExtensionsLoader( |
70 | config, | 96 | config, |
71 | Require.PathsLoader( | 97 | Require.PathsLoader( |
72 | config, | 98 | config, |
73 | Require.CachingLoader( | 99 | Require.MemoizedLoader( |
74 | config, | 100 | config, |
75 | Require.Loader( | 101 | Require.Loader( |
76 | config, | 102 | config, |
@@ -82,17 +108,6 @@ Require.DefaultLoaderConstructor = function(config) { | |||
82 | ); | 108 | ); |
83 | }; | 109 | }; |
84 | 110 | ||
85 | Require.NodeLoader = function (config) { | ||
86 | return function (url, module) { | ||
87 | var id = url.slice(config.location.length); | ||
88 | return { | ||
89 | type: "native", | ||
90 | exports: require(id), | ||
91 | location: url | ||
92 | } | ||
93 | }; | ||
94 | } | ||
95 | |||
96 | Require.main = function () { | 111 | Require.main = function () { |
97 | var require = Require.Sandbox(); | 112 | var require = Require.Sandbox(); |
98 | require.async(process.argv[2]).end(); | 113 | require.async(process.argv[2]).end(); |