Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

bump to requirejs / r.js v2.1 / almond v0.2 / coffee-script 1.3.3

  • Loading branch information...
commit 3c28c113f7f1dcf7c6839b08b616ac5d62230c94 1 parent 0722276
@tkellen authored
View
126 dist/skeleton.js
@@ -2,7 +2,7 @@
var globalDefine = global.define;
/**
- * almond 0.1.2 Copyright (c) 2011, The Dojo Foundation All Rights Reserved.
+ * almond 0.2.0 Copyright (c) 2011, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/almond for details
*/
@@ -13,12 +13,12 @@
var requirejs, require, define;
(function (undef) {
- var defined = {},
+ var main, req, makeMap, handlers,
+ defined = {},
waiting = {},
config = {},
defining = {},
- aps = [].slice,
- main, req;
+ aps = [].slice;
/**
* Given a relative module name, like ./something, normalize it to
@@ -29,11 +29,11 @@ var requirejs, require, define;
* @returns {String} normalized name
*/
function normalize(name, baseName) {
- var baseParts = baseName && baseName.split("/"),
+ var nameParts, nameSegment, mapValue, foundMap,
+ foundI, foundStarMap, starI, i, j, part,
+ baseParts = baseName && baseName.split("/"),
map = config.map,
- starMap = (map && map['*']) || {},
- nameParts, nameSegment, mapValue, foundMap,
- foundI, foundStarMap, starI, i, j, part;
+ starMap = (map && map['*']) || {};
//Adjust any relative paths.
if (name && name.charAt(0) === ".") {
@@ -51,7 +51,8 @@ var requirejs, require, define;
name = baseParts.concat(name.split("/"));
//start trimDots
- for (i = 0; (part = name[i]); i++) {
+ for (i = 0; i < name.length; i += 1) {
+ part = name[i];
if (part === ".") {
name.splice(i, 1);
i -= 1;
@@ -63,7 +64,7 @@ var requirejs, require, define;
//no path mapping for a path starting with '..'.
//This can still fail, but catches the most reasonable
//uses of ..
- return true;
+ break;
} else if (i > 0) {
name.splice(i - 1, 2);
i -= 2;
@@ -159,27 +160,44 @@ var requirejs, require, define;
main.apply(undef, args);
}
- if (!defined.hasOwnProperty(name)) {
+ if (!defined.hasOwnProperty(name) && !defining.hasOwnProperty(name)) {
throw new Error('No ' + name);
}
return defined[name];
}
+ //Turns a plugin!resource to [plugin, resource]
+ //with the plugin being undefined if the name
+ //did not have a plugin prefix.
+ function splitPrefix(name) {
+ var prefix,
+ index = name ? name.indexOf('!') : -1;
+ if (index > -1) {
+ prefix = name.substring(0, index);
+ name = name.substring(index + 1, name.length);
+ }
+ return [prefix, name];
+ }
+
/**
* Makes a name map, normalizing the name, and using a plugin
* for normalization if necessary. Grabs a ref to plugin
* too, as an optimization.
*/
- function makeMap(name, relName) {
- var prefix, plugin,
- index = name.indexOf('!');
+ makeMap = function (name, relName) {
+ var plugin,
+ parts = splitPrefix(name),
+ prefix = parts[0];
- if (index !== -1) {
- prefix = normalize(name.slice(0, index), relName);
- name = name.slice(index + 1);
+ name = parts[1];
+
+ if (prefix) {
+ prefix = normalize(prefix, relName);
plugin = callDep(prefix);
+ }
- //Normalize according
+ //Normalize according
+ if (prefix) {
if (plugin && plugin.normalize) {
name = plugin.normalize(name, makeNormalize(relName));
} else {
@@ -187,15 +205,22 @@ var requirejs, require, define;
}
} else {
name = normalize(name, relName);
+ parts = splitPrefix(name);
+ prefix = parts[0];
+ name = parts[1];
+ if (prefix) {
+ plugin = callDep(prefix);
+ }
}
//Using ridiculous property names for space reasons
return {
f: prefix ? prefix + '!' + name : name, //fullName
n: name,
+ pr: prefix,
p: plugin
};
- }
+ };
function makeConfig(name) {
return function () {
@@ -203,10 +228,32 @@ var requirejs, require, define;
};
}
+ handlers = {
+ require: function (name) {
+ return makeRequire(name);
+ },
+ exports: function (name) {
+ var e = defined[name];
+ if (typeof e !== 'undefined') {
+ return e;
+ } else {
+ return (defined[name] = {});
+ }
+ },
+ module: function (name) {
+ return {
+ id: name,
+ uri: '',
+ exports: defined[name],
+ config: makeConfig(name)
+ };
+ }
+ };
+
main = function (name, deps, callback, relName) {
- var args = [],
- usingExports,
- cjsModule, depName, ret, map, i;
+ var cjsModule, depName, ret, map, i,
+ args = [],
+ usingExports;
//Use name if no relName
relName = relName || name;
@@ -218,31 +265,28 @@ var requirejs, require, define;
//values to the callback.
//Default to [require, exports, module] if no deps
deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
- for (i = 0; i < deps.length; i++) {
+ for (i = 0; i < deps.length; i += 1) {
map = makeMap(deps[i], relName);
depName = map.f;
//Fast path CommonJS standard dependencies.
if (depName === "require") {
- args[i] = makeRequire(name);
+ args[i] = handlers.require(name);
} else if (depName === "exports") {
//CommonJS module spec 1.1
- args[i] = defined[name] = {};
+ args[i] = handlers.exports(name);
usingExports = true;
} else if (depName === "module") {
//CommonJS module spec 1.1
- cjsModule = args[i] = {
- id: name,
- uri: '',
- exports: defined[name],
- config: makeConfig(name)
- };
- } else if (defined.hasOwnProperty(depName) || waiting.hasOwnProperty(depName)) {
+ cjsModule = args[i] = handlers.module(name);
+ } else if (defined.hasOwnProperty(depName) ||
+ waiting.hasOwnProperty(depName) ||
+ defining.hasOwnProperty(depName)) {
args[i] = callDep(depName);
} else if (map.p) {
map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {});
args[i] = defined[depName];
- } else if (!defining[depName]) {
+ } else {
throw new Error(name + ' missing ' + depName);
}
}
@@ -254,7 +298,7 @@ var requirejs, require, define;
//favor that over return value and exports. After that,
//favor a non-undefined return value over exports use.
if (cjsModule && cjsModule.exports !== undef &&
- cjsModule.exports !== defined[name]) {
+ cjsModule.exports !== defined[name]) {
defined[name] = cjsModule.exports;
} else if (ret !== undef || !usingExports) {
//Use the return value from the function.
@@ -268,8 +312,12 @@ var requirejs, require, define;
}
};
- requirejs = require = req = function (deps, callback, relName, forceSync) {
+ requirejs = require = req = function (deps, callback, relName, forceSync, alt) {
if (typeof deps === "string") {
+ if (handlers[deps]) {
+ //callback in this case is really relName
+ return handlers[deps](callback);
+ }
//Just return the module wanted. In this scenario, the
//deps arg is the module name, and second arg (if passed)
//is just the relName.
@@ -292,6 +340,13 @@ var requirejs, require, define;
//Support require(['a'])
callback = callback || function () {};
+ //If relName is a function, it is an errback handler,
+ //so remove it.
+ if (typeof relName === 'function') {
+ relName = forceSync;
+ forceSync = alt;
+ }
+
//Simulate async callback;
if (forceSync) {
main(undef, deps, callback, relName);
@@ -331,7 +386,6 @@ var requirejs, require, define;
jQuery: true
};
}());
-
define("../vendor/almond", function(){});
define('skeleton/core',[],function() {
View
2  dist/skeleton.min.js
@@ -1 +1 @@
-(function(a,b){var c=a.define,d,e,b;(function(a){function l(a,b){var c=b&&b.split("/"),d=g.map,e=d&&d["*"]||{},f,h,i,j,k,l,m,n,o,p;if(a&&a.charAt(0)==="."&&b){c=c.slice(0,c.length-1),a=c.concat(a.split("/"));for(n=0;p=a[n];n++)if(p===".")a.splice(n,1),n-=1;else if(p==="..")if(n!==1||a[2]!==".."&&a[0]!=="..")n>0&&(a.splice(n-1,2),n-=2);else return!0;a=a.join("/")}if((c||e)&&d){f=a.split("/");for(n=f.length;n>0;n-=1){h=f.slice(0,n).join("/");if(c)for(o=c.length;o>0;o-=1){i=d[c.slice(0,o).join("/")];if(i){i=i[h];if(i){j=i,k=n;break}}}if(j)break;!l&&e&&e[h]&&(l=e[h],m=n)}!j&&l&&(j=l,k=m),j&&(f.splice(0,k,j),a=f.join("/"))}return a}function m(b,c){return function(){return k.apply(a,i.call(arguments,0).concat([b,c]))}}function n(a){return function(b){return l(b,a)}}function o(a){return function(b){c[a]=b}}function p(b){if(f.hasOwnProperty(b)){var d=f[b];delete f[b],h[b]=!0,j.apply(a,d)}if(!c.hasOwnProperty(b))throw new Error("No "+b);return c[b]}function q(a,b){var c,d,e=a.indexOf("!");return e!==-1?(c=l(a.slice(0,e),b),a=a.slice(e+1),d=p(c),d&&d.normalize?a=d.normalize(a,n(b)):a=l(a,b)):a=l(a,b),{f:c?c+"!"+a:a,n:a,p:d}}function r(a){return function(){return g&&g.config&&g.config[a]||{}}}var c={},f={},g={},h={},i=[].slice,j,k;j=function(b,d,e,g){var i=[],j,k,l,n,s,t;g=g||b;if(typeof e=="function"){d=!d.length&&e.length?["require","exports","module"]:d;for(t=0;t<d.length;t++){s=q(d[t],g),l=s.f;if(l==="require")i[t]=m(b);else if(l==="exports")i[t]=c[b]={},j=!0;else if(l==="module")k=i[t]={id:b,uri:"",exports:c[b],config:r(b)};else if(c.hasOwnProperty(l)||f.hasOwnProperty(l))i[t]=p(l);else if(s.p)s.p.load(s.n,m(g,!0),o(l),{}),i[t]=c[l];else if(!h[l])throw new Error(b+" missing "+l)}n=e.apply(c[b],i);if(b)if(k&&k.exports!==a&&k.exports!==c[b])c[b]=k.exports;else if(n!==a||!j)c[b]=n}else b&&(c[b]=e)},d=e=k=function(b,c,d,e){return typeof b=="string"?p(q(b,c).f):(b.splice||(g=b,c.splice?(b=c,c=d,d=null):b=a),c=c||function(){},e?j(a,b,c,d):setTimeout(function(){j(a,b,c,d)},15),k)},k.config=function(a){return g=a,k},b=function(a,b,c){b.splice||(c=b,b=[]),f[a]=[a,b,c]},b.amd={jQuery:!0}})(),b("../vendor/almond",function(){}),b("skeleton/core",[],function(){var a={VERSION:"0.1.5"};return a}),b("skeleton/feature",[],function(){return function(){return"working"}}),b("skeleton/module",[],function(){return{method:function(){return"it does"}}}),b("coffee-script",{}),b("cs",{load:function(a){throw new Error("Dynamic load not allowed: "+a)}}),function(){b("cs!skeleton/coffeescript",[],function(){return function(){return"working"}})}.call(this),b("skeleton",["require","skeleton/core","skeleton/feature","skeleton/module","cs!skeleton/coffeescript"],function(a){var b=a("skeleton/core");return b.feature=a("skeleton/feature"),b.module=a("skeleton/module"),b.coffeescript=a("cs!skeleton/coffeescript"),b});var f=e("skeleton");typeof module!="undefined"&&module.exports?module.exports=f:c?function(a){a(function(){return f})}(c):a.skeleton=f})(this);
+(function(e,t){var n=e.define,r,i,t;(function(e){function p(e,t){var n,r,i,s,o,u,a,f,c,h,p=t&&t.split("/"),d=l.map,v=d&&d["*"]||{};if(e&&e.charAt(0)==="."&&t){p=p.slice(0,p.length-1),e=p.concat(e.split("/"));for(f=0;f<e.length;f+=1){h=e[f];if(h===".")e.splice(f,1),f-=1;else if(h===".."){if(f===1&&(e[2]===".."||e[0]===".."))break;f>0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function d(t,n){return function(){return s.apply(e,h.call(arguments,0).concat([t,n]))}}function v(e){return function(t){return p(t,e)}}function m(e){return function(t){a[e]=t}}function g(t){if(f.hasOwnProperty(t)){var r=f[t];delete f[t],c[t]=!0,n.apply(e,r)}if(!a.hasOwnProperty(t)&&!c.hasOwnProperty(t))throw new Error("No "+t);return a[t]}function y(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function b(e){return function(){return l&&l.config&&l.config[e]||{}}}var n,s,o,u,a={},f={},l={},c={},h=[].slice;o=function(e,t){var n,r=y(e),i=r[0];return e=r[1],i&&(i=p(i,t),n=g(i)),i?n&&n.normalize?e=n.normalize(e,v(t)):e=p(e,t):(e=p(e,t),r=y(e),i=r[0],e=r[1],i&&(n=g(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return d(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:b(e)}}},n=function(t,n,r,i){var s,l,h,p,v,y=[],b;i=i||t;if(typeof r=="function"){n=!n.length&&r.length?["require","exports","module"]:n;for(v=0;v<n.length;v+=1){p=o(n[v],i),l=p.f;if(l==="require")y[v]=u.require(t);else if(l==="exports")y[v]=u.exports(t),b=!0;else if(l==="module")s=y[v]=u.module(t);else if(a.hasOwnProperty(l)||f.hasOwnProperty(l)||c.hasOwnProperty(l))y[v]=g(l);else{if(!p.p)throw new Error(t+" missing "+l);p.p.load(p.n,d(i,!0),m(l),{}),y[v]=a[l]}}h=r.apply(a[t],y);if(t)if(s&&s.exports!==e&&s.exports!==a[t])a[t]=s.exports;else if(h!==e||!b)a[t]=h}else t&&(a[t]=r)},r=i=s=function(t,r,i,a,f){return typeof t=="string"?u[t]?u[t](r):g(o(t,r).f):(t.splice||(l=t,r.splice?(t=r,r=i,i=null):t=e),r=r||function(){},typeof i=="function"&&(i=a,a=f),a?n(e,t,r,i):setTimeout(function(){n(e,t,r,i)},15),s)},s.config=function(e){return l=e,s},t=function(e,t,n){t.splice||(n=t,t=[]),f[e]=[e,t,n]},t.amd={jQuery:!0}})(),t("../vendor/almond",function(){}),t("skeleton/core",[],function(){var e={VERSION:"0.1.5"};return e}),t("skeleton/feature",[],function(){return function(){return"working"}}),t("skeleton/module",[],function(){return{method:function(){return"it does"}}}),t("coffee-script",{}),t("cs",{load:function(e){throw new Error("Dynamic load not allowed: "+e)}}),function(){t("cs!skeleton/coffeescript",[],function(){return function(){return"working"}})}.call(this),t("skeleton",["require","skeleton/core","skeleton/feature","skeleton/module","cs!skeleton/coffeescript"],function(e){var t=e("skeleton/core");return t.feature=e("skeleton/feature"),t.module=e("skeleton/module"),t.coffeescript=e("cs!skeleton/coffeescript"),t});var s=i("skeleton");typeof module!="undefined"&&module.exports?module.exports=s:n?function(e){e(function(){return s})}(n):e.skeleton=s})(this);
View
2  grunt.js
@@ -26,7 +26,7 @@ module.exports = function(grunt) {
});
// Load external tasks
- grunt.loadNpmTasks('grunt-contrib');
+ grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-jasmine-task');
// Make task shortcuts
View
6 package.json
@@ -30,10 +30,10 @@
"test": "grunt test"
},
"devDependencies": {
- "grunt": "~0.3.11",
- "grunt-contrib": "*",
+ "grunt": "~0.3.16",
+ "grunt-contrib-requirejs": "~0.3.2",
"grunt-jasmine-task": "*",
- "requirejs": "*",
+ "requirejs": "~2.1.0",
"coffee-script": "*",
"servedir": "*"
}
View
5 test/runner.html
@@ -1,6 +1,7 @@
<!doctype html>
<html>
-<head>
+<head lang="en">
+ <meta charset="utf-8"/>
<title>Test Runner</title>
<link rel="stylesheet" type="text/css" href="../vendor/jasmine/jasmine.css">
<script src="../vendor/jasmine/jasmine.js"></script>
@@ -27,7 +28,7 @@
'spec/cs'
],
function() {
- jasmine.getEnv().addReporter(new jasmine.HtmlReporter());
+ jasmine.getEnv().addReporter(new jasmine.HtmlReporter());
jasmine.getEnv().execute();
});
</script>
View
127 vendor/almond.js
@@ -1,5 +1,5 @@
/**
- * almond 0.1.2 Copyright (c) 2011, The Dojo Foundation All Rights Reserved.
+ * almond 0.2.0 Copyright (c) 2011, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/almond for details
*/
@@ -10,12 +10,12 @@
var requirejs, require, define;
(function (undef) {
- var defined = {},
+ var main, req, makeMap, handlers,
+ defined = {},
waiting = {},
config = {},
defining = {},
- aps = [].slice,
- main, req;
+ aps = [].slice;
/**
* Given a relative module name, like ./something, normalize it to
@@ -26,11 +26,11 @@ var requirejs, require, define;
* @returns {String} normalized name
*/
function normalize(name, baseName) {
- var baseParts = baseName && baseName.split("/"),
+ var nameParts, nameSegment, mapValue, foundMap,
+ foundI, foundStarMap, starI, i, j, part,
+ baseParts = baseName && baseName.split("/"),
map = config.map,
- starMap = (map && map['*']) || {},
- nameParts, nameSegment, mapValue, foundMap,
- foundI, foundStarMap, starI, i, j, part;
+ starMap = (map && map['*']) || {};
//Adjust any relative paths.
if (name && name.charAt(0) === ".") {
@@ -48,7 +48,8 @@ var requirejs, require, define;
name = baseParts.concat(name.split("/"));
//start trimDots
- for (i = 0; (part = name[i]); i++) {
+ for (i = 0; i < name.length; i += 1) {
+ part = name[i];
if (part === ".") {
name.splice(i, 1);
i -= 1;
@@ -60,7 +61,7 @@ var requirejs, require, define;
//no path mapping for a path starting with '..'.
//This can still fail, but catches the most reasonable
//uses of ..
- return true;
+ break;
} else if (i > 0) {
name.splice(i - 1, 2);
i -= 2;
@@ -156,27 +157,44 @@ var requirejs, require, define;
main.apply(undef, args);
}
- if (!defined.hasOwnProperty(name)) {
+ if (!defined.hasOwnProperty(name) && !defining.hasOwnProperty(name)) {
throw new Error('No ' + name);
}
return defined[name];
}
+ //Turns a plugin!resource to [plugin, resource]
+ //with the plugin being undefined if the name
+ //did not have a plugin prefix.
+ function splitPrefix(name) {
+ var prefix,
+ index = name ? name.indexOf('!') : -1;
+ if (index > -1) {
+ prefix = name.substring(0, index);
+ name = name.substring(index + 1, name.length);
+ }
+ return [prefix, name];
+ }
+
/**
* Makes a name map, normalizing the name, and using a plugin
* for normalization if necessary. Grabs a ref to plugin
* too, as an optimization.
*/
- function makeMap(name, relName) {
- var prefix, plugin,
- index = name.indexOf('!');
+ makeMap = function (name, relName) {
+ var plugin,
+ parts = splitPrefix(name),
+ prefix = parts[0];
+
+ name = parts[1];
- if (index !== -1) {
- prefix = normalize(name.slice(0, index), relName);
- name = name.slice(index + 1);
+ if (prefix) {
+ prefix = normalize(prefix, relName);
plugin = callDep(prefix);
+ }
- //Normalize according
+ //Normalize according
+ if (prefix) {
if (plugin && plugin.normalize) {
name = plugin.normalize(name, makeNormalize(relName));
} else {
@@ -184,15 +202,22 @@ var requirejs, require, define;
}
} else {
name = normalize(name, relName);
+ parts = splitPrefix(name);
+ prefix = parts[0];
+ name = parts[1];
+ if (prefix) {
+ plugin = callDep(prefix);
+ }
}
//Using ridiculous property names for space reasons
return {
f: prefix ? prefix + '!' + name : name, //fullName
n: name,
+ pr: prefix,
p: plugin
};
- }
+ };
function makeConfig(name) {
return function () {
@@ -200,10 +225,32 @@ var requirejs, require, define;
};
}
+ handlers = {
+ require: function (name) {
+ return makeRequire(name);
+ },
+ exports: function (name) {
+ var e = defined[name];
+ if (typeof e !== 'undefined') {
+ return e;
+ } else {
+ return (defined[name] = {});
+ }
+ },
+ module: function (name) {
+ return {
+ id: name,
+ uri: '',
+ exports: defined[name],
+ config: makeConfig(name)
+ };
+ }
+ };
+
main = function (name, deps, callback, relName) {
- var args = [],
- usingExports,
- cjsModule, depName, ret, map, i;
+ var cjsModule, depName, ret, map, i,
+ args = [],
+ usingExports;
//Use name if no relName
relName = relName || name;
@@ -215,31 +262,28 @@ var requirejs, require, define;
//values to the callback.
//Default to [require, exports, module] if no deps
deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
- for (i = 0; i < deps.length; i++) {
+ for (i = 0; i < deps.length; i += 1) {
map = makeMap(deps[i], relName);
depName = map.f;
//Fast path CommonJS standard dependencies.
if (depName === "require") {
- args[i] = makeRequire(name);
+ args[i] = handlers.require(name);
} else if (depName === "exports") {
//CommonJS module spec 1.1
- args[i] = defined[name] = {};
+ args[i] = handlers.exports(name);
usingExports = true;
} else if (depName === "module") {
//CommonJS module spec 1.1
- cjsModule = args[i] = {
- id: name,
- uri: '',
- exports: defined[name],
- config: makeConfig(name)
- };
- } else if (defined.hasOwnProperty(depName) || waiting.hasOwnProperty(depName)) {
+ cjsModule = args[i] = handlers.module(name);
+ } else if (defined.hasOwnProperty(depName) ||
+ waiting.hasOwnProperty(depName) ||
+ defining.hasOwnProperty(depName)) {
args[i] = callDep(depName);
} else if (map.p) {
map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {});
args[i] = defined[depName];
- } else if (!defining[depName]) {
+ } else {
throw new Error(name + ' missing ' + depName);
}
}
@@ -251,7 +295,7 @@ var requirejs, require, define;
//favor that over return value and exports. After that,
//favor a non-undefined return value over exports use.
if (cjsModule && cjsModule.exports !== undef &&
- cjsModule.exports !== defined[name]) {
+ cjsModule.exports !== defined[name]) {
defined[name] = cjsModule.exports;
} else if (ret !== undef || !usingExports) {
//Use the return value from the function.
@@ -265,8 +309,12 @@ var requirejs, require, define;
}
};
- requirejs = require = req = function (deps, callback, relName, forceSync) {
+ requirejs = require = req = function (deps, callback, relName, forceSync, alt) {
if (typeof deps === "string") {
+ if (handlers[deps]) {
+ //callback in this case is really relName
+ return handlers[deps](callback);
+ }
//Just return the module wanted. In this scenario, the
//deps arg is the module name, and second arg (if passed)
//is just the relName.
@@ -289,6 +337,13 @@ var requirejs, require, define;
//Support require(['a'])
callback = callback || function () {};
+ //If relName is a function, it is an errback handler,
+ //so remove it.
+ if (typeof relName === 'function') {
+ relName = forceSync;
+ forceSync = alt;
+ }
+
//Simulate async callback;
if (forceSync) {
main(undef, deps, callback, relName);
@@ -327,4 +382,4 @@ var requirejs, require, define;
define.amd = {
jQuery: true
};
-}());
+}());
View
4 vendor/coffee-script.js
2 additions, 2 deletions not shown
View
1,393 vendor/r.js
754 additions, 639 deletions not shown
View
691 vendor/require.js
@@ -1,5 +1,5 @@
/** vim: et:ts=4:sw=4:sts=4
- * @license RequireJS 2.0.5 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
+ * @license RequireJS 2.1.0 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/requirejs for details
*/
@@ -12,7 +12,7 @@ var requirejs, require, define;
(function (global) {
var req, s, head, baseElement, dataMain, src,
interactiveScript, currentlyAddingScript, mainScript, subPath,
- version = '2.0.5',
+ version = '2.1.0',
commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
jsSuffixRegExp = /\.js$/,
@@ -147,41 +147,6 @@ var requirejs, require, define;
return g;
}
- function makeContextModuleFunc(func, relMap, enableBuildCallback) {
- return function () {
- //A version of a require function that passes a moduleName
- //value for items that may need to
- //look up paths relative to the moduleName
- var args = aps.call(arguments, 0), lastArg;
- if (enableBuildCallback &&
- isFunction((lastArg = args[args.length - 1]))) {
- lastArg.__requireJsBuild = true;
- }
- args.push(relMap);
- return func.apply(null, args);
- };
- }
-
- function addRequireMethods(req, context, relMap) {
- each([
- ['toUrl'],
- ['undef'],
- ['defined', 'requireDefined'],
- ['specified', 'requireSpecified']
- ], function (item) {
- var prop = item[1] || item[0];
- req[item[0]] = context ? makeContextModuleFunc(context[prop], relMap) :
- //If no context, then use default context. Reference from
- //contexts instead of early binding to default context, so
- //that during builds, the latest instance of the default
- //context with its config gets used.
- function () {
- var ctx = contexts[defContextName];
- return ctx[prop].apply(ctx, arguments);
- };
- });
- }
-
/**
* Constructs an error with a pointer to an URL with more information.
* @param {String} id the error ID that maps to an ID on a web page.
@@ -238,12 +203,7 @@ var requirejs, require, define;
defined = {},
urlFetched = {},
requireCounter = 1,
- unnormalizedCounter = 1,
- //Used to track the order in which modules
- //should be executed, by the order they
- //load. Important for consistent cycle resolution
- //behavior.
- waitAry = [];
+ unnormalizedCounter = 1;
/**
* Trims the . and .. from an array of path segments.
@@ -405,12 +365,25 @@ var requirejs, require, define;
//Pop off the first array value, since it failed, and
//retry
pathConfig.shift();
- context.undef(id);
+ context.require.undef(id);
context.require([id]);
return true;
}
}
+ //Turns a plugin!resource to [plugin, resource]
+ //with the plugin being undefined if the name
+ //did not have a plugin prefix.
+ function splitPrefix(name) {
+ var prefix,
+ index = name ? name.indexOf('!') : -1;
+ if (index > -1) {
+ prefix = name.substring(0, index);
+ name = name.substring(index + 1, name.length);
+ }
+ return [prefix, name];
+ }
+
/**
* Creates a module mapping that includes plugin prefix, module
* name, and path. If parentModuleMap is provided it will
@@ -427,8 +400,7 @@ var requirejs, require, define;
* @returns {Object}
*/
function makeModuleMap(name, parentModuleMap, isNormalized, applyMap) {
- var url, pluginModule, suffix,
- index = name ? name.indexOf('!') : -1,
+ var url, pluginModule, suffix, nameParts,
prefix = null,
parentName = parentModuleMap ? parentModuleMap.name : null,
originalName = name,
@@ -442,10 +414,9 @@ var requirejs, require, define;
name = '_@r' + (requireCounter += 1);
}
- if (index !== -1) {
- prefix = name.substring(0, index);
- name = name.substring(index + 1, name.length);
- }
+ nameParts = splitPrefix(name);
+ prefix = nameParts[0];
+ name = nameParts[1];
if (prefix) {
prefix = normalize(prefix, parentName, applyMap);
@@ -466,6 +437,15 @@ var requirejs, require, define;
} else {
//A regular module.
normalizedName = normalize(name, parentName, applyMap);
+
+ //Normalized name may be a plugin ID due to map config
+ //application in normalize. The map config values must
+ //already be normalized, so do not need to redo that part.
+ nameParts = splitPrefix(normalizedName);
+ prefix = nameParts[0];
+ normalizedName = nameParts[1];
+ isNormalized = true;
+
url = context.nameToUrl(normalizedName);
}
}
@@ -557,160 +537,71 @@ var requirejs, require, define;
}
}
- /**
- * Helper function that creates a require function object to give to
- * modules that ask for it as a dependency. It needs to be specific
- * per module because of the implication of path mappings that may
- * need to be relative to the module name.
- */
- function makeRequire(mod, enableBuildCallback, altRequire) {
- var relMap = mod && mod.map,
- modRequire = makeContextModuleFunc(altRequire || context.require,
- relMap,
- enableBuildCallback);
-
- addRequireMethods(modRequire, context, relMap);
- modRequire.isBrowser = isBrowser;
-
- return modRequire;
- }
-
handlers = {
'require': function (mod) {
- return makeRequire(mod);
+ if (mod.require) {
+ return mod.require;
+ } else {
+ return (mod.require = context.makeRequire(mod.map));
+ }
},
'exports': function (mod) {
mod.usingExports = true;
if (mod.map.isDefine) {
- return (mod.exports = defined[mod.map.id] = {});
+ if (mod.exports) {
+ return mod.exports;
+ } else {
+ return (mod.exports = defined[mod.map.id] = {});
+ }
}
},
'module': function (mod) {
- return (mod.module = {
- id: mod.map.id,
- uri: mod.map.url,
- config: function () {
- return (config.config && config.config[mod.map.id]) || {};
- },
- exports: defined[mod.map.id]
- });
+ if (mod.module) {
+ return mod.module;
+ } else {
+ return (mod.module = {
+ id: mod.map.id,
+ uri: mod.map.url,
+ config: function () {
+ return (config.config && config.config[mod.map.id]) || {};
+ },
+ exports: defined[mod.map.id]
+ });
+ }
}
};
- function removeWaiting(id) {
+ function cleanRegistry(id) {
//Clean up machinery used for waiting modules.
delete registry[id];
-
- each(waitAry, function (mod, i) {
- if (mod.map.id === id) {
- waitAry.splice(i, 1);
- if (!mod.defined) {
- context.waitCount -= 1;
- }
- return true;
- }
- });
- }
-
- function findCycle(mod, traced) {
- var id = mod.map.id,
- depArray = mod.depMaps,
- foundModule;
-
- //Do not bother with unitialized modules or not yet enabled
- //modules.
- if (!mod.inited) {
- return;
- }
-
- //Found the cycle.
- if (traced[id]) {
- return mod;
- }
-
- traced[id] = true;
-
- //Trace through the dependencies.
- each(depArray, function (depMap) {
- var depId = depMap.id,
- depMod = registry[depId];
-
- if (!depMod) {
- return;
- }
-
- if (!depMod.inited || !depMod.enabled) {
- //Dependency is not inited, so this cannot
- //be used to determine a cycle.
- foundModule = null;
- delete traced[id];
- return true;
- }
-
- //mixin traced to a new object for each dependency, so that
- //sibling dependencies in this object to not generate a
- //false positive match on a cycle. Ideally an Object.create
- //type of prototype delegation would be used here, but
- //optimizing for file size vs. execution speed since hopefully
- //the trees are small for circular dependency scans relative
- //to the full app perf.
- return (foundModule = findCycle(depMod, mixin({}, traced)));
- });
-
- return foundModule;
}
- function forceExec(mod, traced, uninited) {
- var id = mod.map.id,
- depArray = mod.depMaps;
-
- if (!mod.inited || !mod.map.isDefine) {
- return;
- }
-
- if (traced[id]) {
- return defined[id];
- }
-
- traced[id] = mod;
-
- each(depArray, function (depMap) {
- var depId = depMap.id,
- depMod = registry[depId],
- value;
-
- if (handlers[depId]) {
- return;
- }
+ function breakCycle(mod, traced, processed) {
+ var id = mod.map.id;
- if (depMod) {
- if (!depMod.inited || !depMod.enabled) {
- //Dependency is not inited,
- //so this module cannot be
- //given a forced value yet.
- uninited[id] = true;
- return;
- }
-
- //Get the value for the current dependency
- value = forceExec(depMod, traced, uninited);
-
- //Even with forcing it may not be done,
- //in particular if the module is waiting
- //on a plugin resource.
- if (!uninited[depId]) {
- mod.defineDepById(depId, value);
+ if (mod.error) {
+ mod.emit('error', mod.error);
+ } else {
+ traced[id] = true;
+ each(mod.depMaps, function (depMap, i) {
+ var depId = depMap.id,
+ dep = registry[depId];
+
+ //Only force things that have not completed
+ //being defined, so still in the registry,
+ //and only if it has not been matched up
+ //in the module already.
+ if (dep && !mod.depMatched[i] && !processed[depId]) {
+ if (traced[depId]) {
+ mod.defineDep(i, defined[depId]);
+ mod.check(); //pass false?
+ } else {
+ breakCycle(dep, traced, processed);
+ }
}
- }
- });
-
- mod.check(true);
-
- return defined[id];
- }
-
- function modCheck(mod) {
- mod.check();
+ });
+ processed[id] = true;
+ }
}
function checkLoaded() {
@@ -719,6 +610,7 @@ var requirejs, require, define;
//It is possible to disable the wait interval by using waitSeconds of 0.
expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
noLoads = [],
+ reqCalls = [],
stillLoading = false,
needCycleCheck = true;
@@ -739,6 +631,10 @@ var requirejs, require, define;
return;
}
+ if (!map.isDefine) {
+ reqCalls.push(mod);
+ }
+
if (!mod.error) {
//If the module should be executed, and it has not
//been inited and time is up, remember it.
@@ -773,31 +669,9 @@ var requirejs, require, define;
//Not expired, check for a cycle.
if (needCycleCheck) {
-
- each(waitAry, function (mod) {
- if (mod.defined) {
- return;
- }
-
- var cycleMod = findCycle(mod, {}),
- traced = {};
-
- if (cycleMod) {
- forceExec(cycleMod, traced, {});
-
- //traced modules may have been
- //removed from the registry, but
- //their listeners still need to
- //be called.
- eachProp(traced, modCheck);
- }
+ each(reqCalls, function (mod) {
+ breakCycle(mod, {}, {});
});
-
- //Now that dependencies have
- //been satisfied, trigger the
- //completion check that then
- //notifies listeners.
- eachProp(registry, modCheck);
}
//If still waiting on loads, and the waiting load is something
@@ -863,7 +737,6 @@ var requirejs, require, define;
//doing a direct modification of the depMaps array
//would affect that config.
this.depMaps = depMaps && depMaps.slice(0);
- this.depMaps.rjsSkipMap = depMaps.rjsSkipMap;
this.errback = errback;
@@ -885,20 +758,6 @@ var requirejs, require, define;
}
},
- defineDepById: function (id, depExports) {
- var i;
-
- //Find the index for this dependency.
- each(this.depMaps, function (map, index) {
- if (map.id === id) {
- i = index;
- return true;
- }
- });
-
- return this.defineDep(i, depExports);
- },
-
defineDep: function (i, depExports) {
//Because of cycles, defined callback for a given
//export can be called more than once.
@@ -922,7 +781,9 @@ var requirejs, require, define;
//If the manager is for a plugin managed resource,
//ask the plugin to load it now.
if (this.shim) {
- makeRequire(this, true)(this.shim.deps || [], bind(this, function () {
+ context.makeRequire(this.map, {
+ enableBuildCallback: true
+ })(this.shim.deps || [], bind(this, function () {
return map.prefix ? this.callPlugin() : this.load();
}));
} else {
@@ -943,11 +804,9 @@ var requirejs, require, define;
/**
* Checks is the module is ready to define itself, and if so,
- * define it. If the silent argument is true, then it will just
- * define, but not notify listeners, and not ask for a context-wide
- * check of all loaded modules. That is useful for cycle breaking.
+ * define it.
*/
- check: function (silent) {
+ check: function () {
if (!this.enabled || this.enabling) {
return;
}
@@ -1025,11 +884,6 @@ var requirejs, require, define;
delete registry[id];
this.defined = true;
- context.waitCount -= 1;
- if (context.waitCount === 0) {
- //Clear the wait array used for cycles.
- waitAry = [];
- }
}
//Finished the define stage. Allow calling check again
@@ -1037,25 +891,33 @@ var requirejs, require, define;
//cycle.
this.defining = false;
- if (!silent) {
- if (this.defined && !this.defineEmitted) {
- this.defineEmitted = true;
- this.emit('defined', this.exports);
- this.defineEmitComplete = true;
- }
+ if (this.defined && !this.defineEmitted) {
+ this.defineEmitted = true;
+ this.emit('defined', this.exports);
+ this.defineEmitComplete = true;
}
+
}
},
callPlugin: function () {
var map = this.map,
id = map.id,
- pluginMap = makeModuleMap(map.prefix, null, false, true);
+ //Map already normalized the prefix.
+ pluginMap = makeModuleMap(map.prefix);
+
+ //Mark this as a dependency for this plugin, so it
+ //can be traced for cycles.
+ this.depMaps.push(pluginMap);
on(pluginMap, 'defined', bind(this, function (plugin) {
var load, normalizedMap, normalizedMod,
name = this.map.name,
- parentName = this.map.parentMap ? this.map.parentMap.name : null;
+ parentName = this.map.parentMap ? this.map.parentMap.name : null,
+ localRequire = context.makeRequire(map.parentMap, {
+ enableBuildCallback: true,
+ skipMap: true
+ });
//If current map is not normalized, wait for that
//normalized name to load instead of continuing.
@@ -1067,10 +929,10 @@ var requirejs, require, define;
}) || '';
}
+ //prefix and name should already be normalized, no need
+ //for applying map config again either.
normalizedMap = makeModuleMap(map.prefix + '!' + name,
- this.map.parentMap,
- false,
- true);
+ this.map.parentMap);
on(normalizedMap,
'defined', bind(this, function (value) {
this.init([], function () { return value; }, null, {
@@ -1078,8 +940,13 @@ var requirejs, require, define;
ignore: true
});
}));
+
normalizedMod = registry[normalizedMap.id];
if (normalizedMod) {
+ //Mark this as a dependency for this plugin, so it
+ //can be traced for cycles.
+ this.depMaps.push(normalizedMap);
+
if (this.events.error) {
normalizedMod.on('error', bind(this, function (err) {
this.emit('error', err);
@@ -1106,7 +973,7 @@ var requirejs, require, define;
//since they will never be resolved otherwise now.
eachProp(registry, function (mod) {
if (mod.map.id.indexOf(id + '_unnormalized') === 0) {
- removeWaiting(mod.map.id);
+ cleanRegistry(mod.map.id);
}
});
@@ -1115,9 +982,19 @@ var requirejs, require, define;
//Allow plugins to load other code without having to know the
//context or how to 'complete' the load.
- load.fromText = function (moduleName, text) {
+ load.fromText = bind(this, function (text, textAlt) {
/*jslint evil: true */
- var hasInteractive = useInteractive;
+ var moduleName = map.name,
+ moduleMap = makeModuleMap(moduleName),
+ hasInteractive = useInteractive;
+
+ //As of 2.1.0, support just passing the text, to reinforce
+ //fromText only being called once per resource. Still
+ //support old style of passing moduleName but discard
+ //that moduleName in favor of the internal ref.
+ if (textAlt) {
+ text = textAlt;
+ }
//Turn off interactive script matching for IE for any define
//calls in the text, then turn it back on at the end.
@@ -1127,25 +1004,35 @@ var requirejs, require, define;
//Prime the system by creating a module instance for
//it.
- getModule(makeModuleMap(moduleName));
+ getModule(moduleMap);
- req.exec(text);
+ try {
+ req.exec(text);
+ } catch (e) {
+ throw new Error('fromText eval for ' + moduleName +
+ ' failed: ' + e);
+ }
if (hasInteractive) {
useInteractive = true;
}
+ //Mark this as a dependency for the plugin
+ //resource
+ this.depMaps.push(moduleMap);
+
//Support anonymous modules.
context.completeLoad(moduleName);
- };
+
+ //Bind the value of that module to the value for this
+ //resource ID.
+ localRequire([moduleName], load);
+ });
//Use parentName here since the plugin's name is not reliable,
//could be some weird string with no path that actually wants to
//reference the parentName's path.
- plugin.load(map.name, makeRequire(map.parentMap, true, function (deps, cb, er) {
- deps.rjsSkipMap = true;
- return context.require(deps, cb, er);
- }), load, config);
+ plugin.load(map.name, localRequire, load, config);
}));
context.enable(pluginMap, this);
@@ -1155,12 +1042,6 @@ var requirejs, require, define;
enable: function () {
this.enabled = true;
- if (!this.waitPushed) {
- waitAry.push(this);
- context.waitCount += 1;
- this.waitPushed = true;
- }
-
//Set flag mentioning that the module is enabling,
//so that immediate calls to the defined callbacks
//for dependencies do not trigger inadvertent load
@@ -1177,7 +1058,7 @@ var requirejs, require, define;
depMap = makeModuleMap(depMap,
(this.map.isDefine ? this.map : this.map.parentMap),
false,
- !this.depMaps.rjsSkipMap);
+ !this.skipMap);
this.depMaps[i] = depMap;
handler = handlers[depMap.id];
@@ -1239,7 +1120,7 @@ var requirejs, require, define;
if (name === 'error') {
//Now that the error handler was triggered, remove
//the listeners, since this broken Module instance
- //can stay around for a while in the registry/waitAry.
+ //can stay around for a while in the registry.
delete this.events[name];
}
}
@@ -1286,16 +1167,16 @@ var requirejs, require, define;
};
}
- return (context = {
+ context = {
config: config,
contextName: contextName,
registry: registry,
defined: defined,
urlFetched: urlFetched,
- waitCount: 0,
defQueue: defQueue,
Module: Module,
makeModuleMap: makeModuleMap,
+ nextTick: req.nextTick,
/**
* Set a configuration for the context.
@@ -1337,8 +1218,8 @@ var requirejs, require, define;
deps: value
};
}
- if (value.exports && !value.exports.__buildReady) {
- value.exports = context.makeShimExports(value.exports);
+ if (value.exports && !value.exportsFn) {
+ value.exportsFn = context.makeShimExports(value);
}
shim[id] = value;
});
@@ -1393,125 +1274,152 @@ var requirejs, require, define;
}
},
- makeShimExports: function (exports) {
- var func;
- if (typeof exports === 'string') {
- func = function () {
- return getGlobal(exports);
- };
- //Save the exports for use in nodefine checking.
- func.exports = exports;
- return func;
- } else {
- return function () {
- return exports.apply(global, arguments);
- };
+ makeShimExports: function (value) {
+ function fn() {
+ var ret;
+ if (value.init) {
+ ret = value.init.apply(global, arguments);
+ }
+ return ret || getGlobal(value.exports);
}
+ return fn;
},
- requireDefined: function (id, relMap) {
- return hasProp(defined, makeModuleMap(id, relMap, false, true).id);
- },
+ makeRequire: function (relMap, options) {
+ options = options || {};
- requireSpecified: function (id, relMap) {
- id = makeModuleMap(id, relMap, false, true).id;
- return hasProp(defined, id) || hasProp(registry, id);
- },
+ function require(deps, callback, errback) {
+ var id, map, requireMod, args;
- require: function (deps, callback, errback, relMap) {
- var moduleName, id, map, requireMod, args;
- if (typeof deps === 'string') {
- if (isFunction(callback)) {
- //Invalid call
- return onError(makeError('requireargs', 'Invalid require call'), errback);
+ if (options.enableBuildCallback && callback && isFunction(callback)) {
+ callback.__requireJsBuild = true;
}
- //Synchronous access to one module. If require.get is
- //available (as in the Node adapter), prefer that.
- //In this case deps is the moduleName and callback is
- //the relMap
- if (req.get) {
- return req.get(context, deps, callback);
- }
+ if (typeof deps === 'string') {
+ if (isFunction(callback)) {
+ //Invalid call
+ return onError(makeError('requireargs', 'Invalid require call'), errback);
+ }
- //Just return the module wanted. In this scenario, the
- //second arg (if passed) is just the relMap.
- moduleName = deps;
- relMap = callback;
+ //If require|exports|module are requested, get the
+ //value for them from the special handlers. Caveat:
+ //this only works while module is being defined.
+ if (relMap && handlers[deps]) {
+ return handlers[deps](registry[relMap.id]);
+ }
- //Normalize module name, if it contains . or ..
- map = makeModuleMap(moduleName, relMap, false, true);
- id = map.id;
+ //Synchronous access to one module. If require.get is
+ //available (as in the Node adapter), prefer that.
+ if (req.get) {
+ return req.get(context, deps, relMap);
+ }
- if (!hasProp(defined, id)) {
- return onError(makeError('notloaded', 'Module name "' +
- id +
- '" has not been loaded yet for context: ' +
- contextName));
- }
- return defined[id];
- }
+ //Normalize module name, if it contains . or ..
+ map = makeModuleMap(deps, relMap, false, true);
+ id = map.id;
- //Callback require. Normalize args. if callback or errback is
- //not a function, it means it is a relMap. Test errback first.
- if (errback && !isFunction(errback)) {
- relMap = errback;
- errback = undefined;
- }
- if (callback && !isFunction(callback)) {
- relMap = callback;
- callback = undefined;
- }
+ if (!hasProp(defined, id)) {
+ return onError(makeError('notloaded', 'Module name "' +
+ id +
+ '" has not been loaded yet for context: ' +
+ contextName +
+ (relMap ? '' : '. Use require([])')));
+ }
+ return defined[id];
+ }
- //Any defined modules in the global queue, intake them now.
- takeGlobalQueue();
+ //Any defined modules in the global queue, intake them now.
+ takeGlobalQueue();
- //Make sure any remaining defQueue items get properly processed.
- while (defQueue.length) {
- args = defQueue.shift();
- if (args[0] === null) {
- return onError(makeError('mismatch', 'Mismatched anonymous define() module: ' + args[args.length - 1]));
- } else {
- //args are id, deps, factory. Should be normalized by the
- //define() function.
- callGetModule(args);
+ //Make sure any remaining defQueue items get properly processed.
+ while (defQueue.length) {
+ args = defQueue.shift();
+ if (args[0] === null) {
+ return onError(makeError('mismatch', 'Mismatched anonymous define() module: ' + args[args.length - 1]));
+ } else {
+ //args are id, deps, factory. Should be normalized by the
+ //define() function.
+ callGetModule(args);
+ }
}
- }
- //Mark all the dependencies as needing to be loaded.
- requireMod = getModule(makeModuleMap(null, relMap));
+ //Mark all the dependencies as needing to be loaded.
+ context.nextTick(function () {
+ requireMod = getModule(makeModuleMap(null, relMap));
- requireMod.init(deps, callback, errback, {
- enabled: true
- });
+ //Store if map config should be applied to this require
+ //call for dependencies.
+ requireMod.skipMap = options.skipMap;
- checkLoaded();
+ requireMod.init(deps, callback, errback, {
+ enabled: true
+ });
- return context.require;
- },
+ checkLoaded();
+ });
- undef: function (id) {
- //Bind any waiting define() calls to this context,
- //fix for #408
- takeGlobalQueue();
+ return require;
+ }
- var map = makeModuleMap(id, null, true),
- mod = registry[id];
+ mixin(require, {
+ isBrowser: isBrowser,
+
+ /**
+ * Converts a module name + .extension into an URL path.
+ * *Requires* the use of a module name. It does not support using
+ * plain URLs like nameToUrl.
+ */
+ toUrl: function (moduleNamePlusExt) {
+ var index = moduleNamePlusExt.lastIndexOf('.'),
+ ext = null;
+
+ if (index !== -1) {
+ ext = moduleNamePlusExt.substring(index, moduleNamePlusExt.length);
+ moduleNamePlusExt = moduleNamePlusExt.substring(0, index);
+ }
- delete defined[id];
- delete urlFetched[map.url];
- delete undefEvents[id];
+ return context.nameToUrl(normalize(moduleNamePlusExt,
+ relMap && relMap.id, true), ext);
+ },
- if (mod) {
- //Hold on to listeners in case the
- //module will be attempted to be reloaded
- //using a different config.
- if (mod.events.defined) {
- undefEvents[id] = mod.events;
+ defined: function (id) {
+ return hasProp(defined, makeModuleMap(id, relMap, false, true).id);
+ },
+
+ specified: function (id) {
+ id = makeModuleMap(id, relMap, false, true).id;
+ return hasProp(defined, id) || hasProp(registry, id);
}
+ });
+
+ //Only allow undef on top level require calls
+ if (!relMap) {
+ require.undef = function (id) {
+ //Bind any waiting define() calls to this context,
+ //fix for #408
+ takeGlobalQueue();
+
+ var map = makeModuleMap(id, relMap, true),
+ mod = registry[id];
+
+ delete defined[id];
+ delete urlFetched[map.url];
+ delete undefEvents[id];
+
+ if (mod) {
+ //Hold on to listeners in case the
+ //module will be attempted to be reloaded
+ //using a different config.
+ if (mod.events.defined) {
+ undefEvents[id] = mod.events;
+ }
- removeWaiting(id);
+ cleanRegistry(id);
+ }
+ };
}
+
+ return require;
},
/**
@@ -1535,7 +1443,7 @@ var requirejs, require, define;
completeLoad: function (moduleName) {
var found, args, mod,
shim = config.shim[moduleName] || {},
- shExports = shim.exports && shim.exports.exports;
+ shExports = shim.exports;
takeGlobalQueue();
@@ -1575,7 +1483,7 @@ var requirejs, require, define;
} else {
//A script that does not call define(), so just simulate
//the call for it.
- callGetModule([moduleName, (shim.deps || []), shim.exports]);
+ callGetModule([moduleName, (shim.deps || []), shim.exportsFn]);
}
}
@@ -1583,24 +1491,6 @@ var requirejs, require, define;
},
/**
- * Converts a module name + .extension into an URL path.
- * *Requires* the use of a module name. It does not support using
- * plain URLs like nameToUrl.
- */
- toUrl: function (moduleNamePlusExt, relModuleMap) {
- var index = moduleNamePlusExt.lastIndexOf('.'),
- ext = null;
-
- if (index !== -1) {
- ext = moduleNamePlusExt.substring(index, moduleNamePlusExt.length);
- moduleNamePlusExt = moduleNamePlusExt.substring(0, index);
- }
-
- return context.nameToUrl(normalize(moduleNamePlusExt, relModuleMap && relModuleMap.id, true),
- ext);
- },
-
- /**
* Converts a module name to a file path. Supports cases where
* moduleName may actually be just an URL.
* Note that it **does not** call normalize on the moduleName,
@@ -1713,7 +1603,10 @@ var requirejs, require, define;
return onError(makeError('scripterror', 'Script error', evt, [data.id]));
}
}
- });
+ };
+
+ context.require = context.makeRequire();
+ return context;
}
/**
@@ -1775,6 +1668,16 @@ var requirejs, require, define;
};
/**
+ * Execute something after the current tick
+ * of the event loop. Override for other envs
+ * that have a better solution than setTimeout.
+ * @param {Function} fn function to execute later.
+ */
+ req.nextTick = typeof setTimeout !== 'undefined' ? function (fn) {
+ setTimeout(fn, 4);
+ } : function (fn) { fn(); };
+
+ /**
* Export require as a global, but only if it does not already exist.
*/
if (!require) {
@@ -1794,9 +1697,21 @@ var requirejs, require, define;
//Create default context.
req({});
- //Exports some context-sensitive methods on global require, using
- //default context if no context specified.
- addRequireMethods(req);
+ //Exports some context-sensitive methods on global require.
+ each([
+ 'toUrl',
+ 'undef',
+ 'defined',
+ 'specified'
+ ], function (prop) {
+ //Reference from contexts instead of early binding to default context,
+ //so that during builds, the latest instance of the default context
+ //with its config gets used.
+ req[prop] = function () {
+ var ctx = contexts[defContextName];
+ return ctx.require[prop].apply(ctx, arguments);
+ };
+ });
if (isBrowser) {
head = s.head = document.getElementsByTagName('head')[0];
@@ -1974,7 +1889,7 @@ var requirejs, require, define;
define = function (name, deps, callback) {
var node, context;
- //Allow for anonymous functions
+ //Allow for anonymous modules
if (typeof name !== 'string') {
//Adjust args appropriately
callback = deps;
@@ -2050,4 +1965,4 @@ var requirejs, require, define;
//Set up with config info.
req(cfg);
-}(this));
+}(this));
Please sign in to comment.
Something went wrong with that request. Please try again.