Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ES6 module handling update for deferred execution

  • Loading branch information...
commit 4f915f4dc93c06db43ac4a7685749bda97e8669f 1 parent 80e94b9
@guybedford guybedford authored
View
4 dist/es6-module-loader.js
@@ -1,7 +1,7 @@
/*
- * es6-module-loader v0.4.3
+ * es6-module-loader v0.5.0
* https://github.com/ModuleLoader/es6-module-loader
* Implemented to the 2013-12-02 ES6 module specification draft
* Copyright (c) 2014 Guy Bedford, Luke Hoban, Addy Osmani; Licensed MIT
*/
-!function(a){var b="undefined"!=typeof window,c=b?function(a){setTimeout(a,1)}:process.nextTick,d=a.Promise;if(d)if(d.all&&d.resolve&&d.reject){d=a.Promise;{new d(function(a){"function"!=typeof a&&(d=null)})}}else d=null;d||(d=function(a,b,c){function d(a,b){return(typeof b)[0]==a}function e(a,h){return h=function i(j,k,l,m,n,o){function p(a){return function(b){n&&(n=0,i(d,a,b))}}if(m=i.q,j!=d)return e(function(a,b){m.push({p:this,r:a,j:b,1:j,0:k})});if(l&&d(b,l)|d(c,l))try{n=l.then}catch(q){k=0,l=q}if(d(b,n))try{n.call(l,p(1),k=p(0))}catch(q){k(q)}else for(h=f(a,l,k),o=0;o<m.length;)n=m[o++],d(b,j=n[k])?g(n.p,n.r,n.j,l,j):(k?n.r:n.j)(l)},h.q=[],a.call(a={then:function(a,b){return h(a,b)},"catch":function(a){return h(0,a)}},function(a){h(d,1,a)},function(a){h(d,0,a)}),a}function f(a,c,f){return function(h,i){return d(b,h=f?h:i)?e(function(a,b){g(this,a,b,c,h)}):a}}function g(e,f,g,h,i){a(function(){try{h=i(h),i=h&&d(c,h)|d(b,h)&&h.then,d(b,i)?h==e?g(new TypeError):i.call(h,f,g):f(h)}catch(a){g(a)}})}return e.resolve=function(a){return e(function(b){b(a)})},e.reject=function(a){return e(function(b,c){c(a)})},e.all=function(b){return new e(function(c,d){if(!b.length)return a(c);for(var e=[],f=0,g=0,h=b.length;h>g;g++)(function(a){b[a].then(function(d){e[a]=d,f++,f==b.length&&c(e)},d)})(g)})},e}(c,"f","o")),"object"==typeof exports&&(module.exports=d),a.Promise||(a.Promise=d),a.PromisePolyfill=d}("undefined"!=typeof global?global:this),function(a){function b(a){if("object"!=typeof a)throw new TypeError("Expected object");if(!(this instanceof b))return new b(a);var d=this;for(var e in a)!function(a,b){c(d,a,{configurable:!1,enumerable:!0,get:function(){return b}})}(e,a[e]);Object.preventExtensions&&Object.preventExtensions(this)}var c;try{Object.defineProperty({},"a",{})&&(c=Object.defineProperty)}catch(d){c=function(a,b,c){a[b]=c.value||c.get.call(a)}}"object"==typeof exports&&(module.exports=b),a.Module||(a.Module=b),a.ModulePolyfill=b}("undefined"!=typeof global?global:this),function(a){function b(a,b){b||console.log("Assertion Failed - "+a)}function c(a){return{status:"loading",name:a,metadata:{},linkSets:[]}}function d(a,d,f,g){return new w(function(b){b(a.normalize(d,f,g))}).then(function(d){var f;if(a._modules[d])return f=c(d),f.status="linked",f;for(var g=0,h=a._loads.length;h>g;g++)if(f=a._loads[g],f.name==d)return b("loading or loaded","loading"==f.status||"loaded"==f.status),f;return f=c(d),a._loads.push(f),e(a,f),f})}function e(a,b){f(a,b,w.resolve().then(function(){return a.locate({name:b.name,metadata:b.metadata})}))}function f(a,b,c){g(a,b,c.then(function(c){return"failed"==b.status?void 0:(b.address=c,a.fetch({name:b.name,metadata:b.metadata,address:c}))}))}function g(a,c,e){e.then(function(b){return"failed"==c.status?void 0:a.translate({name:c.name,metadata:c.metadata,address:c.address,source:b})}).then(function(b){return"failed"==c.status?void 0:(c.source=b,a.instantiate({name:c.name,metadata:c.metadata,address:c.address,source:b}))}).then(function(e){if("failed"==c.status)return void 0;var f;if(void 0===e){if(B){var g=new B.util.ErrorReporter;g.reportMessageInternal=function(a,b){throw b+"\n"+a};var h=new B.syntax.Parser(new B.syntax.SourceFile(c.address,c.source)),j=h.parseModule();f=s(j),c.body=j}else{var k=c.source.match(A);if(!k)throw new TypeError("Include Traceur for module syntax support");f=[k[1]||k[2]]}c.kind="declarative"}else{if("object"!=typeof e)throw TypeError("Invalid instantiate return value");f=e.deps||[],c.execute=e.execute,c.kind="dynamic"}c.dependencies={},c.depsList=f;for(var l=[],m=0,n=f.length;n>m;m++)(function(e){var f=d(a,e,c.name,c.address);f.then(function(a){if(b("not already a dependency",!c.dependencies[e]),c.dependencies[e]=a.name,"linked"!=a.status)for(var d=c.linkSets.concat([]),f=0,g=d.length;g>f;f++)i(d[f],a)}),l.push(f)})(f[m]);return w.all(l)}).then(function(){b("is loading","loading"==c.status),c.status="loaded";for(var a=c.linkSets.concat([]),d=0,e=a.length;e>d;d++)j(a[d],c)},function(a){b("is loading on fail","loading"==c.status),c.status="failed",c.exception=a;for(var d=0,e=c.linkSets.length;e>d;d++)k(c.linkSets[d],a);b("fail linkSets removed",0==c.linkSets.length)})}function h(a,b){var c,d,e=new w(function(a,b){c=a,d=b}),f={loader:a,loads:[],done:e,resolve:c,reject:d,loadingCount:0};return i(f,b),f}function i(a,c){b("loading or loaded on link set","loading"==c.status||"loaded"==c.status);for(var d=0,e=a.loads.length;e>d;d++)if(a.loads[d]==c)return;a.loads.push(c),c.linkSets.push(a),"loaded"!=c.status&&a.loadingCount++;var f=a.loader;for(var g in c.dependencies){var h=c.dependencies[g];if(!f._modules[h])for(var d=0,e=f._loads.length;e>d;d++)if(f._loads[d].name==h){i(a,f._loads[d]);break}}}function j(a,c){if(b("loaded or linked","loaded"==c.status||"linked"==c.status),a.loadingCount--,!(a.loadingCount>0)){var d=a.loads[0];try{p(a.loads,a.loader)}catch(e){return k(a,e)}b("loads cleared",0==a.loads.length),a.resolve(d)}}function k(a,c){for(var d=a.loads.concat([]),e=0,f=d.length;f>e;e++){var g=d[e],h=y.call(g.linkSets,a);if(b("link not present",-1!=h),g.linkSets.splice(h,1),0==g.linkSets.length){var i=y.call(a.loader._loads,g);-1!=i&&a.loader._loads.splice(i,1)}}a.reject(c)}function l(a,c){c.name&&(b("load not in module table",!a._modules[c.name]),a._modules[c.name]=c.module);var d=y.call(a._loads,c);-1!=d&&a._loads.splice(d,1);for(var e=0,f=c.linkSets.length;f>e;e++)d=y.call(c.linkSets[e].loads,c),c.linkSets[e].loads.splice(d,1);c.linkSets=[]}function m(a,b,c){return new w(n(a,b,c&&c.address?"fetch":"locate",void 0,c&&c.address,void 0)).then(function(a){return a})}function n(a,d,i,j,k,l){return function(m,n){if(a._modules[d])throw new TypeError('Module "'+d+'" already exists in the module table');for(var o=0,p=a._loads.length;p>o;o++)if(a._loads[o].name==d)throw new TypeError('Module "'+d+'" is already loading');var q=c(d);j&&(q.metadata=j);var r=h(a,q);a._loads.push(q),r.done.then(m,n),"locate"==i?e(a,q):"fetch"==i?f(a,q,w.resolve(k)):(b("translate step","translate"==i),q.address=k,g(a,q,w.resolve(l)))}}function o(a,c){return b("is linked "+c.name,"linked"==c.status),b("is a module",c.module instanceof v),c.module}function p(b,c){for(var d=!1;b.length;){d=!0;a:for(var e=0;e<b.length;e++){var f=b[e],g=[];for(var h in f.dependencies){var i=f.dependencies[h];if(!c._modules[i])continue a;var j=f.depsList.indexOf(h);g[j]=i}if(d=!1,"declarative"==f.kind){B.options.sourceMaps=!0,B.options.modules="instantiate";var k=new B.codegeneration.FromOptionsTransformer(reporter),m=k.transform(f.body),n=new B.outputgeneration.SourceMapGenerator({file:f.address}),o={sourceMapGenerator:n},p=B.outputgeneration.TreeWriter.write(m,o);a.btoa&&(p+="\n//# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(o.sourceMap)))+"\n"),console.log(p),t(p,a,f.address,f.name),f.module=new v(exports)}else{var q=f.execute.apply(null,g);if(!(q instanceof v))throw new TypeError("Execution must define a Module instance");f.module=q}f.status="linked",l(c,f)}if(d)throw new TypeError("Circular dependencies not supported by the polyfill")}}function q(a){if("object"!=typeof a)throw new TypeError("Options must be an object");a.normalize&&(this.normalize=a.normalize),a.locate&&(this.locate=a.locate),a.fetch&&(this.fetch=a.fetch),a.translate&&(this.translate=a.translate),a.instantiate&&(this.instantiate=a.instantiate),u(this,"global",{get:function(){throw new TypeError("global accessor not provided by polyfill")}}),u(this,"realm",{get:function(){throw new TypeError("Realms not implemented in polyfill")}}),this._modules={},this._loads=[]}function r(a,b,c,d){var e,f;if(b(a,c,d)!==!1)for(e in a)a.hasOwnProperty(e)&&"location"!=e&&"type"!=e&&(f=a[e],"object"==typeof f&&null!==f&&r(f,b,a,e))}function s(a){function b(a){-1==y.call(c,a)&&c.push(a)}var c=[];return r(a,function(a){"EXPORT_DECLARATION"==a.type?a.declaration.moduleSpecifier&&b(a.declaration.moduleSpecifier.token.processedValue):"IMPORT_DECLARATION"==a.type?b(a.moduleSpecifier.token.processedValue):"MODULE_DECLARATION"==a.type&&b(a.expression.token.processedValue)}),c}function t(a,b,c,d){try{Function("global",'var __moduleName = "'+(d||"").replace('"','"')+'"; with(global) { '+a+" \n }"+(c&&!a.match(/\/\/[@#] ?(sourceURL|sourceMappingURL)=([^\n]+)/)?"\n//# sourceURL="+c:"")).call(b,b)}catch(e){throw"SyntaxError"==e.name&&(e.message="Evaluating "+c+"\n "+e.message),e}}var u,v=a.Module||require("./module.js"),w=a.Promise||require("./promise.js");try{Object.defineProperty({},"a",{})&&(u=Object.defineProperty)}catch(x){u=function(a,b,c){a[b]=c.value||c.get.call(a)}}var y=Array.prototype.indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(this[b]===a)return b;return-1},z={};q.prototype={define:function(a,b,c){if(z[a])throw new TypeError("Module is already loading.");return z[a]=new w(n(this,a,c&&c.address?"fetch":"translate",c&&c.meta||{},c&&c.address,b)),z[a].then(function(){delete z[a]})},load:function(a,b){return this._modules[a]?w.resolve(this._modules[a]):z[a]?z[a]:(z[a]=m(this,a,b),z[a].then(function(){delete z[a]}))},module:function(a,b){var d=c();d.address=b&&b.address;var e=h(this,d),f=w.resolve(a),i=e.done.then(function(){o(this,d)});return g(this,d,f),i},"import":function(a,b){return this._modules[a]?w.resolve(this._modules[a]):(z[a]||(z[a]=m(this,a,b))).then(function(b){return delete z[a],o(this,b)})},eval:function(){throw new TypeError("Eval not implemented in polyfill")},get:function(a){return this._modules[a]},has:function(a){return!!this._modules[a]},set:function(a,b){if(!(b instanceof v))throw new TypeError("Set must be a module");this._modules[a]=b},"delete":function(a){return this._modules[a]?delete this._modules[a]:!1},entries:function(){throw new TypeError("Iteration not yet implemented in the polyfill")},keys:function(){throw new TypeError("Iteration not yet implemented in the polyfill")},values:function(){throw new TypeError("Iteration not yet implemented in the polyfill")},normalize:function(a){return a},locate:function(a){return a.name},fetch:function(){throw new TypeError("Fetch not implemented")},translate:function(a){return a.source},instantiate:function(){}},"object"==typeof exports&&(module.exports=q),a.Loader||(a.Loader=q),a.LoaderPolyfill=q;var A=/^\s*export\s*\*\s*from\s*(?:'([^']+)'|"([^"]+)")/,B=a.traceur}("undefined"!=typeof global?global:this),function(a){function b(a){var b=String(a).replace(/^\s+|\s+$/g,"").match(/^([^:\/?#]+:)?(\/\/(?:[^:@]*(?::[^:@]*)?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);return b?{href:b[0]||"",protocol:b[1]||"",authority:b[2]||"",host:b[3]||"",hostname:b[4]||"",port:b[5]||"",pathname:b[6]||"",search:b[7]||"",hash:b[8]||""}:null}function c(a,c){function d(a){var b=[];return a.replace(/^(\.\.?(\/|$))+/,"").replace(/\/(\.(\/|$))+/g,"/").replace(/\/\.\.$/,"/../").replace(/\/?[^\/]*/g,function(a){"/.."===a?b.pop():b.push(a)}),b.join("").replace(/^\//,"/"===a.charAt(0)?"/":"")}return c=b(c||""),a=b(a||""),c&&a?(c.protocol||a.protocol)+(c.protocol||c.authority?c.authority:a.authority)+d(c.protocol||c.authority||"/"===c.pathname.charAt(0)?c.pathname:c.pathname?(a.authority&&!a.pathname?"/":"")+a.pathname.slice(0,a.pathname.lastIndexOf("/")+1)+c.pathname:a.pathname)+(c.protocol||c.authority||c.pathname?c.search:c.search||a.search)+c.hash:null}console.log("SYSTEM");{var d,e="undefined"!=typeof window,f=(a.Module||require("./module.js"),a.Loader||require("./loader.js")),g=a.Promise||require("./promise.js");Array.prototype.indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(this[b]===a)return b;return-1}}if(e)d=function(a,b,c){function d(){b(f.responseText)}function e(){c(f.statusText+": "+a||"XHR error")}var f=new XMLHttpRequest,g=!0;if(!("withCredentials"in f)){var h=/^(\w+:)?\/\/([^\/]+)/.exec(a);h&&(g=h[2]===window.location.host,h[1]&&(g&=h[1]===window.location.protocol))}g||(f=new XDomainRequest,f.onload=d,f.onerror=e,f.ontimeout=e),f.onreadystatechange=function(){4===f.readyState&&(200===f.status||0==f.status&&f.responseText?d():e())},f.open("GET",a,!0),f.send(null)};else{var h=require("fs");d=function(a,b,c){return h.readFile(a,function(a,d){return a?c(a):(b(d+""),void 0)})}}var i=new f({global:e?window:a,strict:!0,normalize:function(a,b){if("string"!=typeof a)throw new TypeError("Module name must be a string");var c=a.split("/");if(0==c.length)throw new TypeError("No module name provided");var d=0,e=!1,f=0;if("."==c[0]){if(d++,d==c.length)throw new TypeError('Illegal module name "'+a+'"');e=!0}else{for(;".."==c[d];)if(d++,d==c.length)throw new TypeError('Illegal module name "'+a+'"');d&&(e=!0),f=d}for(var g=d;g<c.length;g++){var h=c[g];if(""==h||"."==h||".."==h)throw new TypeError('Illegal module name"'+a+'"')}if(!e)return a;{var i=[],j=(b||"").split("/");j.length-1-f}return i=i.concat(j.splice(0,j.length-1-f)),i=i.concat(c.splice(d)),i.join("/")},locate:function(a){var b,d=a.name,e="";for(var f in this.paths){var g=f.split("*");if(g.length>2)throw new TypeError("Only one wildcard in a path is permitted");1==g.length?d==f&&f.length>e.length&&(e=f):d.substr(0,g[0].length)==g[0]&&d.substr(d.length-g[1].length)==g[1]&&(e=f,b=d.substr(g[0].length,d.length-g[1].length-g[0].length))}var h=this.paths[e];return b&&(h=h.replace("*",b)),c(this.baseURL,h)},fetch:function(a){var b,e,f=new g(function(a,c){b=a,e=c});return d(c(this.baseURL,a.address),function(a){b(a)},e),f}});if(e){var j=window.location.href.split("#")[0].split("?")[0];i.baseURL=j.substring(0,j.lastIndexOf("/")+1)}else i.baseURL="./";if(i.paths={"*":"*.js"},a.System||(a.System=i),e){var k=document.getElementsByTagName("script");k=k[k.length-1],document.onreadystatechange=function(){if("interactive"==document.readyState)for(var a=document.getElementsByTagName("script"),b=0;b<a.length;b++){var c=a[b];if("module"==c.type){var d=c.getAttribute("name"),e=c.getAttribute("src"),f=c.innerHTML;(d?i.define(d,f,{address:e}):i.module(f,{address:e})).then(function(){},function(a){nextTick(function(){throw a})})}}},k.getAttribute("data-init")&&window[k.getAttribute("data-init")]()}"object"==typeof exports&&(module.exports=i),a.System||(a.System=i),a.SystemPolyfill=i}("undefined"!=typeof global?global:this);
+!function(a){var b="undefined"!=typeof window,c=b?function(a){setTimeout(a,1)}:process.nextTick,d=a.Promise;if(d)if(d.all&&d.resolve&&d.reject){d=a.Promise;{new d(function(a){"function"!=typeof a&&(d=null)})}}else d=null;d||(d=function(a,b,c){function d(a,b){return(typeof b)[0]==a}function e(a,h){return h=function i(j,k,l,m,n,o){function p(a){return function(b){n&&(n=0,i(d,a,b))}}if(m=i.q,j!=d)return e(function(a,b){m.push({p:this,r:a,j:b,1:j,0:k})});if(l&&d(b,l)|d(c,l))try{n=l.then}catch(q){k=0,l=q}if(d(b,n))try{n.call(l,p(1),k=p(0))}catch(q){k(q)}else for(h=f(a,l,k),o=0;o<m.length;)n=m[o++],d(b,j=n[k])?g(n.p,n.r,n.j,l,j):(k?n.r:n.j)(l)},h.q=[],a.call(a={then:function(a,b){return h(a,b)},"catch":function(a){return h(0,a)}},function(a){h(d,1,a)},function(a){h(d,0,a)}),a}function f(a,c,f){return function(h,i){return d(b,h=f?h:i)?e(function(a,b){g(this,a,b,c,h)}):a}}function g(e,f,g,h,i){a(function(){try{h=i(h),i=h&&d(c,h)|d(b,h)&&h.then,d(b,i)?h==e?g(new TypeError):i.call(h,f,g):f(h)}catch(a){g(a)}})}return e.resolve=function(a){return e(function(b){b(a)})},e.reject=function(a){return e(function(b,c){c(a)})},e.all=function(b){return new e(function(c,d){if(!b.length)return a(c);for(var e=[],f=0,g=0,h=b.length;h>g;g++)(function(a){b[a].then(function(d){e[a]=d,f++,f==b.length&&c(e)},d)})(g)})},e}(c,"f","o")),"object"==typeof exports&&(module.exports=d),a.Promise||(a.Promise=d),a.PromisePolyfill=d}("undefined"!=typeof global?global:this),function(a){function b(a,b){b||console.log("Assertion Failed - "+a)}function c(a){return{status:"loading",name:a,metadata:{},linkSets:[]}}function d(a,d,f,g){return new x(function(b){b(a.normalize(d,f,g))}).then(function(d){var f;if(a._modules[d])return f=c(d),f.status="linked",f;for(var g=0,h=a._loads.length;h>g;g++)if(f=a._loads[g],f.name==d)return b("loading or loaded","loading"==f.status||"loaded"==f.status),f;return f=c(d),a._loads.push(f),e(a,f),f})}function e(a,b){f(a,b,x.resolve().then(function(){return a.locate({name:b.name,metadata:b.metadata})}))}function f(a,b,c){g(a,b,c.then(function(c){return"failed"==b.status?void 0:(b.address=c,a.fetch({name:b.name,metadata:b.metadata,address:c}))}))}function g(a,c,e){e.then(function(b){return"failed"==c.status?void 0:a.translate({name:c.name,metadata:c.metadata,address:c.address,source:b})}).then(function(b){return"failed"==c.status?void 0:(c.source=b,a.instantiate({name:c.name,metadata:c.metadata,address:c.address,source:b}))}).then(function(e){if("failed"==c.status)return void 0;var f;if(void 0===e){if(C){c.address=c.address||"anon"+ ++D;var g=new C.syntax.Parser(new C.syntax.SourceFile(c.address,c.source)),h=g.parseModule();f=t(h),c.body=new C.codegeneration.module.AttachModuleNameTransformer(c.name).transformAny(h)}else{var j=c.source.match(B);if(!j)throw new TypeError("Include Traceur for module syntax support");f=[j[1]||j[2]]}c.kind="declarative"}else{if("object"!=typeof e)throw TypeError("Invalid instantiate return value");f=e.deps||[],c.execute=e.execute,c.kind="dynamic"}c.dependencies={},c.depsList=f;for(var k=[],l=0,m=f.length;m>l;l++)(function(e){var f=d(a,e,c.name,c.address);f.then(function(a){if(b("not already a dependency",!c.dependencies[e]),c.dependencies[e]=a.name,"linked"!=a.status)for(var d=c.linkSets.concat([]),f=0,g=d.length;g>f;f++)i(d[f],a)}),k.push(f)})(f[l]);return x.all(k)}).then(function(){b("is loading","loading"==c.status),c.status="loaded";for(var a=c.linkSets.concat([]),d=0,e=a.length;e>d;d++)j(a[d],c)},function(a){b("is loading on fail","loading"==c.status),c.status="failed",c.exception=a;for(var d=0,e=c.linkSets.length;e>d;d++)k(c.linkSets[d],a);b("fail linkSets removed",0==c.linkSets.length)})}function h(a,b){var c,d,e=new x(function(a,b){c=a,d=b}),f={loader:a,loads:[],done:e,resolve:c,reject:d,loadingCount:0};return i(f,b),f}function i(a,c){b("loading or loaded on link set","loading"==c.status||"loaded"==c.status);for(var d=0,e=a.loads.length;e>d;d++)if(a.loads[d]==c)return;a.loads.push(c),c.linkSets.push(a),"loaded"!=c.status&&a.loadingCount++;var f=a.loader;for(var g in c.dependencies){var h=c.dependencies[g];if(!f._modules[h])for(var d=0,e=f._loads.length;e>d;d++)if(f._loads[d].name==h){i(a,f._loads[d]);break}}}function j(a,c){if(b("loaded or linked","loaded"==c.status||"linked"==c.status),a.loadingCount--,!(a.loadingCount>0)){var d=a.loads[0];try{q(a.loads,a.loader)}catch(e){return k(a,e)}b("loads cleared",0==a.loads.length),a.resolve(d)}}function k(a,c){for(var d=a.loads.concat([]),e=0,f=d.length;f>e;e++){var g=d[e],h=z.call(g.linkSets,a);if(b("link not present",-1!=h),g.linkSets.splice(h,1),0==g.linkSets.length){var i=z.call(a.loader._loads,g);-1!=i&&a.loader._loads.splice(i,1)}}a.reject(c)}function l(a,c){c.name&&(b("load not in module table",!a._modules[c.name]),a._modules[c.name]=c.module);var d=z.call(a._loads,c);-1!=d&&a._loads.splice(d,1);for(var e=0,f=c.linkSets.length;f>e;e++)d=z.call(c.linkSets[e].loads,c),c.linkSets[e].loads.splice(d,1);c.linkSets=[]}function m(a,b,c){return new x(n(a,b,c&&c.address?"fetch":"locate",void 0,c&&c.address,void 0)).then(function(a){return a})}function n(a,d,i,j,k,l){return function(m,n){if(a._modules[d])throw new TypeError('Module "'+d+'" already exists in the module table');for(var o=0,p=a._loads.length;p>o;o++)if(a._loads[o].name==d)throw new TypeError('Module "'+d+'" is already loading');var q=c(d);j&&(q.metadata=j);var r=h(a,q);a._loads.push(q),r.done.then(m,n),"locate"==i?e(a,q):"fetch"==i?f(a,q,x.resolve(k)):(b("translate step","translate"==i),q.address=k,g(a,q,x.resolve(l)))}}function o(a,c){return b("is linked "+c.name,"linked"==c.status),p(c.module,a),b("is a module",c.module.module instanceof v),c.module.module}function p(b,c){if(b.module)return b.module;for(var d in b.dependencies){var e=b.dependencies[d];c._modules[e].module||p(c._modules[e],c)}C.options.sourceMaps=!0,C.options.modules="instantiate";var f=new C.util.ErrorReporter;f.reportMessageInternal=function(a,b){throw b+"\n"+a};var g=new C.codegeneration.FromOptionsTransformer(f),h=g.transform(b.body);delete b.body;var i=new C.outputgeneration.SourceMapGenerator({file:b.address}),j={sourceMapGenerator:i},k=C.outputgeneration.TreeWriter.write(h,j);a.btoa&&(k+="\n//# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(j.sourceMap)))+"\n");var l=System.register;System.register=function(c,d,e){for(var f=0;f<d.length;f++)d[f]=b.dependencies[d[f]];b.module=new v(e.apply(a,d))},u(k,a,b.address,b.name),System.register=l}function q(a,b){for(var c=!1;a.length;){c=!0;a:for(var d=0;d<a.length;d++){var e=a[d],f=[];for(var g in e.dependencies){var h=e.dependencies[g];if(!b._modules[h])continue a;var i=e.depsList.indexOf(g);f[i]=h}if(c=!1,"declarative"==e.kind)e.module={name:e.name,dependencies:e.dependencies,body:e.body};else{var j=e.execute.apply(null,f);if(!(j instanceof v))throw new TypeError("Execution must define a Module instance");e.module={module:j}}e.status="linked",l(b,e)}if(c)throw new TypeError("Circular dependencies not supported by the polyfill")}}function r(a){if("object"!=typeof a)throw new TypeError("Options must be an object");a.normalize&&(this.normalize=a.normalize),a.locate&&(this.locate=a.locate),a.fetch&&(this.fetch=a.fetch),a.translate&&(this.translate=a.translate),a.instantiate&&(this.instantiate=a.instantiate),w(this,"global",{get:function(){throw new TypeError("global accessor not provided by polyfill")}}),w(this,"realm",{get:function(){throw new TypeError("Realms not implemented in polyfill")}}),this._modules={},this._loads=[]}function s(a,b,c,d){var e,f;if(b(a,c,d)!==!1)for(e in a)a.hasOwnProperty(e)&&"location"!=e&&"type"!=e&&(f=a[e],"object"==typeof f&&null!==f&&s(f,b,a,e))}function t(a){function b(a){-1==z.call(c,a)&&c.push(a)}var c=[];return s(a,function(a){"EXPORT_DECLARATION"==a.type?a.declaration.moduleSpecifier&&b(a.declaration.moduleSpecifier.token.processedValue):"IMPORT_DECLARATION"==a.type?b(a.moduleSpecifier.token.processedValue):"MODULE_DECLARATION"==a.type&&b(a.expression.token.processedValue)}),c}function u(a,b,c,d){try{Function("global",'var __moduleName = "'+(d||"").replace('"','"')+'"; with(global) { '+a+" \n }"+(c&&!a.match(/\/\/[@#] ?(sourceURL|sourceMappingURL)=([^\n]+)/)?"\n//# sourceURL="+c:"")).call(b,b)}catch(e){throw"SyntaxError"==e.name&&(e.message="Evaluating "+c+"\n "+e.message),e}}function v(a){if("object"!=typeof a)throw new TypeError("Expected object");if(!(this instanceof v))return new v(a);var b=this;for(var c in a)!function(a,c){w(b,a,{configurable:!1,enumerable:!0,get:function(){return c}})}(c,a[c]);Object.preventExtensions&&Object.preventExtensions(this)}var w,x=a.Promise||require("./promise");try{Object.defineProperty({},"a",{})&&(w=Object.defineProperty)}catch(y){w=function(a,b,c){a[b]=c.value||c.get.call(a)}}var z=Array.prototype.indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(this[b]===a)return b;return-1},A={};r.prototype={define:function(a,b,c){if(A[a])throw new TypeError("Module is already loading.");return A[a]=new x(n(this,a,c&&c.address?"fetch":"translate",c&&c.meta||{},c&&c.address,b)),A[a].then(function(){delete A[a]})},load:function(a,b){return this._modules[a]?(p(this._modules[a],this),x.resolve(this._modules[a].module)):A[a]?A[a]:(A[a]=m(this,a,b),A[a].then(function(){delete A[a]}))},module:function(a,b){var d=c();d.address=b&&b.address;var e=h(this,d),f=x.resolve(a),i=this,j=e.done.then(function(){return o(i,d)});return g(this,d,f),j},"import":function(a,b){if(this._modules[a])return p(this._modules[a],this),x.resolve(this._modules[a].module);var c=this;return(A[a]||(A[a]=m(this,a,b))).then(function(b){return delete A[a],o(c,b)})},eval:function(){throw new TypeError("Eval not implemented in polyfill")},get:function(a){return p(this._modules[a],this),this._modules[a].module},has:function(a){return!!this._modules[a]},set:function(a,b){if(!(b instanceof v))throw new TypeError("Set must be a module");this._modules[a]={module:b}},"delete":function(a){return this._modules[a]?delete this._modules[a]:!1},entries:function(){throw new TypeError("Iteration not yet implemented in the polyfill")},keys:function(){throw new TypeError("Iteration not yet implemented in the polyfill")},values:function(){throw new TypeError("Iteration not yet implemented in the polyfill")},normalize:function(a){return a},locate:function(a){return a.name},fetch:function(){throw new TypeError("Fetch not implemented")},translate:function(a){return a.source},instantiate:function(){}};var B=/^\s*export\s*\*\s*from\s*(?:'([^']+)'|"([^"]+)")/,C=a.traceur;$traceurRuntime.ModuleStore.get=$traceurRuntime.getModuleImpl=function(a){return System.get(a)};var D=0;"object"==typeof exports&&(module.exports=r),a.Loader||(a.Loader=r),a.LoaderPolyfill=r,a.Module||(a.Module=v)}("undefined"!=typeof global?global:this),function(a){function b(a){var b=String(a).replace(/^\s+|\s+$/g,"").match(/^([^:\/?#]+:)?(\/\/(?:[^:@]*(?::[^:@]*)?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);return b?{href:b[0]||"",protocol:b[1]||"",authority:b[2]||"",host:b[3]||"",hostname:b[4]||"",port:b[5]||"",pathname:b[6]||"",search:b[7]||"",hash:b[8]||""}:null}function c(a,c){function d(a){var b=[];return a.replace(/^(\.\.?(\/|$))+/,"").replace(/\/(\.(\/|$))+/g,"/").replace(/\/\.\.$/,"/../").replace(/\/?[^\/]*/g,function(a){"/.."===a?b.pop():b.push(a)}),b.join("").replace(/^\//,"/"===a.charAt(0)?"/":"")}return c=b(c||""),a=b(a||""),c&&a?(c.protocol||a.protocol)+(c.protocol||c.authority?c.authority:a.authority)+d(c.protocol||c.authority||"/"===c.pathname.charAt(0)?c.pathname:c.pathname?(a.authority&&!a.pathname?"/":"")+a.pathname.slice(0,a.pathname.lastIndexOf("/")+1)+c.pathname:a.pathname)+(c.protocol||c.authority||c.pathname?c.search:c.search||a.search)+c.hash:null}var d,e="undefined"!=typeof window,f=a.Loader||require("./loader"),g=a.Promise||require("./promise");if(e)d=function(a,b,c){function d(){b(f.responseText)}function e(){c(f.statusText+": "+a||"XHR error")}var f=new XMLHttpRequest,g=!0;if(!("withCredentials"in f)){var h=/^(\w+:)?\/\/([^\/]+)/.exec(a);h&&(g=h[2]===window.location.host,h[1]&&(g&=h[1]===window.location.protocol))}g||(f=new XDomainRequest,f.onload=d,f.onerror=e,f.ontimeout=e),f.onreadystatechange=function(){4===f.readyState&&(200===f.status||0==f.status&&f.responseText?d():e())},f.open("GET",a,!0),f.send(null)};else{var h=require("fs");d=function(a,b,c){return h.readFile(a,function(a,d){return a?c(a):(b(d+""),void 0)})}}var i=new f({global:e?window:a,strict:!0,normalize:function(a,b){if("string"!=typeof a)throw new TypeError("Module name must be a string");var c=a.split("/");if(0==c.length)throw new TypeError("No module name provided");var d=0,e=!1,f=0;if("."==c[0]){if(d++,d==c.length)throw new TypeError('Illegal module name "'+a+'"');e=!0}else{for(;".."==c[d];)if(d++,d==c.length)throw new TypeError('Illegal module name "'+a+'"');d&&(e=!0),f=d}for(var g=d;g<c.length;g++){var h=c[g];if(""==h||"."==h||".."==h)throw new TypeError('Illegal module name"'+a+'"')}if(!e)return a;{var i=[],j=(b||"").split("/");j.length-1-f}return i=i.concat(j.splice(0,j.length-1-f)),i=i.concat(c.splice(d)),i.join("/")},locate:function(a){var b,d=a.name,e="";for(var f in this.paths){var g=f.split("*");if(g.length>2)throw new TypeError("Only one wildcard in a path is permitted");1==g.length?d==f&&f.length>e.length&&(e=f):d.substr(0,g[0].length)==g[0]&&d.substr(d.length-g[1].length)==g[1]&&(e=f,b=d.substr(g[0].length,d.length-g[1].length-g[0].length))}var h=this.paths[e];return b&&(h=h.replace("*",b)),c(this.baseURL,h)},fetch:function(a){var b,e,f=new g(function(a,c){b=a,e=c});return d(c(this.baseURL,a.address),function(a){b(a)},e),f}});if(e){var j=window.location.href.split("#")[0].split("?")[0];i.baseURL=j.substring(0,j.lastIndexOf("/")+1)}else i.baseURL="./";if(i.paths={"*":"*.js"},e){var k=document.getElementsByTagName("script");k=k[k.length-1],document.onreadystatechange=function(){if("interactive"==document.readyState)for(var a=document.getElementsByTagName("script"),b=0;b<a.length;b++){var c=a[b];if("module"==c.type){var d=c.getAttribute("name"),e=c.getAttribute("src"),f=c.innerHTML;(d?i.define(d,f,{address:e}):i.module(f,{address:e})).then(function(){},function(a){nextTick(function(){throw a})})}}},k.getAttribute("data-init")&&window[k.getAttribute("data-init")]()}"object"==typeof exports&&(module.exports=i),a.System=i}("undefined"!=typeof global?global:this);
View
6 lib/index.js
@@ -1,5 +1,5 @@
module.exports = {
- Loader: require('./loader.js'),
- Module: require('./module.js'),
- System: require('./system.js')
+ Loader: require('./loader'),
+ Module: require('./module'),
+ System: require('./system')
};
View
198 lib/loader.js
@@ -10,15 +10,15 @@
- Abstract functions have been combined where possible, and their associated functions
commented
- - Declarative Module Support is entirely disabled, and an error will be thrown if
- the instantiate loader hook returns undefined
+ - When the traceur global is detected, declarative modules are transformed by Traceur
+ before execution. The Traceur parse tree is stored as load.body, analogously to the
+ spec
- - With this assumption, instead of Link, LinkDynamicModules is run directly
+ - Link and EnsureEvaluated have been customised from the spec
- - ES6 support is thus provided through the translate function of the System loader
+ - Module Linkage records are stored as: { module: (actual module), dependencies, body, name, address }
- - EnsureEvaluated is removed, but may in future implement dynamic execution pending
- issue - https://github.com/jorendorff/js-loaders/issues/63
+ - Cycles are not supported at all and will throw an error
- Realm implementation is entirely omitted. As such, Loader.global and Loader.realm
accessors will throw errors, as well as Loader.eval
@@ -54,8 +54,7 @@ function logloads(loads) {
} */
(function (global) {
- var Module = global.Module || require('./module.js');
- var Promise = global.Promise || require('./promise.js');
+ var Promise = global.Promise || require('./promise');
var defineProperty;
try {
@@ -72,10 +71,6 @@ function logloads(loads) {
if (!expression)
console.log('Assertion Failed - ' + name);
}
- function preventExtensions(obj) {
- if (Object.preventExtensions)
- Object.preventExtensions(obj);
- }
// Define an IE-friendly shim good-enough for purposes
var indexOf = Array.prototype.indexOf || function (item) {
@@ -99,10 +94,10 @@ function logloads(loads) {
}
// promise for a load record, can be in registry, already loading, or not
- function requestLoad(loader, request, refererName, refererAddress) {
+ function requestLoad(loader, request, referrerName, referrerAddress) {
return new Promise(function(resolve, reject) {
// CallNormalize
- resolve(loader.normalize(request, refererName, refererAddress));
+ resolve(loader.normalize(request, referrerName, referrerAddress));
})
// GetOrCreateLoad
@@ -177,18 +172,11 @@ function logloads(loads) {
var depsList;
if (instantiateResult === undefined) {
if (traceur) {
- var reporter = new traceur.util.ErrorReporter();
-
- reporter.reportMessageInternal = function(location, kind, format, args) {
- throw kind + '\n' + location;
- }
-
+ load.address = load.address || 'anon' + ++anonCnt;
var parser = new traceur.syntax.Parser(new traceur.syntax.SourceFile(load.address, load.source));
-
var tree = parser.parseModule();
-
depsList = getImports(tree);
- load.body = tree;
+ load.body = (new traceur.codegeneration.module.AttachModuleNameTransformer(load.name)).transformAny(tree);
}
else {
var match = load.source.match(aliasRegEx);
@@ -403,11 +391,64 @@ function logloads(loads) {
function evaluateLoadedModule(loader, load) {
assert('is linked ' + load.name, load.status == 'linked');
- assert('is a module', load.module instanceof Module);
+ ensureEvaluated(load.module, loader);
- // ensureEvaluated(load.module, [], loader);
+ assert('is a module', load.module.module instanceof Module);
- return load.module;
+ return load.module.module;
+ }
+ function ensureEvaluated(module, loader) {
+
+ // if already executed or dynamic module exists
+ // dynamic modules are evaluated during linking
+ if (module.module)
+ return module.module;
+
+ // continue until all evaluated
+ var circular = true;
+
+ // ensure all dependencies are evaluated first
+ for (var m in module.dependencies) {
+ var depName = module.dependencies[m];
+ // no module object means it is not executed
+ if (!loader._modules[depName].module)
+ ensureEvaluated(loader._modules[depName], loader);
+ }
+
+ // now evaluate this module
+ traceur.options.sourceMaps = true;
+ traceur.options.modules = 'instantiate';
+
+ var reporter = new traceur.util.ErrorReporter();
+
+ reporter.reportMessageInternal = function(location, kind, format, args) {
+ throw kind + '\n' + location;
+ }
+
+ // transform
+ var transformer = new traceur.codegeneration.FromOptionsTransformer(reporter);
+ var tree = transformer.transform(module.body);
+ delete module.body;
+
+ // convert back to a source string
+ var sourceMapGenerator = new traceur.outputgeneration.SourceMapGenerator({ file: module.address });
+ var options = { sourceMapGenerator: sourceMapGenerator };
+
+ var source = traceur.outputgeneration.TreeWriter.write(tree, options);
+ if (global.btoa)
+ source += '\n//# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(options.sourceMap))) + '\n';
+
+ var sysRegister = System.register;
+ System.register = function(name, deps, execute) {
+ for (var i = 0; i < deps.length; i++)
+ deps[i] = module.dependencies[deps[i]];
+
+ module.module = new Module(execute.apply(global, deps));
+ }
+
+ __eval(source, global, module.address, module.name);
+
+ System.register = sysRegister;
}
// Linking
@@ -433,36 +474,22 @@ function logloads(loads) {
circular = false;
- // all dependencies linked now, so we can execute
+ // all dependencies linked now, so we can link
if (load.kind == 'declarative') {
- traceur.options.sourceMaps = true;
- traceur.options.modules = 'instantiate';
-
- // transform
- var transformer = new traceur.codegeneration.FromOptionsTransformer(reporter);
- var tree = transformer.transform(load.body);
-
- // convert back to a source string
- var sourceMapGenerator = new traceur.outputgeneration.SourceMapGenerator({ file: load.address });
- var options = { sourceMapGenerator: sourceMapGenerator };
-
- var source = traceur.outputgeneration.TreeWriter.write(tree, options);
- if (global.btoa)
- source += '\n//# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(options.sourceMap))) + '\n';
-
- console.log(source);
-
- __eval(source, global, load.address, load.name);
-
- load.module = new Module(exports);
+ load.module = {
+ name: load.name,
+ dependencies: load.dependencies,
+ body: load.body
+ };
}
else {
- // dynamic module
var module = load.execute.apply(null, depNames);
if (!(module instanceof Module))
throw new TypeError('Execution must define a Module instance');
- load.module = module;
+ load.module = {
+ module: module
+ };
}
load.status = 'linked';
@@ -474,6 +501,7 @@ function logloads(loads) {
// console.log('linked');
}
+
// Loader
function Loader(options) {
if (typeof options != 'object')
@@ -515,8 +543,10 @@ function logloads(loads) {
return importPromises[name].then(function() { delete importPromises[name]; });
},
load: function(request, options) {
- if (this._modules[request])
- return Promise.resolve(this._modules[request]);
+ if (this._modules[request]) {
+ ensureEvaluated(this._modules[request], this);
+ return Promise.resolve(this._modules[request].module);
+ }
if (importPromises[request])
return importPromises[request];
importPromises[request] = loadModule(this, request, options);
@@ -527,27 +557,31 @@ function logloads(loads) {
load.address = options && options.address;
var linkSet = createLinkSet(this, load);
var sourcePromise = Promise.resolve(source);
+ var loader = this;
var p = linkSet.done.then(function() {
- evaluateLoadedModule(this, load);
+ return evaluateLoadedModule(loader, load);
});
proceedToTranslate(this, load, sourcePromise);
return p;
},
'import': function(name, options) {
- if (this._modules[name])
- return Promise.resolve(this._modules[name]);
+ if (this._modules[name]) {
+ ensureEvaluated(this._modules[name], this);
+ return Promise.resolve(this._modules[name].module);
+ }
+ var loader = this;
return (importPromises[name] || (importPromises[name] = loadModule(this, name, options)))
.then(function(load) {
delete importPromises[name];
- return evaluateLoadedModule(this, load);
+ return evaluateLoadedModule(loader, load);
});
},
eval: function(source) {
throw new TypeError('Eval not implemented in polyfill')
},
get: function(key) {
- // NB run ensure evaluted here when implemented
- return this._modules[key];
+ ensureEvaluated(this._modules[key], this);
+ return this._modules[key].module;
},
has: function(name) {
return !!this._modules[name];
@@ -555,7 +589,9 @@ function logloads(loads) {
set: function(name, module) {
if (!(module instanceof Module))
throw new TypeError('Set must be a module');
- this._modules[name] = module;
+ this._modules[name] = {
+ module: module
+ };
},
'delete': function(name) {
return this._modules[name] ? delete this._modules[name] : false;
@@ -570,7 +606,7 @@ function logloads(loads) {
values: function() {
throw new TypeError('Iteration not yet implemented in the polyfill');
},
- normalize: function(name, refererName, refererAddress) {
+ normalize: function(name, referrerName, referrerAddress) {
return name;
},
locate: function(load) {
@@ -586,13 +622,6 @@ function logloads(loads) {
}
};
- if (typeof exports === 'object') {
- module.exports = Loader;
- }
-
- global.Loader || (global.Loader = Loader);
- global.LoaderPolyfill = Loader;
-
// es6 module forwarding - allow detecting without Traceur
var aliasRegEx = /^\s*export\s*\*\s*from\s*(?:'([^']+)'|"([^"]+)")/;
@@ -601,6 +630,9 @@ function logloads(loads) {
Use Traceur?
*/
var traceur = global.traceur;
+ $traceurRuntime.ModuleStore.get = $traceurRuntime.getModuleImpl = function(name) {
+ return System.get(name);
+ }
// tree traversal, NB should use visitor pattern here
function traverse(object, iterator, parent, parentProperty) {
@@ -643,6 +675,7 @@ function logloads(loads) {
});
return imports;
}
+ var anonCnt = 0;
function __eval(__source, global, __sourceURL, __moduleName) {
@@ -658,4 +691,37 @@ function logloads(loads) {
}
}
+ // Module Object
+ function Module(obj) {
+ if (typeof obj != 'object')
+ throw new TypeError('Expected object');
+
+ if (!(this instanceof Module))
+ return new Module(obj);
+
+ var self = this;
+ for (var key in obj) {
+ (function (key, value) {
+ defineProperty(self, key, {
+ configurable: false,
+ enumerable: true,
+ get: function () {
+ return value;
+ }
+ });
+ })(key, obj[key]);
+ }
+ if (Object.preventExtensions)
+ Object.preventExtensions(this);
+ }
+ // Module.prototype = null;
+
+
+ if (typeof exports === 'object')
+ module.exports = Loader;
+
+ global.Loader || (global.Loader = Loader);
+ global.LoaderPolyfill = Loader;
+ global.Module || (global.Module = Module);
+
})(typeof global !== 'undefined' ? global : this);
View
45 lib/module.js
@@ -1,45 +0,0 @@
-(function (global) {
- var defineProperty;
- try {
- if (!!Object.defineProperty({}, 'a', {})) {
- defineProperty = Object.defineProperty;
- }
- } catch (e) {
- defineProperty = function (obj, prop, opt) {
- obj[prop] = opt.value || opt.get.call(obj);
- }
- }
-
- // Module Object
- function Module(obj) {
- if (typeof obj != 'object')
- throw new TypeError('Expected object');
-
- if (!(this instanceof Module))
- return new Module(obj);
-
- var self = this;
- for (var key in obj) {
- (function (key, value) {
- defineProperty(self, key, {
- configurable: false,
- enumerable: true,
- get: function () {
- return value;
- }
- });
- })(key, obj[key]);
- }
- if (Object.preventExtensions)
- Object.preventExtensions(this);
- }
- // Module.prototype = null;
-
- if (typeof exports === 'object') {
- module.exports = Module;
- }
-
- global.Module || (global.Module = Module);
- global.ModulePolyfill = Module;
-
-})(typeof global !== 'undefined' ? global : this);
View
31 lib/system.js
@@ -5,17 +5,15 @@
- Implemented to https://github.com/jorendorff/js-loaders/blob/master/browser-loader.js
- - <script type="module"> supported, but <module> tag not
+ - <script type="module"> supported
*********************************************************************************************
*/
(function (global) {
- console.log('SYSTEM');
var isBrowser = typeof window != 'undefined';
- var Module = global.Module || require('./module.js');
- var Loader = global.Loader || require('./loader.js');
- var Promise = global.Promise || require('./promise.js');
+ var Loader = global.Loader || require('./loader');
+ var Promise = global.Promise || require('./promise');
// Helpers
// Absolute URL parsing, from https://gist.github.com/Yaffle/1088850
@@ -58,15 +56,6 @@
(href.protocol || href.authority || href.pathname ? href.search : (href.search || base.search)) +
href.hash;
}
- // Define an IE-friendly shim good-enough for purposes
- var indexOf = Array.prototype.indexOf || function (item) {
- for (var i = 0, thisLen = this.length; i < thisLen; i++) {
- if (this[i] === item) {
- return i;
- }
- }
- return -1;
- };
var fetchTextFromURL;
if (isBrowser) {
@@ -218,21 +207,15 @@
}
});
- // count anonymous evals to have unique name
- var anonCnt = 1;
-
if (isBrowser) {
var href = window.location.href.split('#')[0].split('?')[0];
- System.baseURL = href.substring(0, href.lastIndexOf('\/') + 1);
+ System.baseURL = href.substring(0, href.lastIndexOf('/') + 1);
}
else {
System.baseURL = './';
}
System.paths = { '*': '*.js' };
- // Export the System object
- global.System || (global.System = System);
-
// <script type="module"> support
// allow a data-init function callback once loaded
if (isBrowser) {
@@ -265,11 +248,9 @@
window[curScript.getAttribute('data-init')]();
}
- if (typeof exports === 'object') {
+ if (typeof exports === 'object')
module.exports = System;
- }
- global.System || (global.System = System);
- global.SystemPolyfill = System;
+ global.System = System;
})(typeof global !== 'undefined' ? global : this);
View
4 package.json
@@ -1,7 +1,7 @@
{
"name": "es6-module-loader",
"description": "An ES6 Module Loader shim",
- "version": "0.4.3",
+ "version": "0.5.0",
"homepage": "https://github.com/ModuleLoader/es6-module-loader",
"author": {
"name": "Guy Bedford, Luke Hoban, Addy Osmani",
@@ -44,6 +44,6 @@
"lib/es6-module-loader.js"
],
"dependencies": {
- "traceur": "0.0.24"
+ "traceur": "0.0.25"
}
}
View
1  test/syntax/export.js
@@ -2,7 +2,6 @@ export var p = 5;
export function foo() {};
export var q = {};
-export default 42;
export default function bar() {};
var s = 4;
View
2  test/syntax/import.js
@@ -4,6 +4,8 @@ import d from './export';
import { s as p } from './reexport1';
+import r from './reexport2';
+
import { z, q as r } from './reexport2';
module q from './reexport1';
View
6 test/test.html
@@ -14,7 +14,7 @@
<script src="../lib/traceur.js"></script>
- <script src="../lib/es6-module-loader.js"></script>
+ <script src="../tmp/es6-module-loader.js"></script>
<script>
runTests();
@@ -48,6 +48,10 @@
test('Named &lt;script type="module"> tag', function(assert) {
System.import('named-module').then(function(m) {
assert(m.p, 'hi');
+ }, function(e) {
+ setTimeout(function() {
+ throw e;
+ }, 1);
});
});
test('Anonymous &lt;script type="module"> tag', function(assert) {
View
8 test/test.js
@@ -187,7 +187,9 @@ function runTests() {
System.import('syntax/es6-withdep').then(function(m) {
assert(m.p, 'p');
}, function(e) {
- console.log(e);
+ setTimeout(function() {
+ throw e;
+ }, 1);
});
});
@@ -306,6 +308,10 @@ function runTests() {
[m.d, 4],
[typeof m.q.foo, 'function']
);
+ }).catch(function(e) {
+ setTimeout(function() {
+ throw e;
+ }, 1);
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.