Browse files

Promises (using when.js) is getting implemented. Hard dependency stil…

…l required. Only works on the test page
  • Loading branch information...
1 parent faa95d1 commit e96e86ead2723a530ed9c236c11bcb725fe00217 @xcambar committed Apr 10, 2012
Showing with 107 additions and 100 deletions.
  1. +3 −0 .gitmodules
  2. +43 −49 build/shepherd.dev.js
  3. +1 −1 build/shepherd.min.js
  4. +1 −0 lib/when
  5. +58 −50 src/shepherd.js
  6. +1 −0 test/index.html
View
3 .gitmodules
@@ -1,3 +1,6 @@
[submodule "lib/harmony-parser"]
path = lib/harmony-parser
url = https://xcambar@github.com/xcambar/harmony-parser.git
+[submodule "lib/when"]
+ path = lib/when
+ url = https://xcambar@github.com/cujojs/when.git
View
92 build/shepherd.dev.js
@@ -898,7 +898,7 @@
}
return harmony_parser;
}();
- (function(me, parser, undefined) {
+ (function(me, parser, when, undefined) {
if (typeof parser.parse !== "function") {
throw "No parser provided.";
}
@@ -1032,22 +1032,21 @@
return "Invalid declaration \n" + e.message + "\nDeclaration: " + declaration;
}
}
- function xhr(o) {
- var http = "XMLHttpRequest" in me ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP");
- http.open("GET", o.url, true);
+ function xhr(url) {
+ var deferred = when.defer(), http = "XMLHttpRequest" in me ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP");
+ http.open("GET", url, true);
http.setRequestHeader("Accept", "application/javascript, text/javascript");
http.onreadystatechange = function onReadyStateChange() {
if (this.readyState == 4) {
if (/^20\d$/.test(this.status)) {
- o.success && o.success(http);
- o.complete && o.complete(http);
+ deferred.resolve(http);
} else {
- o.error && o.error(http);
- o.complete && o.complete(http);
+ deferred.reject(this.status);
}
}
};
http.send();
+ return deferred.promise;
}
function _handleExports(module, moduleConf, callback) {
moduleConf._internals.src && (modules[moduleConf._internals.src] = module);
@@ -1157,24 +1156,8 @@
}
function applyConfiguration(conf, callback, errorFn) {
var moduleConf = {};
+ var confPromises = [];
moduleConf._internals = conf._internals;
- var depsPool = function() {
- var _c = 0;
- if (conf.type === "module" && conf.decl.expressions) {
- for (var i = 0, _l = conf.decl.expressions.length; i < _l; i++) {
- _c++;
- }
- } else if (conf.type === "export") {
- _c++;
- } else if (conf.type === "import") {
- _c++;
- }
- return function depsPool() {
- if (!--_c) {
- callback(moduleConf);
- }
- };
- }();
function importLoader(declaration) {
moduleConf.imports = moduleConf.imports || {};
var _dep = modules[declaration.from.path];
@@ -1183,15 +1166,13 @@
var _importName = declaration.vars[i];
moduleConf.imports[_importName] = _dep[_importName];
}
- depsPool();
} else {
- _module(declaration.from.path, function(module) {
+ confPromises.push(_module(declaration.from.path, function(module) {
for (var i = 0, _l = declaration.vars.length; i < _l; i++) {
var _importName = declaration.vars[i];
moduleConf.imports[_importName] = module[_importName];
}
- depsPool();
- }, errorFn);
+ }, errorFn));
}
}
function exportLoader(declaration) {
@@ -1202,7 +1183,6 @@
dest: declaration[i]
});
}
- depsPool();
}
function moduleLoader(declaration) {
moduleConf.name = conf.decl.id;
@@ -1222,12 +1202,10 @@
var ref = declaration.path || declaration.src;
if (modules[ref]) {
moduleConf.imports[declaration.id] = modules[declaration.src];
- depsPool();
} else if (declaration.path) {
- _module(declaration.path, function(module) {
+ confPromises.push(_module(declaration.path, function(module) {
moduleConf.imports[declaration.id] = module;
- depsPool();
- }, errorFn);
+ }, errorFn));
} else {
if (_isServer) {
var _dep;
@@ -1237,7 +1215,6 @@
throw new Error("The required module %1 doesn't exist".replace("%1", declaration.src));
}
moduleConf.imports[declaration.id] = _dep;
- depsPool();
} else {
throw new Error("The required module %1 doesn't exist".replace("%1", declaration.src));
}
@@ -1252,7 +1229,14 @@
moduleLoader(conf.decl);
} else if (conf.type === "export") {
exportLoader(conf.decl);
+ } else if (conf.type === "import") {
+ importLoader(conf.decl);
}
+ return when.all(confPromises).then(function() {
+ callback(moduleConf);
+ }, function() {
+ errorFn("error");
+ });
}
function _moduleSrc(conf, callback, errorFn) {
var moduleConf = conf || {}, callback = callback || function() {}, errorFn = errorFn || function() {}, rawText = conf.contents ? conf.contents : "", declaration = "";
@@ -1306,34 +1290,38 @@
if (modules.hasOwnProperty(moduleSrc)) {
return callback(modules[moduleSrc]);
}
- var _error = function(msg) {
+ function _error(msg) {
_errModules = _errModules || [];
_errModules.indexOf(moduleSrc) === -1 && _errModules.push(moduleSrc);
if (is(errorFn, "function")) {
errorFn();
} else {
throw new Error("(" + moduleSrc + ") " + msg);
}
- };
+ }
_error.origFn = errorFn;
+ var modulePromise = when.defer();
+ modulePromise.then(callback, _error);
var moduleConf = is(moduleSrc, "string") ? {
src: moduleSrc
} : moduleSrc;
!moduleConf.format && _isServer && (moduleConf.format = "commonJS");
var uri = is(moduleSrc, "string") ? moduleSrc : moduleSrc.name;
if (uri) {
- !_isServer && xhr({
- url: uri,
- error: function xhrError() {
- _error('Unable to fetch the module "' + moduleSrc + '"');
- },
- success: function xhrSuccess(res) {
+ if (!_isServer) {
+ when(xhr(uri)).then(function xhrSuccess(res) {
var responseText = res.responseText;
moduleConf.contents = responseText;
- _moduleSrc(moduleConf, callback, _error);
- }
- });
- if (_isServer) {
+ _moduleSrc(moduleConf, function(conf) {
+ modulePromise.resolve(conf);
+ }, function(msg) {
+ modulePromise.reject(msg);
+ });
+ }, function xhrError(code) {
+ _error('Unable to fetch the module "' + moduleSrc + '" (status code: ' + code + ")");
+ });
+ return modulePromise.promise;
+ } else {
var modPath, url = require("url"), parsedURL = url.parse(uri);
if (parsedURL.host) {
var get = require(parsedURL.protocol.indexOf("https") !== -1 ? "https" : "http").get;
@@ -1373,7 +1361,13 @@
}
}
} else {
- is(moduleSrc, "object") && _moduleSrc(moduleSrc, callback, _error);
+ if (is(moduleSrc, "object")) {
+ _moduleSrc(moduleSrc, function(conf) {
+ modulePromise.resolve(conf);
+ }, function(msg) {
+ modulePromise.reject(msg);
+ });
+ }
}
}
function initConfig(confs) {
@@ -1454,5 +1448,5 @@
exports = module.exports = me.s6d;
}
}
- })(this, harmonyParser);
+ })(this, harmonyParser, when);
})();
View
2 build/shepherd.min.js
@@ -1 +1 @@
-(function(a,b,c){function d(a,b){return Object.prototype.toString.call(a).toLowerCase()=="[object "+b.toLowerCase()+"]"}function k(a){var b=a.format;if(b==="commonJS")return{fn:function(c){return a.deps&&a.deps.hasOwnProperty(c)?a.deps[c]:require(c)},name:"require"};if(b==="amd"){var c="define";return{name:c,fn:function(c,d,e){var f,g,h;switch(arguments.length){case 1:f=a.name,h=c;break;case 2:g=c,h=d;break;default:f=c,g=d,h=e}if(g){var i={};for(var j=0,k=g.length;j<k;j++)i[g[j]]={format:"amd",ref:g[j]};g=i}var l={};g&&(l.import=g),f&&(l.name=f),h&&(l.fn=h),l.src=a.src,r(l,function(b){throw new Error("AMD not handled yet")})}}}}function l(a,c){function e(a){var b=a.split(";"),c=/^\s*([a-zA-Z_$][0-9a-zA-Z_$]*)\!([a-zA-Z_$][0-9a-zA-Z_$]*)\s*$/;for(var e=0;e<b.length;e++){if(!b[e])continue;var f=b[e],g=f.match(c);if(!g)return!1;var h=g[1];argument=g[2];if(!j[h])return'Unknown plugin "'+h+'"';var i=j[h](argument);if(d(i,"string")||!i)return i}return!0}var f=c||{},g=e(a);if(d(g,"string"))return g;if(g)return f;try{var h=b.parse(a);return typeof true=="undefined"&&console.log(h),h}catch(i){return"Invalid declaration \n"+i.message+"\nDeclaration: "+a}}function m(b){var c="XMLHttpRequest"in a?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");c.open("GET",b.url,!0),c.setRequestHeader("Accept","application/javascript, text/javascript"),c.onreadystatechange=function(){this.readyState==4&&(/^20\d$/.test(this.status)?(b.success&&b.success(c),b.complete&&b.complete(c)):(b.error&&b.error(c),b.complete&&b.complete(c)))},c.send()}function n(a,b,c){b._internals.src&&(e[b._internals.src]=a),b.hasOwnProperty("name")&&b.name&&(e[b.name]=a),d(c,"function")&&c(a||{})}function o(b,c,d){var e=b.imports||{},f,g;e.window={};for(var j in window)e.window[j]=window[j];var l=b.exports?"{"+b.exports.map(function(a){return a.dest+":("+["window."+a.src,"this."+a.src,a.src].join("||")+")"}).join(",")+"}":"{}",m=[],o=[];for(var j in e)e.hasOwnProperty(j)&&(o.push(j),m.push(e[j]));b.format&&b.format.length&&(g=k(b),o.push(g.name),m.push(g.fn));if(i){var p=document.createElement("script"),q=document.getElementsByTagName("head")[0];p.type="text/javascript";var r=h++;p.innerHTML="(function runner ("+o.join(", ")+") {\n"+c+"\n;s6d["+r+"]("+l+");\n}).apply({}, s6d["+r+"]())",b.src&&p.setAttribute("data-src",b.src),b.name&&p.setAttribute("name",b.name),a.s6d[r]=function(c){if(c){delete a.s6d[r],n(c,b,d);return}return m},q.appendChild(p)}else{var s;c.apply&&c.call?s=c:s=Function.apply({},o.concat([c+";\nreturn "+l])),f=s.apply({},m),n(f,b,d)}}function p(a,b,c){var d,e,f=require("vm"),g=a.imports||{};a.format&&a.format.length&&(e=k(a),g[e.name]=e.fn),g.returns={},g.console=console,g.exports={},g.module={exports:{}},g.require=function(a){return g[a]?g[a]:require(a)};var h=a.exports?a.exports.map(function(a){return"returns."+a.dest+" = "+a.src}).join(";\n"):"";f.runInNewContext(b+";\n"+h,g,a._internals.src+".vm"),d=g.returns;for(var i in g.exports)g.exports.hasOwnProperty(i)&&(d[i]=g.exports[i]);for(var i in g.module.exports)g.module.exports.hasOwnProperty(i)&&(d[i]=g.module.exports[i]);n(d,a,c)}function q(a,b,c){!a&&(a={}),g?p(a,b,c):o(a,b,c)}function r(a,b,c){function h(a){d.imports=d.imports||{};var b=e[a.from.path];if(b){for(var g=0,h=a.vars.length;g<h;g++){var i=a.vars[g];d.imports[i]=b[i]}f()}else u(a.from.path,function(b){for(var c=0,e=a.vars.length;c<e;c++){var g=a.vars[c];d.imports[g]=b[g]}f()},c)}function i(a){for(var b=0,c=a.length;b<c;b++)d.exports=d.exports||[],d.exports.push({src:a[b],dest:a[b]});f()}function j(b){d.name=a.decl.id;if(b.expressions)for(var k=0,l=b.expressions.length;k<l;k++){var m=b.expressions[k];m.type==="export"?i(m.decl):m.type==="import"?h(m.decl):m.type==="module"&&j(m.decl)}else{d.imports=d.imports||{};var n=b.path||b.src;if(e[n])d.imports[b.id]=e[b.src],f();else if(b.path)u(b.path,function(a){d.imports[b.id]=a,f()},c);else{if(!g)throw new Error("The required module %1 doesn't exist".replace("%1",b.src));var o;try{o=require(b.src)}catch(p){throw new Error("The required module %1 doesn't exist".replace("%1",b.src))}d.imports[b.id]=o,f()}}}var d={};d._internals=a._internals;var f=function(){var c=0;if(a.type==="module"&&a.decl.expressions)for(var e=0,f=a.decl.expressions.length;e<f;e++)c++;else a.type==="export"?c++:a.type==="import"&&c++;return function(){--c||b(d)}}();if(a.length===0)return b(a);a.type==="module"?(d.name=a.decl.id,j(a.decl)):a.type==="export"&&i(a.decl)}function s(a,b,c){var e=a||{},b=b||function(){},c=c||function(){},f=a.contents?a.contents:"",g="",h=f.match(/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg);if(!h)return q({_internals:{src:a.src}},f,b);var i=h[0].split("\n");for(var j=0,k=i.length;j<k;j++)g+=i[j].trim().replace(/(^\/\*+)|(\*+\/?)/,"");if(g.length){e=l(g,e);if(d(e,"string"))c(e);else{var m=e[0];m._internals={src:a.src},r(m,function(a){q(a,f,b)},c.origFn)}}else q({_internals:{src:a.src}},f,b)}function t(a){var b;try{b=require.resolve(a)}catch(c){}try{b=b?b:require("fs").statSync(__dirname+"/"+a).isFile()&&__dirname+"/"+a}catch(c){}try{b=b?b:require("fs").statSync(process.cwd()+"/"+a).isFile()&&process.cwd()+"/"+a}catch(c){}return b}function u(a,b,c){if(e.hasOwnProperty(a))return b(e[a]);var h=function(b){f=f||[],f.indexOf(a)===-1&&f.push(a);if(!d(c,"function"))throw new Error("("+a+") "+b);c()};h.origFn=c;var i=d(a,"string")?{src:a}:a;!i.format&&g&&(i.format="commonJS");var j=d(a,"string")?a:a.name;if(j){!g&&m({url:j,error:function(){h('Unable to fetch the module "'+a+'"')},success:function(c){var d=c.responseText;i.contents=d,s(i,b,h)}});if(g){var k,l=require("url"),n=l.parse(j);if(n.host){var o=require(n.protocol.indexOf("https")!==-1?"https":"http").get,p={host:n.host,path:n.pathname};n.port&&(p.port=n.port),o(p,function(a){var c="";a.on("data",function(a){c+=a}),a.on("end",function(){i.contents=c,s(i,b,h)}),a.on("error",h)})}else{k=t(j);if(!k){h("Unable to locate file "+j);return}if(d(k,"object"))i.deps=i.deps||{},i.deps[k.uri]=k.node_module;else try{i.contents=require("fs").readFileSync(k,"utf-8")}catch(q){h(q.message);return}s(i,b,h)}}}else d(a,"object")&&s(a,b,h)}function v(a){for(var b=0;b<a.length;b++){var c=a[b],e;if(d(JSON,"object"))e=JSON.parse(c);else{var f=new Function("return "+c);e=f()}for(var g in e){if(!e.hasOwnProperty(g))continue;g in j?j[g](e[g]):g=="debug"&&(i=e[g])}}}function w(a){for(var b=0;b<a.length;b++){var c=a[b],d=c.getAttribute("data-src");d&&!a.hasOwnProperty(d)&&u(d),!d&&c.innerHTML&&s({contents:c.innerHTML})}}if(typeof b.parse!="function")throw"No parser provided.";var e={},f=null,g=typeof window=="undefined",h=0,i,j={modularize:function(c){function f(b){return a.hasOwnProperty(b)?(e[b]=a[b],!0):'No global "'+b+'"'}if(d(c,"array"))for(var g=0;g<c.length;g++)f(c[g]);else f(c)},noGlobal:function(c){var e=function(b){return a.hasOwnProperty(b)?(delete a[b],!0):'No global "'+b+'"'};if(d(c,"array"))for(var f=0;f<c.length;f++)e(c[f]);else e(c)}};!g&&a.addEventListener&&a.addEventListener("load",function(){var b=[],c=[];for(var d=0;d<document.scripts.length;d++){var e=document.scripts[d],f=e.getAttribute("type");f=="text/shepherd-js"?c.push(e):f=="text/shepherd-js/config"&&b.push(e.innerHTML.trim())}v(b),w(c)});if(typeof true=="undefined"){var x;a.s6d=function(a,b){d(a,"object")?v([a]):u(a,b,x)},a.s6d.src=function(a,b){s({contents:a},b,x)},a.s6d.get=function(a){return e[a]},a.s6d.error=function(a){if(arguments.length===0)return f;x=a},a.s6d.reset=function(){x=c,e={},f=null},g&&(exports=module.exports=a.s6d)}})(this,(function(){var a,b=function(){var a={trace:function(){},yy:{},symbols_:{error:2,Program:3,ProgramNext:4,ProgramElement:5,ModuleDeclaration:6,ImportDeclaration:7,ExportDeclaration:8,EOF:9,ModuleSpecifier:10,Path:11,String:12,module:13,Id:14,at:15,SEMICOLON:16,IS:17,ImportSource:18,OPEN_BRACE:19,ModuleBody:20,CLOSE_BRACE:21,from:22,"import":23,ImportSpecifierSet:24,WILDCARD:25,ImportSpecifier:26,ImportSpecifierNext:27,COMMA:28,COLON:29,"export":30,ExportSpecifierSet:31,ExportSpecifierSetNext:32,ExportSpecifier:33,ExportSpecifierNext:34,ModuleElement:35,PERIOD:36,$accept:0,$end:1},terminals_:{2:"error",9:"EOF",12:"String",13:"module",14:"Id",15:"at",16:"SEMICOLON",17:"IS",19:"OPEN_BRACE",21:"CLOSE_BRACE",22:"from",23:"import",25:"WILDCARD",28:"COMMA",29:"COLON",30:"export",36:"PERIOD"},productions_:[0,[3,1],[4,1],[4,2],[5,1],[5,1],[5,1],[5,1],[10,1],[10,1],[6,5],[6,5],[6,5],[18,1],[18,3],[7,5],[24,1],[24,1],[24,4],[27,3],[27,0],[26,1],[26,3],[8,4],[32,3],[32,0],[31,4],[31,1],[31,1],[31,3],[33,1],[33,3],[34,3],[34,0],[20,2],[20,2],[20,2],[20,0],[35,1],[35,1],[11,1],[11,3]],performAction:function(b,c,d,e,f,g,h){var i=g.length-1;switch(f){case 1:return g[i];case 2:this.$=g[i];break;case 3:this.$=g[i].length?g[i-1].concat(g[i]):g[i-1];break;case 4:this.$=[{type:"module",decl:g[i]}];break;case 5:this.$=[{type:"import",decl:g[i]}];break;case 6:this.$=[{type:"export",decl:g[i]}];break;case 7:this.$=[];break;case 8:this.$={type:"module",path:g[i]};break;case 9:this.$={type:"uri",path:g[i].trim().replace(/^(['"])(.*)\1$/,function(a,b,c,d){return c})};break;case 10:this.$={id:g[i-3],path:g[i-1].trim().replace(/^(['"])(.*)\1$/,function(a,b,c,d){return c})};break;case 11:this.$={id:g[i-3],src:g[i-1]};break;case 12:this.$={id:g[i-3],expressions:g[i-1]};break;case 13:this.$=g[i];break;case 14:var j={id:g[i-2]};j[g[i].type]=g[i].path,this.$=j;break;case 15:this.$={from:g[i-1],vars:g[i-3]};break;case 16:this.$=[g[i]];break;case 17:this.$=[g[i]];break;case 18:this.$=[g[i-2]].concat(g[i-1]);break;case 19:this.$=typeof g[i]!="undefined"?[g[i-1]].concat(g[i]):g[i-1];break;case 21:this.$=g[i];break;case 22:this.$={remote:g[i-2],local:g[i]};break;case 23:this.$=typeof g[i-1]!="undefined"?g[i-2].concat(g[i-1]):g[i-2];break;case 24:this.$=typeof g[i]!="undefined"?g[i-1].concat(g[i]):g[i-1];break;case 26:this.$=typeof g[i-1]!="undefined"?[g[i-2]].concat(g[i-1]):[g[i-2]];break;case 27:this.$=[g[i]];break;case 28:this.$=[g[i]];break;case 29:this.$=[{from:g[i]}];break;case 30:this.$=g[i];break;case 31:this.$={local:g[i-2],remote:g[i]};break;case 32:this.$=typeof g[i]!="undefined"?[g[i-1]].concat(g[i]):[g[i-1]];break;case 34:this.$=[{type:"module",decl:g[i-1]}].concat(g[i]);break;case 35:this.$=[{type:"import",decl:g[i-1]}].concat(g[i]);break;case 36:this.$=[{type:"export",decl:g[i-1]}].concat(g[i]);break;case 37:this.$=[];break;case 38:this.$=g[i];break;case 39:this.$=g[i];break;case 40:this.$=g[i];break;case 41:this.$=g[i-2]+"."+g[i]}},table:[{3:1,4:2,5:3,6:4,7:5,8:6,9:[1,7],13:[1,8],23:[1,9],30:[1,10]},{1:[3]},{1:[2,1]},{1:[2,2],4:11,5:3,6:4,7:5,8:6,9:[1,7],13:[1,8],23:[1,9],30:[1,10]},{1:[2,4],9:[2,4],13:[2,4],23:[2,4],30:[2,4]},{1:[2,5],9:[2,5],13:[2,5],23:[2,5],30:[2,5]},{1:[2,6],9:[2,6],13:[2,6],23:[2,6],30:[2,6]},{1:[2,7],9:[2,7],13:[2,7],23:[2,7],30:[2,7]},{14:[1,12]},{14:[1,14],19:[1,16],24:13,25:[1,15]},{14:[1,19],19:[1,18],25:[1,20],31:17},{1:[2,3]},{15:[1,21],17:[1,22],19:[1,23]},{22:[1,24]},{22:[2,16]},{22:[2,17]},{14:[1,26],26:25},{16:[2,25],28:[1,28],32:27},{14:[1,30],33:29},{16:[2,27],28:[2,27]},{16:[2,28],22:[1,31],28:[2,28]},{12:[1,32]},{14:[1,34],18:33},{6:36,7:37,8:38,13:[1,8],20:35,21:[2,37],23:[1,9],30:[1,10]},{10:39,11:40,12:[1,41],14:[1,42]},{21:[2,20],27:43,28:[1,44]},{21:[2,21],28:[2,21],29:[1,45]},{16:[1,46]},{14:[1,19],19:[1,18],25:[1,20],31:47},{21:[2,33],28:[1,49],34:48},{21:[2,30],28:[2,30],29:[1,50]},{11:51,14:[1,42]},{16:[1,52]},{16:[1,53]},{16:[2,13],22:[1,54]},{21:[1,55]},{6:36,7:37,8:38,13:[1,8],20:56,21:[2,37],23:[1,9],30:[1,10]},{6:36,7:37,8:38,13:[1,8],20:57,21:[2,37],23:[1,9],30:[1,10]},{6:36,7:37,8:38,13:[1,8],20:58,21:[2,37],23:[1,9],30:[1,10]},{16:[1,59]},{16:[2,8]},{16:[2,9]},{16:[2,40],21:[2,40],28:[2,40],36:[1,60]},{21:[1,61]},{14:[1,26],26:62},{11:63,14:[1,42]},{1:[2,23],9:[2,23],13:[2,23],21:[2,23],23:[2,23],30:[2,23]},{16:[2,25],28:[1,28],32:64},{21:[1,65]},{14:[1,30],33:66},{11:67,14:[1,42]},{16:[2,29],28:[2,29]},{1:[2,10],9:[2,10],13:[2,10],21:[2,10],23:[2,10],30:[2,10]},{1:[2,11],9:[2,11],13:[2,11],21:[2,11],23:[2,11],30:[2,11]},{10:68,11:40,12:[1,41],14:[1,42]},{1:[2,12],9:[2,12],13:[2,12],21:[2,12],23:[2,12],30:[2,12]},{21:[2,34]},{21:[2,35]},{21:[2,36]},{1:[2,15],9:[2,15],13:[2,15],21:[2,15],23:[2,15],30:[2,15]},{11:69,14:[1,42]},{22:[2,18]},{21:[2,20],27:70,28:[1,44]},{21:[2,22],28:[2,22]},{16:[2,24]},{16:[2,26],28:[2,26]},{21:[2,33],28:[1,49],34:71},{21:[2,31],28:[2,31]},{16:[2,14]},{16:[2,41],21:[2,41],28:[2,41]},{21:[2,19]},{21:[2,32]}],defaultActions:{2:[2,1],11:[2,3],14:[2,16],15:[2,17],40:[2,8],41:[2,9],56:[2,34],57:[2,35],58:[2,36],61:[2,18],64:[2,24],68:[2,14],70:[2,19],71:[2,32]},parseError:function(b,c){throw new Error(b)},parse:function(b){function o(a){d.length=d.length-2*a,e.length=e.length-a,f.length=f.length-a}function p(){var a;return a=c.lexer.lex()||1,typeof a!="number"&&(a=c.symbols_[a]||a),a}var c=this,d=[0],e=[null],f=[],g=this.table,h="",i=0,j=0,k=0,l=2,m=1;this.lexer.setInput(b),this.lexer.yy=this.yy,this.yy.lexer=this.lexer,typeof this.lexer.yylloc=="undefined"&&(this.lexer.yylloc={});var n=this.lexer.yylloc;f.push(n),typeof this.yy.parseError=="function"&&(this.parseError=this.yy.parseError);var q,r,s,t,u,v,w={},x,y,z,A;for(;;){s=d[d.length-1],this.defaultActions[s]?t=this.defaultActions[s]:(q==null&&(q=p()),t=g[s]&&g[s][q]);if(typeof t=="undefined"||!t.length||!t[0]){if(!k){A=[];for(x in g[s])this.terminals_[x]&&x>2&&A.push("'"+this.terminals_[x]+"'");var B="";this.lexer.showPosition?B="Parse error on line "+(i+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+A.join(", ")+", got '"+this.terminals_[q]+"'":B="Parse error on line "+(i+1)+": Unexpected "+(q==1?"end of input":"'"+(this.terminals_[q]||q)+"'"),this.parseError(B,{text:this.lexer.match,token:this.terminals_[q]||q,line:this.lexer.yylineno,loc:n,expected:A})}if(k==3){if(q==m)throw new Error(B||"Parsing halted.");j=this.lexer.yyleng,h=this.lexer.yytext,i=this.lexer.yylineno,n=this.lexer.yylloc,q=p()}for(;;){if(l.toString()in g[s])break;if(s==0)throw new Error(B||"Parsing halted.");o(1),s=d[d.length-1]}r=q,q=l,s=d[d.length-1],t=g[s]&&g[s][l],k=3}if(t[0]instanceof Array&&t.length>1)throw new Error("Parse Error: multiple actions possible at state: "+s+", token: "+q);switch(t[0]){case 1:d.push(q),e.push(this.lexer.yytext),f.push(this.lexer.yylloc),d.push(t[1]),q=null,r?(q=r,r=null):(j=this.lexer.yyleng,h=this.lexer.yytext,i=this.lexer.yylineno,n=this.lexer.yylloc,k>0&&k--);break;case 2:y=this.productions_[t[1]][1],w.$=e[e.length-y],w._$={first_line:f[f.length-(y||1)].first_line,last_line:f[f.length-1].last_line,first_column:f[f.length-(y||1)].first_column,last_column:f[f.length-1].last_column},v=this.performAction.call(w,h,j,i,this.yy,t[1],e,f);if(typeof v!="undefined")return v;y&&(d=d.slice(0,-1*y*2),e=e.slice(0,-1*y),f=f.slice(0,-1*y)),d.push(this.productions_[t[1]][0]),e.push(w.$),f.push(w._$),z=g[d[d.length-2]][d[d.length-1]],d.push(z);break;case 3:return!0}}return!0}},b=function(){var a={EOF:1,parseError:function(b,c){if(!this.yy.parseError)throw new Error(b);this.yy.parseError(b,c)},setInput:function(a){return this._input=a,this._more=this._less=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this},input:function(){var a=this._input[0];this.yytext+=a,this.yyleng++,this.match+=a,this.matched+=a;var b=a.match(/\n/);return b&&this.yylineno++,this._input=this._input.slice(1),a},unput:function(a){return this._input=a+this._input,this},more:function(){return this._more=!0,this},pastInput:function(){var a=this.matched.substr(0,this.matched.length-this.match.length);return(a.length>20?"...":"")+a.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var a=this.match;return a.length<20&&(a+=this._input.substr(0,20-a.length)),(a.substr(0,20)+(a.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var a=this.pastInput(),b=(new Array(a.length+1)).join("-");return a+this.upcomingInput()+"\n"+b+"^"},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var a,b,c,d,e,f;this._more||(this.yytext="",this.match="");var g=this._currentRules();for(var h=0;h<g.length;h++){c=this._input.match(this.rules[g[h]]);if(c&&(!b||c[0].length>b[0].length)){b=c,d=h;if(!this.options.flex)break}}if(b){f=b[0].match(/\n.*/g),f&&(this.yylineno+=f.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:f?f[f.length-1].length-1:this.yylloc.last_column+b[0].length},this.yytext+=b[0],this.match+=b[0],this.yyleng=this.yytext.length,this._more=!1,this._input=this._input.slice(b[0].length),this.matched+=b[0],a=this.performAction.call(this,this.yy,this,g[d],this.conditionStack[this.conditionStack.length-1]);if(a)return a;return}if(this._input==="")return this.EOF;this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var b=this.next();return typeof b!="undefined"?b:this.lex()},begin:function(b){this.conditionStack.push(b)},popState:function(){return this.conditionStack.pop()},_currentRules:function(){return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules},topState:function(){return this.conditionStack[this.conditionStack.length-2]},pushState:function(b){this.begin(b)}};return a.options={},a.performAction=function(b,c,d,e){var f=e;switch(d){case 0:break;case 1:break;case 2:break;case 3:return"SEMICOLON";case 4:return"COLON";case 5:return"OPEN_BRACE";case 6:return"CLOSE_BRACE";case 7:return"module";case 8:return"import";case 9:return"export";case 10:return 15;case 11:return 17;case 12:return 22;case 13:return"WILDCARD";case 14:return 28;case 15:return 36;case 16:return"Id";case 17:return"String";case 18:return"String";case 19:return 9}},a.rules=[/^\n+/,/^\s+/,/^\t+/,/^;/,/^:/,/^\{/,/^\}/,/^module\b/,/^import\b/,/^export\b/,/^at\b/,/^is\b/,/^from\b/,/^\*/,/^,/,/^\./,/^[a-zA-Z_$][0-9a-zA-Z_$]*/,/^'[^\']+'/,/^"[^\"]+"/,/^$/],a.conditions={INITIAL:{rules:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19],inclusive:!0}},a}();return a.lexer=b,a}();return typeof undefined!="undefined"&&typeof a!="undefined"&&(a.parser=b,a.parse=function(){return b.parse.apply(b,arguments)},a.main=function(c){if(!c[1])throw new Error("Usage: "+c[0]+" FILE");if(typeof process!="undefined")var d=undefined("fs").readFileSync(undefined("path").join(process.cwd(),c[1]),"utf8");else var e=undefined("file").path(undefined("file").cwd()),d=e.join(c[1]).read({charset:"utf-8"});return a.parser.parse(d)},typeof module!="undefined"&&undefined.main===module&&a.main(typeof process!="undefined"?process.argv.slice(1):undefined("system").args)),b})())
+(function(a,b,c,d){function e(a,b){return Object.prototype.toString.call(a).toLowerCase()=="[object "+b.toLowerCase()+"]"}function l(a){var b=a.format;if(b==="commonJS")return{fn:function(c){return a.deps&&a.deps.hasOwnProperty(c)?a.deps[c]:require(c)},name:"require"};if(b==="amd"){var c="define";return{name:c,fn:function(c,d,e){var f,g,h;switch(arguments.length){case 1:f=a.name,h=c;break;case 2:g=c,h=d;break;default:f=c,g=d,h=e}if(g){var i={};for(var j=0,k=g.length;j<k;j++)i[g[j]]={format:"amd",ref:g[j]};g=i}var l={};g&&(l.import=g),f&&(l.name=f),h&&(l.fn=h),l.src=a.src,s(l,function(b){throw new Error("AMD not handled yet")})}}}}function m(a,c){function d(a){var b=a.split(";"),c=/^\s*([a-zA-Z_$][0-9a-zA-Z_$]*)\!([a-zA-Z_$][0-9a-zA-Z_$]*)\s*$/;for(var d=0;d<b.length;d++){if(!b[d])continue;var f=b[d],g=f.match(c);if(!g)return!1;var h=g[1];argument=g[2];if(!k[h])return'Unknown plugin "'+h+'"';var i=k[h](argument);if(e(i,"string")||!i)return i}return!0}var f=c||{},g=d(a);if(e(g,"string"))return g;if(g)return f;try{var h=b.parse(a);return typeof true=="undefined"&&console.log(h),h}catch(i){return"Invalid declaration \n"+i.message+"\nDeclaration: "+a}}function n(b){var d=c.defer(),e="XMLHttpRequest"in a?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");return e.open("GET",b,!0),e.setRequestHeader("Accept","application/javascript, text/javascript"),e.onreadystatechange=function(){this.readyState==4&&(/^20\d$/.test(this.status)?d.resolve(e):d.reject(this.status))},e.send(),d.promise}function o(a,b,c){b._internals.src&&(f[b._internals.src]=a),b.hasOwnProperty("name")&&b.name&&(f[b.name]=a),e(c,"function")&&c(a||{})}function p(b,c,d){var e=b.imports||{},f,g;e.window={};for(var h in window)e.window[h]=window[h];var k=b.exports?"{"+b.exports.map(function(a){return a.dest+":("+["window."+a.src,"this."+a.src,a.src].join("||")+")"}).join(",")+"}":"{}",m=[],n=[];for(var h in e)e.hasOwnProperty(h)&&(n.push(h),m.push(e[h]));b.format&&b.format.length&&(g=l(b),n.push(g.name),m.push(g.fn));if(j){var p=document.createElement("script"),q=document.getElementsByTagName("head")[0];p.type="text/javascript";var r=i++;p.innerHTML="(function runner ("+n.join(", ")+") {\n"+c+"\n;s6d["+r+"]("+k+");\n}).apply({}, s6d["+r+"]())",b.src&&p.setAttribute("data-src",b.src),b.name&&p.setAttribute("name",b.name),a.s6d[r]=function(c){if(c){delete a.s6d[r],o(c,b,d);return}return m},q.appendChild(p)}else{var s;c.apply&&c.call?s=c:s=Function.apply({},n.concat([c+";\nreturn "+k])),f=s.apply({},m),o(f,b,d)}}function q(a,b,c){var d,e,f=require("vm"),g=a.imports||{};a.format&&a.format.length&&(e=l(a),g[e.name]=e.fn),g.returns={},g.console=console,g.exports={},g.module={exports:{}},g.require=function(a){return g[a]?g[a]:require(a)};var h=a.exports?a.exports.map(function(a){return"returns."+a.dest+" = "+a.src}).join(";\n"):"";f.runInNewContext(b+";\n"+h,g,a._internals.src+".vm"),d=g.returns;for(var i in g.exports)g.exports.hasOwnProperty(i)&&(d[i]=g.exports[i]);for(var i in g.module.exports)g.module.exports.hasOwnProperty(i)&&(d[i]=g.module.exports[i]);o(d,a,c)}function r(a,b,c){!a&&(a={}),h?q(a,b,c):p(a,b,c)}function s(a,b,d){function i(a){e.imports=e.imports||{};var b=f[a.from.path];if(b)for(var c=0,h=a.vars.length;c<h;c++){var i=a.vars[c];e.imports[i]=b[i]}else g.push(v(a.from.path,function(b){for(var c=0,d=a.vars.length;c<d;c++){var f=a.vars[c];e.imports[f]=b[f]}},d))}function j(a){for(var b=0,c=a.length;b<c;b++)e.exports=e.exports||[],e.exports.push({src:a[b],dest:a[b]})}function k(b){e.name=a.decl.id;if(b.expressions)for(var c=0,l=b.expressions.length;c<l;c++){var m=b.expressions[c];m.type==="export"?j(m.decl):m.type==="import"?i(m.decl):m.type==="module"&&k(m.decl)}else{e.imports=e.imports||{};var n=b.path||b.src;if(f[n])e.imports[b.id]=f[b.src];else if(b.path)g.push(v(b.path,function(a){e.imports[b.id]=a},d));else{if(!h)throw new Error("The required module %1 doesn't exist".replace("%1",b.src));var o;try{o=require(b.src)}catch(p){throw new Error("The required module %1 doesn't exist".replace("%1",b.src))}e.imports[b.id]=o}}}var e={},g=[];return e._internals=a._internals,a.length===0?b(a):(a.type==="module"?(e.name=a.decl.id,k(a.decl)):a.type==="export"?j(a.decl):a.type==="import"&&i(a.decl),c.all(g).then(function(){b(e)},function(){d("error")}))}function t(a,b,c){var d=a||{},b=b||function(){},c=c||function(){},f=a.contents?a.contents:"",g="",h=f.match(/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg);if(!h)return r({_internals:{src:a.src}},f,b);var i=h[0].split("\n");for(var j=0,k=i.length;j<k;j++)g+=i[j].trim().replace(/(^\/\*+)|(\*+\/?)/,"");if(g.length){d=m(g,d);if(e(d,"string"))c(d);else{var l=d[0];l._internals={src:a.src},s(l,function(a){r(a,f,b)},c.origFn)}}else r({_internals:{src:a.src}},f,b)}function u(a){var b;try{b=require.resolve(a)}catch(c){}try{b=b?b:require("fs").statSync(__dirname+"/"+a).isFile()&&__dirname+"/"+a}catch(c){}try{b=b?b:require("fs").statSync(process.cwd()+"/"+a).isFile()&&process.cwd()+"/"+a}catch(c){}return b}function v(a,b,d){function i(b){g=g||[],g.indexOf(a)===-1&&g.push(a);if(!e(d,"function"))throw new Error("("+a+") "+b);d()}if(f.hasOwnProperty(a))return b(f[a]);i.origFn=d;var j=c.defer();j.then(b,i);var k=e(a,"string")?{src:a}:a;!k.format&&h&&(k.format="commonJS");var l=e(a,"string")?a:a.name;if(l){if(!h)return c(n(l)).then(function(b){var c=b.responseText;k.contents=c,t(k,function(a){j.resolve(a)},function(a){j.reject(a)})},function(c){i('Unable to fetch the module "'+a+'" (status code: '+c+")")}),j.promise;var m,o=require("url"),p=o.parse(l);if(p.host){var q=require(p.protocol.indexOf("https")!==-1?"https":"http").get,r={host:p.host,path:p.pathname};p.port&&(r.port=p.port),q(r,function(a){var c="";a.on("data",function(a){c+=a}),a.on("end",function(){k.contents=c,t(k,b,i)}),a.on("error",i)})}else{m=u(l);if(!m){i("Unable to locate file "+l);return}if(e(m,"object"))k.deps=k.deps||{},k.deps[m.uri]=m.node_module;else try{k.contents=require("fs").readFileSync(m,"utf-8")}catch(s){i(s.message);return}t(k,b,i)}}else e(a,"object")&&t(a,function(a){j.resolve(a)},function(a){j.reject(a)})}function w(a){for(var b=0;b<a.length;b++){var c=a[b],d;if(e(JSON,"object"))d=JSON.parse(c);else{var f=new Function("return "+c);d=f()}for(var g in d){if(!d.hasOwnProperty(g))continue;g in k?k[g](d[g]):g=="debug"&&(j=d[g])}}}function x(a){for(var b=0;b<a.length;b++){var c=a[b],d=c.getAttribute("data-src");d&&!a.hasOwnProperty(d)&&v(d),!d&&c.innerHTML&&t({contents:c.innerHTML})}}if(typeof b.parse!="function")throw"No parser provided.";var f={},g=null,h=typeof window=="undefined",i=0,j,k={modularize:function(c){function d(b){return a.hasOwnProperty(b)?(f[b]=a[b],!0):'No global "'+b+'"'}if(e(c,"array"))for(var g=0;g<c.length;g++)d(c[g]);else d(c)},noGlobal:function(c){var d=function(b){return a.hasOwnProperty(b)?(delete a[b],!0):'No global "'+b+'"'};if(e(c,"array"))for(var f=0;f<c.length;f++)d(c[f]);else d(c)}};!h&&a.addEventListener&&a.addEventListener("load",function(){var b=[],c=[];for(var d=0;d<document.scripts.length;d++){var e=document.scripts[d],f=e.getAttribute("type");f=="text/shepherd-js"?c.push(e):f=="text/shepherd-js/config"&&b.push(e.innerHTML.trim())}w(b),x(c)});if(typeof true=="undefined"){var y;a.s6d=function(a,b){e(a,"object")?w([a]):v(a,b,y)},a.s6d.src=function(a,b){t({contents:a},b,y)},a.s6d.get=function(a){return f[a]},a.s6d.error=function(a){if(arguments.length===0)return g;y=a},a.s6d.reset=function(){y=d,f={},g=null},h&&(exports=module.exports=a.s6d)}})(this,(function(){var a,b=function(){var a={trace:function(){},yy:{},symbols_:{error:2,Program:3,ProgramNext:4,ProgramElement:5,ModuleDeclaration:6,ImportDeclaration:7,ExportDeclaration:8,EOF:9,ModuleSpecifier:10,Path:11,String:12,module:13,Id:14,at:15,SEMICOLON:16,IS:17,ImportSource:18,OPEN_BRACE:19,ModuleBody:20,CLOSE_BRACE:21,from:22,"import":23,ImportSpecifierSet:24,WILDCARD:25,ImportSpecifier:26,ImportSpecifierNext:27,COMMA:28,COLON:29,"export":30,ExportSpecifierSet:31,ExportSpecifierSetNext:32,ExportSpecifier:33,ExportSpecifierNext:34,ModuleElement:35,PERIOD:36,$accept:0,$end:1},terminals_:{2:"error",9:"EOF",12:"String",13:"module",14:"Id",15:"at",16:"SEMICOLON",17:"IS",19:"OPEN_BRACE",21:"CLOSE_BRACE",22:"from",23:"import",25:"WILDCARD",28:"COMMA",29:"COLON",30:"export",36:"PERIOD"},productions_:[0,[3,1],[4,1],[4,2],[5,1],[5,1],[5,1],[5,1],[10,1],[10,1],[6,5],[6,5],[6,5],[18,1],[18,3],[7,5],[24,1],[24,1],[24,4],[27,3],[27,0],[26,1],[26,3],[8,4],[32,3],[32,0],[31,4],[31,1],[31,1],[31,3],[33,1],[33,3],[34,3],[34,0],[20,2],[20,2],[20,2],[20,0],[35,1],[35,1],[11,1],[11,3]],performAction:function(b,c,d,e,f,g,h){var i=g.length-1;switch(f){case 1:return g[i];case 2:this.$=g[i];break;case 3:this.$=g[i].length?g[i-1].concat(g[i]):g[i-1];break;case 4:this.$=[{type:"module",decl:g[i]}];break;case 5:this.$=[{type:"import",decl:g[i]}];break;case 6:this.$=[{type:"export",decl:g[i]}];break;case 7:this.$=[];break;case 8:this.$={type:"module",path:g[i]};break;case 9:this.$={type:"uri",path:g[i].trim().replace(/^(['"])(.*)\1$/,function(a,b,c,d){return c})};break;case 10:this.$={id:g[i-3],path:g[i-1].trim().replace(/^(['"])(.*)\1$/,function(a,b,c,d){return c})};break;case 11:this.$={id:g[i-3],src:g[i-1]};break;case 12:this.$={id:g[i-3],expressions:g[i-1]};break;case 13:this.$=g[i];break;case 14:var j={id:g[i-2]};j[g[i].type]=g[i].path,this.$=j;break;case 15:this.$={from:g[i-1],vars:g[i-3]};break;case 16:this.$=[g[i]];break;case 17:this.$=[g[i]];break;case 18:this.$=[g[i-2]].concat(g[i-1]);break;case 19:this.$=typeof g[i]!="undefined"?[g[i-1]].concat(g[i]):g[i-1];break;case 21:this.$=g[i];break;case 22:this.$={remote:g[i-2],local:g[i]};break;case 23:this.$=typeof g[i-1]!="undefined"?g[i-2].concat(g[i-1]):g[i-2];break;case 24:this.$=typeof g[i]!="undefined"?g[i-1].concat(g[i]):g[i-1];break;case 26:this.$=typeof g[i-1]!="undefined"?[g[i-2]].concat(g[i-1]):[g[i-2]];break;case 27:this.$=[g[i]];break;case 28:this.$=[g[i]];break;case 29:this.$=[{from:g[i]}];break;case 30:this.$=g[i];break;case 31:this.$={local:g[i-2],remote:g[i]};break;case 32:this.$=typeof g[i]!="undefined"?[g[i-1]].concat(g[i]):[g[i-1]];break;case 34:this.$=[{type:"module",decl:g[i-1]}].concat(g[i]);break;case 35:this.$=[{type:"import",decl:g[i-1]}].concat(g[i]);break;case 36:this.$=[{type:"export",decl:g[i-1]}].concat(g[i]);break;case 37:this.$=[];break;case 38:this.$=g[i];break;case 39:this.$=g[i];break;case 40:this.$=g[i];break;case 41:this.$=g[i-2]+"."+g[i]}},table:[{3:1,4:2,5:3,6:4,7:5,8:6,9:[1,7],13:[1,8],23:[1,9],30:[1,10]},{1:[3]},{1:[2,1]},{1:[2,2],4:11,5:3,6:4,7:5,8:6,9:[1,7],13:[1,8],23:[1,9],30:[1,10]},{1:[2,4],9:[2,4],13:[2,4],23:[2,4],30:[2,4]},{1:[2,5],9:[2,5],13:[2,5],23:[2,5],30:[2,5]},{1:[2,6],9:[2,6],13:[2,6],23:[2,6],30:[2,6]},{1:[2,7],9:[2,7],13:[2,7],23:[2,7],30:[2,7]},{14:[1,12]},{14:[1,14],19:[1,16],24:13,25:[1,15]},{14:[1,19],19:[1,18],25:[1,20],31:17},{1:[2,3]},{15:[1,21],17:[1,22],19:[1,23]},{22:[1,24]},{22:[2,16]},{22:[2,17]},{14:[1,26],26:25},{16:[2,25],28:[1,28],32:27},{14:[1,30],33:29},{16:[2,27],28:[2,27]},{16:[2,28],22:[1,31],28:[2,28]},{12:[1,32]},{14:[1,34],18:33},{6:36,7:37,8:38,13:[1,8],20:35,21:[2,37],23:[1,9],30:[1,10]},{10:39,11:40,12:[1,41],14:[1,42]},{21:[2,20],27:43,28:[1,44]},{21:[2,21],28:[2,21],29:[1,45]},{16:[1,46]},{14:[1,19],19:[1,18],25:[1,20],31:47},{21:[2,33],28:[1,49],34:48},{21:[2,30],28:[2,30],29:[1,50]},{11:51,14:[1,42]},{16:[1,52]},{16:[1,53]},{16:[2,13],22:[1,54]},{21:[1,55]},{6:36,7:37,8:38,13:[1,8],20:56,21:[2,37],23:[1,9],30:[1,10]},{6:36,7:37,8:38,13:[1,8],20:57,21:[2,37],23:[1,9],30:[1,10]},{6:36,7:37,8:38,13:[1,8],20:58,21:[2,37],23:[1,9],30:[1,10]},{16:[1,59]},{16:[2,8]},{16:[2,9]},{16:[2,40],21:[2,40],28:[2,40],36:[1,60]},{21:[1,61]},{14:[1,26],26:62},{11:63,14:[1,42]},{1:[2,23],9:[2,23],13:[2,23],21:[2,23],23:[2,23],30:[2,23]},{16:[2,25],28:[1,28],32:64},{21:[1,65]},{14:[1,30],33:66},{11:67,14:[1,42]},{16:[2,29],28:[2,29]},{1:[2,10],9:[2,10],13:[2,10],21:[2,10],23:[2,10],30:[2,10]},{1:[2,11],9:[2,11],13:[2,11],21:[2,11],23:[2,11],30:[2,11]},{10:68,11:40,12:[1,41],14:[1,42]},{1:[2,12],9:[2,12],13:[2,12],21:[2,12],23:[2,12],30:[2,12]},{21:[2,34]},{21:[2,35]},{21:[2,36]},{1:[2,15],9:[2,15],13:[2,15],21:[2,15],23:[2,15],30:[2,15]},{11:69,14:[1,42]},{22:[2,18]},{21:[2,20],27:70,28:[1,44]},{21:[2,22],28:[2,22]},{16:[2,24]},{16:[2,26],28:[2,26]},{21:[2,33],28:[1,49],34:71},{21:[2,31],28:[2,31]},{16:[2,14]},{16:[2,41],21:[2,41],28:[2,41]},{21:[2,19]},{21:[2,32]}],defaultActions:{2:[2,1],11:[2,3],14:[2,16],15:[2,17],40:[2,8],41:[2,9],56:[2,34],57:[2,35],58:[2,36],61:[2,18],64:[2,24],68:[2,14],70:[2,19],71:[2,32]},parseError:function(b,c){throw new Error(b)},parse:function(b){function o(a){d.length=d.length-2*a,e.length=e.length-a,f.length=f.length-a}function p(){var a;return a=c.lexer.lex()||1,typeof a!="number"&&(a=c.symbols_[a]||a),a}var c=this,d=[0],e=[null],f=[],g=this.table,h="",i=0,j=0,k=0,l=2,m=1;this.lexer.setInput(b),this.lexer.yy=this.yy,this.yy.lexer=this.lexer,typeof this.lexer.yylloc=="undefined"&&(this.lexer.yylloc={});var n=this.lexer.yylloc;f.push(n),typeof this.yy.parseError=="function"&&(this.parseError=this.yy.parseError);var q,r,s,t,u,v,w={},x,y,z,A;for(;;){s=d[d.length-1],this.defaultActions[s]?t=this.defaultActions[s]:(q==null&&(q=p()),t=g[s]&&g[s][q]);if(typeof t=="undefined"||!t.length||!t[0]){if(!k){A=[];for(x in g[s])this.terminals_[x]&&x>2&&A.push("'"+this.terminals_[x]+"'");var B="";this.lexer.showPosition?B="Parse error on line "+(i+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+A.join(", ")+", got '"+this.terminals_[q]+"'":B="Parse error on line "+(i+1)+": Unexpected "+(q==1?"end of input":"'"+(this.terminals_[q]||q)+"'"),this.parseError(B,{text:this.lexer.match,token:this.terminals_[q]||q,line:this.lexer.yylineno,loc:n,expected:A})}if(k==3){if(q==m)throw new Error(B||"Parsing halted.");j=this.lexer.yyleng,h=this.lexer.yytext,i=this.lexer.yylineno,n=this.lexer.yylloc,q=p()}for(;;){if(l.toString()in g[s])break;if(s==0)throw new Error(B||"Parsing halted.");o(1),s=d[d.length-1]}r=q,q=l,s=d[d.length-1],t=g[s]&&g[s][l],k=3}if(t[0]instanceof Array&&t.length>1)throw new Error("Parse Error: multiple actions possible at state: "+s+", token: "+q);switch(t[0]){case 1:d.push(q),e.push(this.lexer.yytext),f.push(this.lexer.yylloc),d.push(t[1]),q=null,r?(q=r,r=null):(j=this.lexer.yyleng,h=this.lexer.yytext,i=this.lexer.yylineno,n=this.lexer.yylloc,k>0&&k--);break;case 2:y=this.productions_[t[1]][1],w.$=e[e.length-y],w._$={first_line:f[f.length-(y||1)].first_line,last_line:f[f.length-1].last_line,first_column:f[f.length-(y||1)].first_column,last_column:f[f.length-1].last_column},v=this.performAction.call(w,h,j,i,this.yy,t[1],e,f);if(typeof v!="undefined")return v;y&&(d=d.slice(0,-1*y*2),e=e.slice(0,-1*y),f=f.slice(0,-1*y)),d.push(this.productions_[t[1]][0]),e.push(w.$),f.push(w._$),z=g[d[d.length-2]][d[d.length-1]],d.push(z);break;case 3:return!0}}return!0}},b=function(){var a={EOF:1,parseError:function(b,c){if(!this.yy.parseError)throw new Error(b);this.yy.parseError(b,c)},setInput:function(a){return this._input=a,this._more=this._less=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this},input:function(){var a=this._input[0];this.yytext+=a,this.yyleng++,this.match+=a,this.matched+=a;var b=a.match(/\n/);return b&&this.yylineno++,this._input=this._input.slice(1),a},unput:function(a){return this._input=a+this._input,this},more:function(){return this._more=!0,this},pastInput:function(){var a=this.matched.substr(0,this.matched.length-this.match.length);return(a.length>20?"...":"")+a.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var a=this.match;return a.length<20&&(a+=this._input.substr(0,20-a.length)),(a.substr(0,20)+(a.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var a=this.pastInput(),b=(new Array(a.length+1)).join("-");return a+this.upcomingInput()+"\n"+b+"^"},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var a,b,c,d,e,f;this._more||(this.yytext="",this.match="");var g=this._currentRules();for(var h=0;h<g.length;h++){c=this._input.match(this.rules[g[h]]);if(c&&(!b||c[0].length>b[0].length)){b=c,d=h;if(!this.options.flex)break}}if(b){f=b[0].match(/\n.*/g),f&&(this.yylineno+=f.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:f?f[f.length-1].length-1:this.yylloc.last_column+b[0].length},this.yytext+=b[0],this.match+=b[0],this.yyleng=this.yytext.length,this._more=!1,this._input=this._input.slice(b[0].length),this.matched+=b[0],a=this.performAction.call(this,this.yy,this,g[d],this.conditionStack[this.conditionStack.length-1]);if(a)return a;return}if(this._input==="")return this.EOF;this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var b=this.next();return typeof b!="undefined"?b:this.lex()},begin:function(b){this.conditionStack.push(b)},popState:function(){return this.conditionStack.pop()},_currentRules:function(){return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules},topState:function(){return this.conditionStack[this.conditionStack.length-2]},pushState:function(b){this.begin(b)}};return a.options={},a.performAction=function(b,c,d,e){var f=e;switch(d){case 0:break;case 1:break;case 2:break;case 3:return"SEMICOLON";case 4:return"COLON";case 5:return"OPEN_BRACE";case 6:return"CLOSE_BRACE";case 7:return"module";case 8:return"import";case 9:return"export";case 10:return 15;case 11:return 17;case 12:return 22;case 13:return"WILDCARD";case 14:return 28;case 15:return 36;case 16:return"Id";case 17:return"String";case 18:return"String";case 19:return 9}},a.rules=[/^\n+/,/^\s+/,/^\t+/,/^;/,/^:/,/^\{/,/^\}/,/^module\b/,/^import\b/,/^export\b/,/^at\b/,/^is\b/,/^from\b/,/^\*/,/^,/,/^\./,/^[a-zA-Z_$][0-9a-zA-Z_$]*/,/^'[^\']+'/,/^"[^\"]+"/,/^$/],a.conditions={INITIAL:{rules:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19],inclusive:!0}},a}();return a.lexer=b,a}();return typeof undefined!="undefined"&&typeof a!="undefined"&&(a.parser=b,a.parse=function(){return b.parse.apply(b,arguments)},a.main=function(c){if(!c[1])throw new Error("Usage: "+c[0]+" FILE");if(typeof process!="undefined")var d=undefined("fs").readFileSync(undefined("path").join(process.cwd(),c[1]),"utf8");else var e=undefined("file").path(undefined("file").cwd()),d=e.join(c[1]).read({charset:"utf-8"});return a.parser.parse(d)},typeof module!="undefined"&&undefined.main===module&&a.main(typeof process!="undefined"?process.argv.slice(1):undefined("system").args)),b})(),when)
1 lib/when
@@ -0,0 +1 @@
+Subproject commit 8a7950ce73f9f78d28e157ee71607da8b08b6d24
View
108 src/shepherd.js
@@ -7,7 +7,7 @@
* @see http://wiki.ecmascript.org/doku.php?id=harmony:modules for parsing and use case reference
* @see http://addyosmani.com/writing-modular-js/
*/
-(function (me, parser, undefined) {
+(function (me, parser, when, undefined) {
if (typeof parser.parse !== 'function') {
throw 'No parser provided.';
}
@@ -179,22 +179,22 @@
/**
* XHR request
**/
- function xhr (o) {
- var http = ('XMLHttpRequest' in me) ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
- http.open('GET', o.url, true);
+ function xhr (url) {
+ var deferred = when.defer(),
+ http = ('XMLHttpRequest' in me) ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
+ http.open('GET', url, true);
http.setRequestHeader('Accept', 'application/javascript, text/javascript');
http.onreadystatechange = function onReadyStateChange () {
if (this.readyState == 4) {
if (/^20\d$/.test(this.status)) {
- o.success && o.success(http);
- o.complete && o.complete(http);
+ deferred.resolve(http);
} else {
- o.error && o.error(http);
- o.complete && o.complete(http);
+ deferred.reject(this.status);
}
}
};
http.send();
+ return deferred.promise;
}
/**
@@ -334,24 +334,9 @@
*/
function applyConfiguration (conf, callback, errorFn) {
var moduleConf = {};
+ var confPromises = [];
+
moduleConf._internals = conf._internals;
- var depsPool = (function () {
- var _c = 0;
- if (conf.type === 'module' && conf.decl.expressions) {
- for (var i = 0, _l = conf.decl.expressions.length; i < _l; i++) {
- _c++;
- }
- } else if (conf.type === 'export') {
- _c++;
- } else if (conf.type === 'import') {
- _c++;
- }
- return function depsPool() {
- if(!--_c) {
- callback(moduleConf);
- }
- };
- })();
function importLoader (declaration) {
moduleConf.imports = moduleConf.imports || {};
@@ -361,19 +346,17 @@
var _importName = declaration.vars[i];
moduleConf.imports[_importName] = _dep[_importName];
}
- depsPool();
} else {
- _module(
+ confPromises.push(_module(
declaration.from.path,
function (module) {
for (var i = 0, _l = declaration.vars.length; i < _l; i++) {
var _importName = declaration.vars[i];
moduleConf.imports[_importName] = module[_importName];
}
- depsPool();
},
errorFn
- );
+ ));
}
}
@@ -383,7 +366,6 @@
moduleConf.exports = moduleConf.exports || [];
moduleConf.exports.push({src: declaration[i], dest: declaration[i]});
}
- depsPool();
}
function moduleLoader (declaration) {
@@ -409,16 +391,14 @@
var ref = declaration.path || declaration.src;
if (modules[ref]) { //The module has already been loaded
moduleConf.imports[declaration.id] = modules[declaration.src];
- depsPool();
} else if (declaration.path) {
- _module(
+ confPromises.push(_module(
declaration.path,
function (module) {
moduleConf.imports[declaration.id] = module;
- depsPool();
},
errorFn
- );
+ ));
} else {
if (_isServer) {
var _dep;
@@ -428,7 +408,6 @@
throw new Error('The required module %1 doesn\'t exist'.replace('%1', declaration.src));
}
moduleConf.imports[declaration.id] = _dep;
- depsPool();
} else {
throw new Error('The required module %1 doesn\'t exist'.replace('%1', declaration.src));
}
@@ -445,7 +424,18 @@
moduleLoader(conf.decl);
} else if (conf.type === 'export') {
exportLoader(conf.decl);
+ } else if (conf.type === 'import') {
+ importLoader(conf.decl);
}
+
+ return when.all(confPromises).then(
+ function () {
+ callback(moduleConf);
+ },
+ function () {
+ errorFn('error');
+ }
+ );
}
function _moduleSrc (conf, callback, errorFn) {
@@ -501,36 +491,48 @@
/**
* Retrieves the file corresponding to the module and declares it
+ * @return A promise
*/
function _module (moduleSrc, callback, errorFn) {
if (modules.hasOwnProperty(moduleSrc)) {
return callback(modules[moduleSrc]);
}
- var _error = function (msg) {
+ function _error (msg) {
_errModules = _errModules || [];
_errModules.indexOf(moduleSrc) === -1 && _errModules.push(moduleSrc);
if (is(errorFn, 'function')) {
errorFn();
} else {
throw new Error( '(' + moduleSrc + ') ' + msg);
}
- };
+ }
_error.origFn = errorFn;
+
+ var modulePromise = when.defer();
+ modulePromise.then(callback, _error);
+
var moduleConf = is(moduleSrc, 'string') ? {src: moduleSrc} : moduleSrc;
!moduleConf.format && _isServer && (moduleConf.format = 'commonJS');
var uri = is(moduleSrc, 'string') ? moduleSrc : moduleSrc.name;
if (uri) {
- !_isServer && xhr({ url: uri,
- error: function xhrError () {
- _error('Unable to fetch the module "' + moduleSrc + '"');
- },
- success: function xhrSuccess (res) {
- var responseText = res.responseText;
- moduleConf.contents = responseText;
- _moduleSrc(moduleConf, callback, _error);
- }
- });
- if (_isServer) {
+ if (!_isServer) {
+ when(xhr(uri))
+ .then(
+ function xhrSuccess (res) {
+ var responseText = res.responseText;
+ moduleConf.contents = responseText;
+ _moduleSrc(moduleConf, function (conf) {
+ modulePromise.resolve(conf);
+ }, function (msg) {
+ modulePromise.reject(msg);
+ });
+ },
+ function xhrError (code) {
+ _error('Unable to fetch the module "' + moduleSrc + '" (status code: ' + code + ')');
+ }
+ );
+ return modulePromise.promise;
+ } else {
var modPath, url = require('url'), parsedURL = url.parse(uri);
if(parsedURL.host) {
var get = require(parsedURL.protocol.indexOf('https') !== -1 ? 'https' : 'http').get;
@@ -567,7 +569,13 @@
}
}
} else {
- is(moduleSrc, 'object') && _moduleSrc(moduleSrc, callback, _error);
+ if (is(moduleSrc, 'object')) {
+ _moduleSrc(moduleSrc, function (conf) {
+ modulePromise.resolve(conf);
+ }, function (msg) {
+ modulePromise.reject(msg);
+ });
+ }
}
}
@@ -653,4 +661,4 @@
exports = module.exports = me.s6d;
}
}
-})(this, harmonyParser);
+})(this, harmonyParser, when);
View
1 test/index.html
@@ -8,6 +8,7 @@
<script type="text/javascript" src="jasmine-1.1.0/jasmine.js"></script>
<script type="text/javascript" src="jasmine-1.1.0/jasmine-html.js"></script>
<!-- source files -->
+ <script type="text/javascript" src="../lib/when/when.js"></script>
<script type="text/javascript" src="../build/shepherd.dev.js"></script>
<!-- spec files -->
<script type="text/javascript" src="spec/specHelper.js"></script>

0 comments on commit e96e86e

Please sign in to comment.