diff --git a/dist/system-production-amd.js b/dist/system-production-amd.js index 6861fb28..c4a56fc4 100644 --- a/dist/system-production-amd.js +++ b/dist/system-production-amd.js @@ -316,12 +316,20 @@ function register(loader) { // now we know the entry is in our unlinked linkage group var depGroupIndex = entry.groupIndex + (depEntry.declarative != entry.declarative); - if (depEntry.groupIndex === undefined) { + // the group index of an entry is always the maximum + if (depEntry.groupIndex === undefined || depEntry.groupIndex < depGroupIndex) { + + // if already in a group, remove from the old group + if (depEntry.groupIndex) { + groups[depEntry.groupIndex].splice(groups[depEntry.groupIndex].indexOf(depEntry), 1); + + // if the old group is empty, then we have a mixed depndency cycle + if (groups[depEntry.groupIndex].length == 0) + throw new TypeError("Mixed dependency cycle detected"); + } + depEntry.groupIndex = depGroupIndex; } - else if (depEntry.groupIndex != depGroupIndex) { - throw new TypeError('System.register mixed dependency cycle'); - } buildGroups(depEntry, loader, groups); } @@ -336,7 +344,7 @@ function register(loader) { buildGroups(startEntry, loader, groups); - var curGroupDeclarative = startEntry.declarative == groups.length % 2; + var curGroupDeclarative = !!startEntry.declarative == groups.length % 2; for (var i = groups.length - 1; i >= 0; i--) { var group = groups[i]; for (var j = 0; j < group.length; j++) { @@ -482,8 +490,12 @@ function register(loader) { for (var i = 0; i < entry.normalizedDeps.length; i++) { var depName = entry.normalizedDeps[i]; - if (indexOf.call(seen, depName) == -1) - ensureEvaluated(depName, seen, loader); + if (indexOf.call(seen, depName) == -1) { + if (!loader.defined[depName]) + loader.get(depName); + else + ensureEvaluated(depName, seen, loader); + } } if (entry.evaluated) diff --git a/dist/system-production-amd.min.js b/dist/system-production-amd.min.js index 372fec38..29639fbe 100644 --- a/dist/system-production-amd.min.js +++ b/dist/system-production-amd.min.js @@ -5,4 +5,4 @@ * MIT License */ -!function(__$global){function __eval(__source,__global,__address,__sourceMap){try{__source="with(__global) { (function() { "+__source+" \n }).call(__global); }\n//# sourceURL="+__address+(__sourceMap?"\n//# sourceMappingURL="+__sourceMap:""),eval(__source)}catch(e){throw"SyntaxError"==e.name&&(e.message="Evaluating "+__address+"\n "+e.message),e}}var indexOf=Array.prototype.indexOf||function(e){for(var t=0,r=this.length;r>t;t++)if(this[t]===e)return t;return-1};__$global.upgradeSystemLoader=function(){function e(e){function t(e){var t=this;"@traceur"==e.name&&(m=System,p=Module);var r,n=e.source.lastIndexOf("\n");-1!=n&&"//# sourceMappingURL="==e.source.substr(n+1,21)&&(r=a(e.address,e.source.substr(n+22))),__eval(e.source,t.global,e.address,r),"@traceur"==e.name&&(t.global.traceurSystem=t.global.System,t.global.System=m)}function r(e){var t=String(e).replace(/^\s+|\s+$/g,"").match(/^([^:\/?#]+:)?(\/\/(?:[^:@]*(?::[^:@]*)?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);return t?{href:t[0]||"",protocol:t[1]||"",authority:t[2]||"",host:t[3]||"",hostname:t[4]||"",port:t[5]||"",pathname:t[6]||"",search:t[7]||"",hash:t[8]||""}:null}function a(e,t){function a(e){var t=[];return e.replace(/^(\.\.?(\/|$))+/,"").replace(/\/(\.(\/|$))+/g,"/").replace(/\/\.\.$/,"/../").replace(/\/?[^\/]*/g,function(e){"/.."===e?t.pop():t.push(e)}),t.join("").replace(/^\//,"/"===e.charAt(0)?"/":"")}return t=r(t||""),e=r(e||""),t&&e?(t.protocol||e.protocol)+(t.protocol||t.authority?t.authority:e.authority)+a(t.protocol||t.authority||"/"===t.pathname.charAt(0)?t.pathname:t.pathname?(e.authority&&!e.pathname?"/":"")+e.pathname.slice(0,e.pathname.lastIndexOf("/")+1)+t.pathname:e.pathname)+(t.protocol||t.authority||t.pathname?t.search:t.search||e.search)+t.hash:null}var n=e["import"];e["import"]=function(e,t){return n.call(this,e,t).then(function(e){return e.__useDefault?e["default"]:e})},e.set("@empty",Module({})),e.config=function(e){for(var t in e){var r=e[t];if("object"==typeof r){this[t]=this[t]||{};for(var a in r)this[t][a]=r[a]}else this[t]=r}};var i;if("undefined"==typeof window)i=__dirname+"/";else if(i=document.baseURI,!i){var o=document.getElementsByTagName("base");i=o[0]&&o[0].href||window.location.href}var s,u=e.locate;e.locate=function(e){return this.baseURL!=s&&(s=a(i,this.baseURL),"/"!=s.substr(s.length-1,1)&&(s+="/"),this.baseURL=s),Promise.resolve(u.call(this,e))};var d=/^\s*export\s*\*\s*from\s*(?:'([^']+)'|"([^"]+)")/,l=/(?:^\s*|[}{\(\);,\n]\s*)(import\s+['"]|(import|module)\s+[^"'\(\)\n;]+\s+from\s+['"]|export\s+(\*|\{|default|function|var|const|let|[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*))/,c=e.translate;e.translate=function(e){var r=this;if(r.__exec=t,"@traceur"==e.name)return c.call(r,e);var a;if(!r.global.traceur&&("es6"==e.metadata.format||!e.metadata.format)&&(a=e.source.match(d))){var n=a[1]||a[2];e.metadata.deps=[n],e.metadata.execute=function(e){return e(n)}}return"es6"!=e.metadata.format&&(e.metadata.format||!e.source.match(l))||(e.metadata.format="es6",r.global.traceur)?c.call(r,e):r["import"]("@traceur").then(function(){return c.call(r,e)})};var f=e.instantiate;e.instantiate=function(e){var t=this;return"@traceur"==e.name?(t.__exec(e),{deps:[],execute:function(){return Module({})}}):f.call(t,e)};var m,p;e.__exec=t}function t(e){function t(e){for(var t=[],r=0;r=0;u--){for(var d=n[u],l=0;la.length)return 0;for(var n=0;nparseInt(n[i])?1:-1}return 0};e.versions=e.versions||{};var a=e.normalize;e.normalize=function(n,i,o){e.versions||(e.versions={});var s=this.versions;return Promise.resolve(a.call(this,n,i,o)).then(function(e){var a,n,i,o,u=e.indexOf("@");if(-1==u){for(var d in s)if(o=s[d],e.substr(0,d.length)==d&&(i=e.substr(d.length,1),!i||"/"==i))return d+"@"+("string"==typeof o?o:o[o.length-1])+e.substr(d.length);return e}a=e.substr(u+1).split("/")[0];var l,c=a.length;if("^"==a.substr(0,1)&&(a=a.substr(1),l=!0),n=a.match(t),!n)return e;l&&(n[2]||(l=!1),n[3]||(n[2]>0?n[3]="0":l=!1)),l&&(n[1]>0?(n[2]||(a=n[1]+".0.0"),n[3]||(a=n[1]+".0"),l=a,n=[n[1]]):n[2]>0?(l=a,n=[0,n[2]]):(l=!1,n=[0,0,n[3]]),a=n.join("."));var f=e.substr(0,u);if(o=s[f]||[],"string"==typeof o&&(o=[o]),!n[3]||l)for(var m=o.length-1;m>=0;m--){var p=o[m];if(p.substr(0,a.length)==a&&p.substr(a.length,1).match(/^[\.\-]?$/)&&(!l||l&&-1!=r(p,l)))return f+"@"+p+e.substr(f.length+c+1)}return-1==indexOf.call(o,a)&&(o.push(a),o.sort(r),e=f+"@"+a+e.substr(f.length+c+1),n[3]&&-1!=(u=indexOf.call(o,n[1]+"."+n[2]))&&o.splice(u,1),n[2]&&-1!=(u=indexOf.call(o,n[1]))&&o.splice(u,1),s[f]=1==o.length?o[0]:o),e})}}__$global.upgradeSystemLoader=void 0,e(System),t(System),r(System),a(System),n(System),i(System),System.baseURL=__$curScript.getAttribute("data-baseurl")||System.baseURL;var o=__$curScript.getAttribute("data-config");""===o&&(o=System.baseURL+"config.json");var s=__$curScript.getAttribute("data-main");System.paths["@traceur"]||(System.paths["@traceur"]="undefined"!=typeof __$curScript&&__$curScript.getAttribute("data-traceur-src")),(o?Promise.resolve(System.fetch.call(System,{address:o,metadata:{}})).then(JSON.parse).then(System.config):Promise.resolve()).then(function(){return s?System["import"](s):void 0})["catch"](function(e){setTimeout(function(){throw e})})};var __$curScript;!function(e){if("undefined"!=typeof window){var t=document.getElementsByTagName("script");if(__$curScript=t[t.length-1],!e.System||e.System.registerModule){var r=__$curScript.src,a=r.substr(0,r.lastIndexOf("/")+1);document.write('')}else e.upgradeSystemLoader()}else{var n=require("es6-module-loader");e.System=n.System,e.Loader=n.Loader,e.Module=n.Module,module.exports=e.System,e.upgradeSystemLoader()}}(__$global)}("undefined"!=typeof window?window:global); \ No newline at end of file +!function(__$global){function __eval(__source,__global,__address,__sourceMap){try{__source="with(__global) { (function() { "+__source+" \n }).call(__global); }\n//# sourceURL="+__address+(__sourceMap?"\n//# sourceMappingURL="+__sourceMap:""),eval(__source)}catch(e){throw"SyntaxError"==e.name&&(e.message="Evaluating "+__address+"\n "+e.message),e}}var indexOf=Array.prototype.indexOf||function(e){for(var t=0,r=this.length;r>t;t++)if(this[t]===e)return t;return-1};__$global.upgradeSystemLoader=function(){function e(e){function t(e){var t=this;"@traceur"==e.name&&(m=System,p=Module);var r,a=e.source.lastIndexOf("\n");-1!=a&&"//# sourceMappingURL="==e.source.substr(a+1,21)&&(r=n(e.address,e.source.substr(a+22))),__eval(e.source,t.global,e.address,r),"@traceur"==e.name&&(t.global.traceurSystem=t.global.System,t.global.System=m)}function r(e){var t=String(e).replace(/^\s+|\s+$/g,"").match(/^([^:\/?#]+:)?(\/\/(?:[^:@]*(?::[^:@]*)?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);return t?{href:t[0]||"",protocol:t[1]||"",authority:t[2]||"",host:t[3]||"",hostname:t[4]||"",port:t[5]||"",pathname:t[6]||"",search:t[7]||"",hash:t[8]||""}:null}function n(e,t){function n(e){var t=[];return e.replace(/^(\.\.?(\/|$))+/,"").replace(/\/(\.(\/|$))+/g,"/").replace(/\/\.\.$/,"/../").replace(/\/?[^\/]*/g,function(e){"/.."===e?t.pop():t.push(e)}),t.join("").replace(/^\//,"/"===e.charAt(0)?"/":"")}return t=r(t||""),e=r(e||""),t&&e?(t.protocol||e.protocol)+(t.protocol||t.authority?t.authority:e.authority)+n(t.protocol||t.authority||"/"===t.pathname.charAt(0)?t.pathname:t.pathname?(e.authority&&!e.pathname?"/":"")+e.pathname.slice(0,e.pathname.lastIndexOf("/")+1)+t.pathname:e.pathname)+(t.protocol||t.authority||t.pathname?t.search:t.search||e.search)+t.hash:null}var a=e["import"];e["import"]=function(e,t){return a.call(this,e,t).then(function(e){return e.__useDefault?e["default"]:e})},e.set("@empty",Module({})),e.config=function(e){for(var t in e){var r=e[t];if("object"==typeof r){this[t]=this[t]||{};for(var n in r)this[t][n]=r[n]}else this[t]=r}};var o;if("undefined"==typeof window)o=__dirname+"/";else if(o=document.baseURI,!o){var i=document.getElementsByTagName("base");o=i[0]&&i[0].href||window.location.href}var s,u=e.locate;e.locate=function(e){return this.baseURL!=s&&(s=n(o,this.baseURL),"/"!=s.substr(s.length-1,1)&&(s+="/"),this.baseURL=s),Promise.resolve(u.call(this,e))};var d=/^\s*export\s*\*\s*from\s*(?:'([^']+)'|"([^"]+)")/,l=/(?:^\s*|[}{\(\);,\n]\s*)(import\s+['"]|(import|module)\s+[^"'\(\)\n;]+\s+from\s+['"]|export\s+(\*|\{|default|function|var|const|let|[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*))/,c=e.translate;e.translate=function(e){var r=this;if(r.__exec=t,"@traceur"==e.name)return c.call(r,e);var n;if(!r.global.traceur&&("es6"==e.metadata.format||!e.metadata.format)&&(n=e.source.match(d))){var a=n[1]||n[2];e.metadata.deps=[a],e.metadata.execute=function(e){return e(a)}}return"es6"!=e.metadata.format&&(e.metadata.format||!e.source.match(l))||(e.metadata.format="es6",r.global.traceur)?c.call(r,e):r["import"]("@traceur").then(function(){return c.call(r,e)})};var f=e.instantiate;e.instantiate=function(e){var t=this;return"@traceur"==e.name?(t.__exec(e),{deps:[],execute:function(){return Module({})}}):f.call(t,e)};var m,p;e.__exec=t}function t(e){function t(e){for(var t=[],r=0;r=0;u--){for(var d=a[u],l=0;ln.length)return 0;for(var a=0;aparseInt(a[o])?1:-1}return 0};e.versions=e.versions||{};var n=e.normalize;e.normalize=function(a,o,i){e.versions||(e.versions={});var s=this.versions;return Promise.resolve(n.call(this,a,o,i)).then(function(e){var n,a,o,i,u=e.indexOf("@");if(-1==u){for(var d in s)if(i=s[d],e.substr(0,d.length)==d&&(o=e.substr(d.length,1),!o||"/"==o))return d+"@"+("string"==typeof i?i:i[i.length-1])+e.substr(d.length);return e}n=e.substr(u+1).split("/")[0];var l,c=n.length;if("^"==n.substr(0,1)&&(n=n.substr(1),l=!0),a=n.match(t),!a)return e;l&&(a[2]||(l=!1),a[3]||(a[2]>0?a[3]="0":l=!1)),l&&(a[1]>0?(a[2]||(n=a[1]+".0.0"),a[3]||(n=a[1]+".0"),l=n,a=[a[1]]):a[2]>0?(l=n,a=[0,a[2]]):(l=!1,a=[0,0,a[3]]),n=a.join("."));var f=e.substr(0,u);if(i=s[f]||[],"string"==typeof i&&(i=[i]),!a[3]||l)for(var m=i.length-1;m>=0;m--){var p=i[m];if(p.substr(0,n.length)==n&&p.substr(n.length,1).match(/^[\.\-]?$/)&&(!l||l&&-1!=r(p,l)))return f+"@"+p+e.substr(f.length+c+1)}return-1==indexOf.call(i,n)&&(i.push(n),i.sort(r),e=f+"@"+n+e.substr(f.length+c+1),a[3]&&-1!=(u=indexOf.call(i,a[1]+"."+a[2]))&&i.splice(u,1),a[2]&&-1!=(u=indexOf.call(i,a[1]))&&i.splice(u,1),s[f]=1==i.length?i[0]:i),e})}}__$global.upgradeSystemLoader=void 0,e(System),t(System),r(System),n(System),a(System),o(System),System.baseURL=__$curScript.getAttribute("data-baseurl")||System.baseURL;var i=__$curScript.getAttribute("data-config");""===i&&(i=System.baseURL+"config.json");var s=__$curScript.getAttribute("data-main");System.paths["@traceur"]||(System.paths["@traceur"]="undefined"!=typeof __$curScript&&__$curScript.getAttribute("data-traceur-src")),(i?Promise.resolve(System.fetch.call(System,{address:i,metadata:{}})).then(JSON.parse).then(System.config):Promise.resolve()).then(function(){return s?System["import"](s):void 0})["catch"](function(e){setTimeout(function(){throw e})})};var __$curScript;!function(e){if("undefined"!=typeof window){var t=document.getElementsByTagName("script");if(__$curScript=t[t.length-1],!e.System||e.System.registerModule){var r=__$curScript.src,n=r.substr(0,r.lastIndexOf("/")+1);document.write('')}else e.upgradeSystemLoader()}else{var a=require("es6-module-loader");e.System=a.System,e.Loader=a.Loader,e.Module=a.Module,module.exports=e.System,e.upgradeSystemLoader()}}(__$global)}("undefined"!=typeof window?window:global); \ No newline at end of file diff --git a/dist/system.js b/dist/system.js index 6796a4d0..ccb6183c 100644 --- a/dist/system.js +++ b/dist/system.js @@ -409,12 +409,20 @@ function register(loader) { // now we know the entry is in our unlinked linkage group var depGroupIndex = entry.groupIndex + (depEntry.declarative != entry.declarative); - if (depEntry.groupIndex === undefined) { + // the group index of an entry is always the maximum + if (depEntry.groupIndex === undefined || depEntry.groupIndex < depGroupIndex) { + + // if already in a group, remove from the old group + if (depEntry.groupIndex) { + groups[depEntry.groupIndex].splice(groups[depEntry.groupIndex].indexOf(depEntry), 1); + + // if the old group is empty, then we have a mixed depndency cycle + if (groups[depEntry.groupIndex].length == 0) + throw new TypeError("Mixed dependency cycle detected"); + } + depEntry.groupIndex = depGroupIndex; } - else if (depEntry.groupIndex != depGroupIndex) { - throw new TypeError('System.register mixed dependency cycle'); - } buildGroups(depEntry, loader, groups); } @@ -429,7 +437,7 @@ function register(loader) { buildGroups(startEntry, loader, groups); - var curGroupDeclarative = startEntry.declarative == groups.length % 2; + var curGroupDeclarative = !!startEntry.declarative == groups.length % 2; for (var i = groups.length - 1; i >= 0; i--) { var group = groups[i]; for (var j = 0; j < group.length; j++) { @@ -575,8 +583,12 @@ function register(loader) { for (var i = 0; i < entry.normalizedDeps.length; i++) { var depName = entry.normalizedDeps[i]; - if (indexOf.call(seen, depName) == -1) - ensureEvaluated(depName, seen, loader); + if (indexOf.call(seen, depName) == -1) { + if (!loader.defined[depName]) + loader.get(depName); + else + ensureEvaluated(depName, seen, loader); + } } if (entry.evaluated) diff --git a/dist/system.min.js b/dist/system.min.js index 59c1e5b4..c04b43ac 100644 --- a/dist/system.min.js +++ b/dist/system.min.js @@ -5,4 +5,4 @@ * MIT License */ -!function(__$global){function __eval(__source,__global,__address,__sourceMap){try{__source="with(__global) { (function() { "+__source+" \n }).call(__global); }\n//# sourceURL="+__address+(__sourceMap?"\n//# sourceMappingURL="+__sourceMap:""),eval(__source)}catch(e){throw"SyntaxError"==e.name&&(e.message="Evaluating "+__address+"\n "+e.message),e}}var indexOf=Array.prototype.indexOf||function(e){for(var t=0,a=this.length;a>t;t++)if(this[t]===e)return t;return-1};__$global.upgradeSystemLoader=function(){function e(e){function t(e){var t=this;"@traceur"==e.name&&(m=System,p=Module);var a,n=e.source.lastIndexOf("\n");-1!=n&&"//# sourceMappingURL="==e.source.substr(n+1,21)&&(a=r(e.address,e.source.substr(n+22))),__eval(e.source,t.global,e.address,a),"@traceur"==e.name&&(t.global.traceurSystem=t.global.System,t.global.System=m)}function a(e){var t=String(e).replace(/^\s+|\s+$/g,"").match(/^([^:\/?#]+:)?(\/\/(?:[^:@]*(?::[^:@]*)?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);return t?{href:t[0]||"",protocol:t[1]||"",authority:t[2]||"",host:t[3]||"",hostname:t[4]||"",port:t[5]||"",pathname:t[6]||"",search:t[7]||"",hash:t[8]||""}:null}function r(e,t){function r(e){var t=[];return e.replace(/^(\.\.?(\/|$))+/,"").replace(/\/(\.(\/|$))+/g,"/").replace(/\/\.\.$/,"/../").replace(/\/?[^\/]*/g,function(e){"/.."===e?t.pop():t.push(e)}),t.join("").replace(/^\//,"/"===e.charAt(0)?"/":"")}return t=a(t||""),e=a(e||""),t&&e?(t.protocol||e.protocol)+(t.protocol||t.authority?t.authority:e.authority)+r(t.protocol||t.authority||"/"===t.pathname.charAt(0)?t.pathname:t.pathname?(e.authority&&!e.pathname?"/":"")+e.pathname.slice(0,e.pathname.lastIndexOf("/")+1)+t.pathname:e.pathname)+(t.protocol||t.authority||t.pathname?t.search:t.search||e.search)+t.hash:null}var n=e["import"];e["import"]=function(e,t){return n.call(this,e,t).then(function(e){return e.__useDefault?e["default"]:e})},e.set("@empty",Module({})),e.config=function(e){for(var t in e){var a=e[t];if("object"==typeof a){this[t]=this[t]||{};for(var r in a)this[t][r]=a[r]}else this[t]=a}};var o;if("undefined"==typeof window)o=__dirname+"/";else if(o=document.baseURI,!o){var i=document.getElementsByTagName("base");o=i[0]&&i[0].href||window.location.href}var s,l=e.locate;e.locate=function(e){return this.baseURL!=s&&(s=r(o,this.baseURL),"/"!=s.substr(s.length-1,1)&&(s+="/"),this.baseURL=s),Promise.resolve(l.call(this,e))};var u=/^\s*export\s*\*\s*from\s*(?:'([^']+)'|"([^"]+)")/,d=/(?:^\s*|[}{\(\);,\n]\s*)(import\s+['"]|(import|module)\s+[^"'\(\)\n;]+\s+from\s+['"]|export\s+(\*|\{|default|function|var|const|let|[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*))/,c=e.translate;e.translate=function(e){var a=this;if(a.__exec=t,"@traceur"==e.name)return c.call(a,e);var r;if(!a.global.traceur&&("es6"==e.metadata.format||!e.metadata.format)&&(r=e.source.match(u))){var n=r[1]||r[2];e.metadata.deps=[n],e.metadata.execute=function(e){return e(n)}}return"es6"!=e.metadata.format&&(e.metadata.format||!e.source.match(d))||(e.metadata.format="es6",a.global.traceur)?c.call(a,e):a["import"]("@traceur").then(function(){return c.call(a,e)})};var f=e.instantiate;e.instantiate=function(e){var t=this;return"@traceur"==e.name?(t.__exec(e),{deps:[],execute:function(){return Module({})}}):f.call(t,e)};var m,p;e.__exec=t}function t(e){function t(e,t){var a=e.meta&&e.meta[t.name];if(a)for(var r in a)t.metadata[r]=t.metadata[r]||a[r]}var a=/^(\s*\/\*.*\*\/|\s*\/\/[^\n]*|\s*"[^"]+"\s*;?|\s*'[^']+'\s*;?)+/,r=/\/\*.*\*\/|\/\/[^\n]*|"[^"]+"\s*;?|'[^']+'\s*;?/g;e.meta={};var n=e.locate;e.locate=function(e){return t(this,e),n.call(this,e)};var o=e.translate;e.translate=function(e){var n=e.source.match(a);if(n)for(var i=n[0].match(r),s=0;s=0;l--){for(var u=n[l],d=0;dr.length)return 0;for(var n=0;nparseInt(n[o])?1:-1}return 0};e.versions=e.versions||{};var r=e.normalize;e.normalize=function(n,o,i){e.versions||(e.versions={});var s=this.versions;return Promise.resolve(r.call(this,n,o,i)).then(function(e){var r,n,o,i,l=e.indexOf("@");if(-1==l){for(var u in s)if(i=s[u],e.substr(0,u.length)==u&&(o=e.substr(u.length,1),!o||"/"==o))return u+"@"+("string"==typeof i?i:i[i.length-1])+e.substr(u.length);return e}r=e.substr(l+1).split("/")[0];var d,c=r.length;if("^"==r.substr(0,1)&&(r=r.substr(1),d=!0),n=r.match(t),!n)return e;d&&(n[2]||(d=!1),n[3]||(n[2]>0?n[3]="0":d=!1)),d&&(n[1]>0?(n[2]||(r=n[1]+".0.0"),n[3]||(r=n[1]+".0"),d=r,n=[n[1]]):n[2]>0?(d=r,n=[0,n[2]]):(d=!1,n=[0,0,n[3]]),r=n.join("."));var f=e.substr(0,l);if(i=s[f]||[],"string"==typeof i&&(i=[i]),!n[3]||d)for(var m=i.length-1;m>=0;m--){var p=i[m];if(p.substr(0,r.length)==r&&p.substr(r.length,1).match(/^[\.\-]?$/)&&(!d||d&&-1!=a(p,d)))return f+"@"+p+e.substr(f.length+c+1)}return-1==indexOf.call(i,r)&&(i.push(r),i.sort(a),e=f+"@"+r+e.substr(f.length+c+1),n[3]&&-1!=(l=indexOf.call(i,n[1]+"."+n[2]))&&i.splice(l,1),n[2]&&-1!=(l=indexOf.call(i,n[1]))&&i.splice(l,1),s[f]=1==i.length?i[0]:i),e})}}__$global.upgradeSystemLoader=void 0,e(System),t(System),a(System),r(System),n(System),o(System),i(System),s(System),l(System),u(System),System.baseURL=__$curScript.getAttribute("data-baseurl")||System.baseURL;var d=__$curScript.getAttribute("data-config");""===d&&(d=System.baseURL+"config.json");var c=__$curScript.getAttribute("data-main");System.paths["@traceur"]||(System.paths["@traceur"]="undefined"!=typeof __$curScript&&__$curScript.getAttribute("data-traceur-src")),(d?Promise.resolve(System.fetch.call(System,{address:d,metadata:{}})).then(JSON.parse).then(System.config):Promise.resolve()).then(function(){return c?System["import"](c):void 0})["catch"](function(e){setTimeout(function(){throw e})})};var __$curScript;!function(e){if("undefined"!=typeof window){var t=document.getElementsByTagName("script");if(__$curScript=t[t.length-1],!e.System||e.System.registerModule){var a=__$curScript.src,r=a.substr(0,a.lastIndexOf("/")+1);document.write('')}else e.upgradeSystemLoader()}else{var n=require("es6-module-loader");e.System=n.System,e.Loader=n.Loader,e.Module=n.Module,module.exports=e.System,e.upgradeSystemLoader()}}(__$global)}("undefined"!=typeof window?window:global); \ No newline at end of file +!function(__$global){function __eval(__source,__global,__address,__sourceMap){try{__source="with(__global) { (function() { "+__source+" \n }).call(__global); }\n//# sourceURL="+__address+(__sourceMap?"\n//# sourceMappingURL="+__sourceMap:""),eval(__source)}catch(e){throw"SyntaxError"==e.name&&(e.message="Evaluating "+__address+"\n "+e.message),e}}var indexOf=Array.prototype.indexOf||function(e){for(var t=0,a=this.length;a>t;t++)if(this[t]===e)return t;return-1};__$global.upgradeSystemLoader=function(){function e(e){function t(e){var t=this;"@traceur"==e.name&&(m=System,p=Module);var a,n=e.source.lastIndexOf("\n");-1!=n&&"//# sourceMappingURL="==e.source.substr(n+1,21)&&(a=r(e.address,e.source.substr(n+22))),__eval(e.source,t.global,e.address,a),"@traceur"==e.name&&(t.global.traceurSystem=t.global.System,t.global.System=m)}function a(e){var t=String(e).replace(/^\s+|\s+$/g,"").match(/^([^:\/?#]+:)?(\/\/(?:[^:@]*(?::[^:@]*)?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);return t?{href:t[0]||"",protocol:t[1]||"",authority:t[2]||"",host:t[3]||"",hostname:t[4]||"",port:t[5]||"",pathname:t[6]||"",search:t[7]||"",hash:t[8]||""}:null}function r(e,t){function r(e){var t=[];return e.replace(/^(\.\.?(\/|$))+/,"").replace(/\/(\.(\/|$))+/g,"/").replace(/\/\.\.$/,"/../").replace(/\/?[^\/]*/g,function(e){"/.."===e?t.pop():t.push(e)}),t.join("").replace(/^\//,"/"===e.charAt(0)?"/":"")}return t=a(t||""),e=a(e||""),t&&e?(t.protocol||e.protocol)+(t.protocol||t.authority?t.authority:e.authority)+r(t.protocol||t.authority||"/"===t.pathname.charAt(0)?t.pathname:t.pathname?(e.authority&&!e.pathname?"/":"")+e.pathname.slice(0,e.pathname.lastIndexOf("/")+1)+t.pathname:e.pathname)+(t.protocol||t.authority||t.pathname?t.search:t.search||e.search)+t.hash:null}var n=e["import"];e["import"]=function(e,t){return n.call(this,e,t).then(function(e){return e.__useDefault?e["default"]:e})},e.set("@empty",Module({})),e.config=function(e){for(var t in e){var a=e[t];if("object"==typeof a){this[t]=this[t]||{};for(var r in a)this[t][r]=a[r]}else this[t]=a}};var o;if("undefined"==typeof window)o=__dirname+"/";else if(o=document.baseURI,!o){var i=document.getElementsByTagName("base");o=i[0]&&i[0].href||window.location.href}var s,l=e.locate;e.locate=function(e){return this.baseURL!=s&&(s=r(o,this.baseURL),"/"!=s.substr(s.length-1,1)&&(s+="/"),this.baseURL=s),Promise.resolve(l.call(this,e))};var u=/^\s*export\s*\*\s*from\s*(?:'([^']+)'|"([^"]+)")/,d=/(?:^\s*|[}{\(\);,\n]\s*)(import\s+['"]|(import|module)\s+[^"'\(\)\n;]+\s+from\s+['"]|export\s+(\*|\{|default|function|var|const|let|[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*))/,c=e.translate;e.translate=function(e){var a=this;if(a.__exec=t,"@traceur"==e.name)return c.call(a,e);var r;if(!a.global.traceur&&("es6"==e.metadata.format||!e.metadata.format)&&(r=e.source.match(u))){var n=r[1]||r[2];e.metadata.deps=[n],e.metadata.execute=function(e){return e(n)}}return"es6"!=e.metadata.format&&(e.metadata.format||!e.source.match(d))||(e.metadata.format="es6",a.global.traceur)?c.call(a,e):a["import"]("@traceur").then(function(){return c.call(a,e)})};var f=e.instantiate;e.instantiate=function(e){var t=this;return"@traceur"==e.name?(t.__exec(e),{deps:[],execute:function(){return Module({})}}):f.call(t,e)};var m,p;e.__exec=t}function t(e){function t(e,t){var a=e.meta&&e.meta[t.name];if(a)for(var r in a)t.metadata[r]=t.metadata[r]||a[r]}var a=/^(\s*\/\*.*\*\/|\s*\/\/[^\n]*|\s*"[^"]+"\s*;?|\s*'[^']+'\s*;?)+/,r=/\/\*.*\*\/|\/\/[^\n]*|"[^"]+"\s*;?|'[^']+'\s*;?/g;e.meta={};var n=e.locate;e.locate=function(e){return t(this,e),n.call(this,e)};var o=e.translate;e.translate=function(e){var n=e.source.match(a);if(n)for(var i=n[0].match(r),s=0;s=0;l--){for(var u=n[l],d=0;dr.length)return 0;for(var n=0;nparseInt(n[o])?1:-1}return 0};e.versions=e.versions||{};var r=e.normalize;e.normalize=function(n,o,i){e.versions||(e.versions={});var s=this.versions;return Promise.resolve(r.call(this,n,o,i)).then(function(e){var r,n,o,i,l=e.indexOf("@");if(-1==l){for(var u in s)if(i=s[u],e.substr(0,u.length)==u&&(o=e.substr(u.length,1),!o||"/"==o))return u+"@"+("string"==typeof i?i:i[i.length-1])+e.substr(u.length);return e}r=e.substr(l+1).split("/")[0];var d,c=r.length;if("^"==r.substr(0,1)&&(r=r.substr(1),d=!0),n=r.match(t),!n)return e;d&&(n[2]||(d=!1),n[3]||(n[2]>0?n[3]="0":d=!1)),d&&(n[1]>0?(n[2]||(r=n[1]+".0.0"),n[3]||(r=n[1]+".0"),d=r,n=[n[1]]):n[2]>0?(d=r,n=[0,n[2]]):(d=!1,n=[0,0,n[3]]),r=n.join("."));var f=e.substr(0,l);if(i=s[f]||[],"string"==typeof i&&(i=[i]),!n[3]||d)for(var m=i.length-1;m>=0;m--){var p=i[m];if(p.substr(0,r.length)==r&&p.substr(r.length,1).match(/^[\.\-]?$/)&&(!d||d&&-1!=a(p,d)))return f+"@"+p+e.substr(f.length+c+1)}return-1==indexOf.call(i,r)&&(i.push(r),i.sort(a),e=f+"@"+r+e.substr(f.length+c+1),n[3]&&-1!=(l=indexOf.call(i,n[1]+"."+n[2]))&&i.splice(l,1),n[2]&&-1!=(l=indexOf.call(i,n[1]))&&i.splice(l,1),s[f]=1==i.length?i[0]:i),e})}}__$global.upgradeSystemLoader=void 0,e(System),t(System),a(System),r(System),n(System),o(System),i(System),s(System),l(System),u(System),System.baseURL=__$curScript.getAttribute("data-baseurl")||System.baseURL;var d=__$curScript.getAttribute("data-config");""===d&&(d=System.baseURL+"config.json");var c=__$curScript.getAttribute("data-main");System.paths["@traceur"]||(System.paths["@traceur"]="undefined"!=typeof __$curScript&&__$curScript.getAttribute("data-traceur-src")),(d?Promise.resolve(System.fetch.call(System,{address:d,metadata:{}})).then(JSON.parse).then(System.config):Promise.resolve()).then(function(){return c?System["import"](c):void 0})["catch"](function(e){setTimeout(function(){throw e})})};var __$curScript;!function(e){if("undefined"!=typeof window){var t=document.getElementsByTagName("script");if(__$curScript=t[t.length-1],!e.System||e.System.registerModule){var a=__$curScript.src,r=a.substr(0,a.lastIndexOf("/")+1);document.write('')}else e.upgradeSystemLoader()}else{var n=require("es6-module-loader");e.System=n.System,e.Loader=n.Loader,e.Module=n.Module,module.exports=e.System,e.upgradeSystemLoader()}}(__$global)}("undefined"!=typeof window?window:global); \ No newline at end of file diff --git a/lib/extension-register.js b/lib/extension-register.js index 919ee170..77ab7c96 100644 --- a/lib/extension-register.js +++ b/lib/extension-register.js @@ -83,12 +83,20 @@ function register(loader) { // now we know the entry is in our unlinked linkage group var depGroupIndex = entry.groupIndex + (depEntry.declarative != entry.declarative); - if (depEntry.groupIndex === undefined) { + // the group index of an entry is always the maximum + if (depEntry.groupIndex === undefined || depEntry.groupIndex < depGroupIndex) { + + // if already in a group, remove from the old group + if (depEntry.groupIndex) { + groups[depEntry.groupIndex].splice(groups[depEntry.groupIndex].indexOf(depEntry), 1); + + // if the old group is empty, then we have a mixed depndency cycle + if (groups[depEntry.groupIndex].length == 0) + throw new TypeError("Mixed dependency cycle detected"); + } + depEntry.groupIndex = depGroupIndex; } - else if (depEntry.groupIndex != depGroupIndex) { - throw new TypeError('System.register mixed dependency cycle'); - } buildGroups(depEntry, loader, groups); } @@ -103,7 +111,7 @@ function register(loader) { buildGroups(startEntry, loader, groups); - var curGroupDeclarative = startEntry.declarative == groups.length % 2; + var curGroupDeclarative = !!startEntry.declarative == groups.length % 2; for (var i = groups.length - 1; i >= 0; i--) { var group = groups[i]; for (var j = 0; j < group.length; j++) { @@ -249,8 +257,12 @@ function register(loader) { for (var i = 0; i < entry.normalizedDeps.length; i++) { var depName = entry.normalizedDeps[i]; - if (indexOf.call(seen, depName) == -1) - ensureEvaluated(depName, seen, loader); + if (indexOf.call(seen, depName) == -1) { + if (!loader.defined[depName]) + loader.get(depName); + else + ensureEvaluated(depName, seen, loader); + } } if (entry.evaluated) diff --git a/test/test.js b/test/test.js index 84a1a310..5a751feb 100644 --- a/test/test.js +++ b/test/test.js @@ -361,12 +361,10 @@ asyncTest('System.register Circular', function() { }, err); }); - - -asyncTest('AMD, CJS circular, System.register circular, ES6 circular', function() { +asyncTest('AMD -> System.register circular -> ES6', function() { + System['import']('tests/all-layers1').then(function(m) { + ok(m == true) + start(); + }, err); }); -/* -asyncTest('CJS loading ES6 circular, CJS circular, System.register circular', function() { - -}); */ diff --git a/test/tests/all-layers1.js b/test/tests/all-layers1.js new file mode 100644 index 00000000..21880b15 --- /dev/null +++ b/test/tests/all-layers1.js @@ -0,0 +1,3 @@ +define(['./all-layers2'], function(al2) { + return al2.q == 10 && al2.r == 5; +}); \ No newline at end of file diff --git a/test/tests/all-layers2.js b/test/tests/all-layers2.js new file mode 100644 index 00000000..e5dd5406 --- /dev/null +++ b/test/tests/all-layers2.js @@ -0,0 +1,39 @@ +System.register(["./all-layers3"], function($__0) { + "use strict"; + var q, + r; + function p() { + if (q) + r = $__0[0]["c"]; + else + q = $__0[0]["c"]; + } + return { + exports: { + get q() { + return q; + }, + get r() { + return r; + }, + get p() { + return p; + }, + set q(value) { + q = value; + }, + set r(value) { + r = value; + }, + set p(value) { + p = value; + } + }, + execute: function() { + ; + $__0[0]["c"] = 5; + ; + p(); + } + }; +}); diff --git a/test/tests/all-layers3.js b/test/tests/all-layers3.js new file mode 100644 index 00000000..dd41c2a5 --- /dev/null +++ b/test/tests/all-layers3.js @@ -0,0 +1,19 @@ +System.register(["./all-layers2", "./all-layers4"], function($__0) { + "use strict"; + var c; + return { + exports: { + get c() { + return c; + }, + set c(value) { + c = value; + } + }, + execute: function() { + c = $__0[1]["c"]; + ; + $__0[0]["p"](); + } + }; +}); diff --git a/test/tests/all-layers4.js b/test/tests/all-layers4.js new file mode 100644 index 00000000..4a2d7bf8 --- /dev/null +++ b/test/tests/all-layers4.js @@ -0,0 +1 @@ +export var c = 10; \ No newline at end of file