From 37e37c302f20926bd0ed9edb9f15ab6ad761568f Mon Sep 17 00:00:00 2001 From: guybedford Date: Mon, 5 May 2014 15:50:52 -0700 Subject: [PATCH] nodejs test completion --- dist/system-production-amd.js | 57 ++++++++++++++++++------------- dist/system-production-amd.min.js | 2 +- dist/system.js | 57 ++++++++++++++++++------------- dist/system.min.js | 2 +- lib/extension-core.js | 3 +- lib/extension-register.js | 13 +++++-- lib/polyfill-wrapper-end.js | 41 +++++++++++----------- test/test.js | 3 +- 8 files changed, 105 insertions(+), 73 deletions(-) diff --git a/dist/system-production-amd.js b/dist/system-production-amd.js index c4a56fc4..002931ff 100644 --- a/dist/system-production-amd.js +++ b/dist/system-production-amd.js @@ -82,7 +82,7 @@ function core(loader) { // override locate to allow baseURL to be document-relative var baseURI; if (typeof window == 'undefined') { - baseURI = __dirname + '/'; + baseURI = process.cwd() + '/'; } else { baseURI = document.baseURI; @@ -99,7 +99,6 @@ function core(loader) { if (normalizedBaseURL.substr(normalizedBaseURL.length - 1, 1) != '/') normalizedBaseURL += '/'; - this.baseURL = normalizedBaseURL; } @@ -288,7 +287,7 @@ function register(loader) { lastRegister = { deps: deps, declare: declare, - declarative: true + declarative: true, }; if (name) @@ -454,6 +453,15 @@ function register(loader) { } } + // lookup the module name if it is in the registry + var moduleName; + for (var d in loader.defined) { + if (loader.defined[d] != entry) + continue; + moduleName = d; + break; + } + // now execute try { entry.evaluated = true; @@ -463,7 +471,7 @@ function register(loader) { continue; return getModule(entry.normalizedDeps[i], loader); } - }, entry.module, name); + }, entry.module, moduleName); } catch(e) { throw e; @@ -1024,30 +1032,33 @@ scriptLoader(System); map(System); bundles(System); versions(System); - System.baseURL = __$curScript.getAttribute('data-baseurl') || System.baseURL; + + if (__$curScript) { + System.baseURL = __$curScript.getAttribute('data-baseurl') || System.baseURL; - var configPath = __$curScript.getAttribute('data-config'); - if (configPath === '') - configPath = System.baseURL + 'config.json'; + var configPath = __$curScript.getAttribute('data-config'); + if (configPath === '') + configPath = System.baseURL + 'config.json'; - var main = __$curScript.getAttribute('data-main'); + var main = __$curScript.getAttribute('data-main'); - if (!System.paths['@traceur']) - System.paths['@traceur'] = typeof __$curScript != 'undefined' && __$curScript.getAttribute('data-traceur-src'); + if (!System.paths['@traceur']) + System.paths['@traceur'] = typeof __$curScript != 'undefined' && __$curScript.getAttribute('data-traceur-src'); - (!configPath ? Promise.resolve() : - Promise.resolve(System.fetch.call(System, { address: configPath, metadata: {} })) - .then(JSON.parse) - .then(System.config) - ).then(function() { - if (main) - return System['import'](main); - }) - ['catch'](function(e) { - setTimeout(function() { - throw e; + (!configPath ? Promise.resolve() : + Promise.resolve(System.fetch.call(System, { address: configPath, metadata: {} })) + .then(JSON.parse) + .then(System.config) + ).then(function() { + if (main) + return System['import'](main); }) - }); + ['catch'](function(e) { + setTimeout(function() { + throw e; + }) + }); + } }; diff --git a/dist/system-production-amd.min.js b/dist/system-production-amd.min.js index 29639fbe..5921378f 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,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 +!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&&(p=System,m=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=p)}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 i;if("undefined"==typeof window)i=process.cwd()+"/";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=n(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 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 p,m;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[i])?1:-1}return 0};e.versions=e.versions||{};var n=e.normalize;e.normalize=function(a,i,o){e.versions||(e.versions={});var s=this.versions;return Promise.resolve(n.call(this,a,i,o)).then(function(e){var n,a,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}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(o=s[f]||[],"string"==typeof o&&(o=[o]),!a[3]||l)for(var p=o.length-1;p>=0;p--){var m=o[p];if(m.substr(0,n.length)==n&&m.substr(n.length,1).match(/^[\.\-]?$/)&&(!l||l&&-1!=r(m,l)))return f+"@"+m+e.substr(f.length+c+1)}return-1==indexOf.call(o,n)&&(o.push(n),o.sort(r),e=f+"@"+n+e.substr(f.length+c+1),a[3]&&-1!=(u=indexOf.call(o,a[1]+"."+a[2]))&&o.splice(u,1),a[2]&&-1!=(u=indexOf.call(o,a[1]))&&o.splice(u,1),s[f]=1==o.length?o[0]:o),e})}}if(__$global.upgradeSystemLoader=void 0,e(System),t(System),r(System),n(System),a(System),i(System),__$curScript){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,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 ccb6183c..ae3fc348 100644 --- a/dist/system.js +++ b/dist/system.js @@ -82,7 +82,7 @@ function core(loader) { // override locate to allow baseURL to be document-relative var baseURI; if (typeof window == 'undefined') { - baseURI = __dirname + '/'; + baseURI = process.cwd() + '/'; } else { baseURI = document.baseURI; @@ -99,7 +99,6 @@ function core(loader) { if (normalizedBaseURL.substr(normalizedBaseURL.length - 1, 1) != '/') normalizedBaseURL += '/'; - this.baseURL = normalizedBaseURL; } @@ -381,7 +380,7 @@ function register(loader) { lastRegister = { deps: deps, declare: declare, - declarative: true + declarative: true, }; if (name) @@ -547,6 +546,15 @@ function register(loader) { } } + // lookup the module name if it is in the registry + var moduleName; + for (var d in loader.defined) { + if (loader.defined[d] != entry) + continue; + moduleName = d; + break; + } + // now execute try { entry.evaluated = true; @@ -556,7 +564,7 @@ function register(loader) { continue; return getModule(entry.normalizedDeps[i], loader); } - }, entry.module, name); + }, entry.module, moduleName); } catch(e) { throw e; @@ -1585,30 +1593,33 @@ map(System); plugins(System); bundles(System); versions(System); - System.baseURL = __$curScript.getAttribute('data-baseurl') || System.baseURL; + + if (__$curScript) { + System.baseURL = __$curScript.getAttribute('data-baseurl') || System.baseURL; - var configPath = __$curScript.getAttribute('data-config'); - if (configPath === '') - configPath = System.baseURL + 'config.json'; + var configPath = __$curScript.getAttribute('data-config'); + if (configPath === '') + configPath = System.baseURL + 'config.json'; - var main = __$curScript.getAttribute('data-main'); + var main = __$curScript.getAttribute('data-main'); - if (!System.paths['@traceur']) - System.paths['@traceur'] = typeof __$curScript != 'undefined' && __$curScript.getAttribute('data-traceur-src'); + if (!System.paths['@traceur']) + System.paths['@traceur'] = typeof __$curScript != 'undefined' && __$curScript.getAttribute('data-traceur-src'); - (!configPath ? Promise.resolve() : - Promise.resolve(System.fetch.call(System, { address: configPath, metadata: {} })) - .then(JSON.parse) - .then(System.config) - ).then(function() { - if (main) - return System['import'](main); - }) - ['catch'](function(e) { - setTimeout(function() { - throw e; + (!configPath ? Promise.resolve() : + Promise.resolve(System.fetch.call(System, { address: configPath, metadata: {} })) + .then(JSON.parse) + .then(System.config) + ).then(function() { + if (main) + return System['import'](main); }) - }); + ['catch'](function(e) { + setTimeout(function() { + throw e; + }) + }); + } }; diff --git a/dist/system.min.js b/dist/system.min.js index c04b43ac..ee863529 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=process.cwd()+"/";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})}}if(__$global.upgradeSystemLoader=void 0,e(System),t(System),a(System),r(System),n(System),o(System),i(System),s(System),l(System),u(System),__$curScript){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-core.js b/lib/extension-core.js index c9fcf8ba..72ae6f3f 100644 --- a/lib/extension-core.js +++ b/lib/extension-core.js @@ -64,7 +64,7 @@ function core(loader) { // override locate to allow baseURL to be document-relative var baseURI; if (typeof window == 'undefined') { - baseURI = __dirname + '/'; + baseURI = process.cwd() + '/'; } else { baseURI = document.baseURI; @@ -81,7 +81,6 @@ function core(loader) { if (normalizedBaseURL.substr(normalizedBaseURL.length - 1, 1) != '/') normalizedBaseURL += '/'; - this.baseURL = normalizedBaseURL; } diff --git a/lib/extension-register.js b/lib/extension-register.js index 77ab7c96..0ae5cc15 100644 --- a/lib/extension-register.js +++ b/lib/extension-register.js @@ -55,7 +55,7 @@ function register(loader) { lastRegister = { deps: deps, declare: declare, - declarative: true + declarative: true, }; if (name) @@ -221,6 +221,15 @@ function register(loader) { } } + // lookup the module name if it is in the registry + var moduleName; + for (var d in loader.defined) { + if (loader.defined[d] != entry) + continue; + moduleName = d; + break; + } + // now execute try { entry.evaluated = true; @@ -230,7 +239,7 @@ function register(loader) { continue; return getModule(entry.normalizedDeps[i], loader); } - }, entry.module, name); + }, entry.module, moduleName); } catch(e) { throw e; diff --git a/lib/polyfill-wrapper-end.js b/lib/polyfill-wrapper-end.js index 567f3bb5..297695e9 100644 --- a/lib/polyfill-wrapper-end.js +++ b/lib/polyfill-wrapper-end.js @@ -1,27 +1,30 @@ - System.baseURL = __$curScript.getAttribute('data-baseurl') || System.baseURL; + + if (__$curScript) { + System.baseURL = __$curScript.getAttribute('data-baseurl') || System.baseURL; - var configPath = __$curScript.getAttribute('data-config'); - if (configPath === '') - configPath = System.baseURL + 'config.json'; + var configPath = __$curScript.getAttribute('data-config'); + if (configPath === '') + configPath = System.baseURL + 'config.json'; - var main = __$curScript.getAttribute('data-main'); + var main = __$curScript.getAttribute('data-main'); - if (!System.paths['@traceur']) - System.paths['@traceur'] = typeof __$curScript != 'undefined' && __$curScript.getAttribute('data-traceur-src'); + if (!System.paths['@traceur']) + System.paths['@traceur'] = typeof __$curScript != 'undefined' && __$curScript.getAttribute('data-traceur-src'); - (!configPath ? Promise.resolve() : - Promise.resolve(System.fetch.call(System, { address: configPath, metadata: {} })) - .then(JSON.parse) - .then(System.config) - ).then(function() { - if (main) - return System['import'](main); - }) - ['catch'](function(e) { - setTimeout(function() { - throw e; + (!configPath ? Promise.resolve() : + Promise.resolve(System.fetch.call(System, { address: configPath, metadata: {} })) + .then(JSON.parse) + .then(System.config) + ).then(function() { + if (main) + return System['import'](main); }) - }); + ['catch'](function(e) { + setTimeout(function() { + throw e; + }) + }); + } }; diff --git a/test/test.js b/test/test.js index 5a751feb..f9aa5822 100644 --- a/test/test.js +++ b/test/test.js @@ -5,8 +5,7 @@ QUnit.config.testTimeout = 2000; QUnit.module("SystemJS"); if (typeof window == 'undefined') { - var path = require('path'); - System.baseURL = path.resolve(__dirname, 'test'); + System.baseURL = 'test'; } function err(e) {