diff --git a/dist/es6-module-loader.js b/dist/es6-module-loader.js index 98f867e..ad5f9b0 100644 --- a/dist/es6-module-loader.js +++ b/dist/es6-module-loader.js @@ -1,4 +1,4 @@ -/*! es6-module-loader - v0.1.0 - 5/20/2012 +/*! es6-module-loader - v0.1.0 - 5/22/2012 * https://github.com/addyosmani/es6-module-loader * Copyright (c) 2012 Luke Hogan, Addy Osmani; Licensed MIT */ @@ -6,12 +6,12 @@ // new Loader( parent [, options ] ) - Module loader constructor - // The Loader constructor creates a new loader. The first argument is the - // parent loader. The second is an options object + // The Loader constructor creates a new loader. The first argument is the + // parent loader. The second is an options object // - // options.global - The loader’s global object - // options.baseURL - The loader’s base URL - // options.linkedTo - The source of the loader’s intrinsics (not impl) + // options.global - The loader's global object + // options.baseURL - The loader's base URL + // options.linkedTo - The source of the loader's intrinsics (not impl) // options.strict - should code evaluated in the loader be in strict mode? // options.resolve( relURL, baseURL ) - The URL resolution hook // options.fetch( relURL, baseURL, request, resolved ) - The module loading hook @@ -52,11 +52,11 @@ // Loader.prototype.load( url, callback, errback ) - // - // The load method takes a string representing a module URL and a - // callback that receives the result of loading, compiling, and - // executing the module at that URL. The compiled code is statically - // associated with this loader, and its URL is the given URL. The + // + // The load method takes a string representing a module URL and a + // callback that receives the result of loading, compiling, and + // executing the module at that URL. The compiled code is statically + // associated with this loader, and its URL is the given URL. The // additional callback is used if an error occurs. Loader.prototype.load = function (url, callback, errback) { var key = this._resolve(url, this._baseURL); @@ -73,7 +73,7 @@ if (self._strict) { actualSrc = "'use strict';\n" + actualSrc; } - + evalSrc = eval(actualSrc); self.set(url, evalSrc); callback(self._mios[key]); @@ -89,7 +89,7 @@ }; // Loader.prototype.eval( src ) - // The eval method takes a string representing a Program and returns + // The eval method takes a string representing a Program and returns // the result of compiling and executing the program. Loader.prototype.eval = function (sourceText) { with(this._global) { @@ -100,10 +100,10 @@ // Loader.prototype.evalAsync( src, callback, errback ) // - // The evalAsync method takes a string representing a Program and a - // callback that receives the result of compiling and executing the - // program. The compiled code is statically associated with this loader, - // and its URL is the base URL of this loader. The additional callback + // The evalAsync method takes a string representing a Program and a + // callback that receives the result of compiling and executing the + // program. The compiled code is statically associated with this loader, + // and its URL is the base URL of this loader. The additional callback // is used if an error occurs. Loader.prototype.evalAsync = function () { @@ -113,8 +113,8 @@ // Loader.prototype.get( url ) // - // The get method looks up a module in the loader’s module instance table. - // The URL is resolved to a key by calling the loader’s resolve operation. + // The get method looks up a module in the loader's module instance table. + // The URL is resolved to a key by calling the loader's resolve operation. Loader.prototype.get = function (url) { var key = this._resolve(url, this._baseURL); return this._mios[key]; @@ -122,10 +122,10 @@ // Loader.prototype.set( urlOrMods[, mod ] ) - // - // The set method stores a module or set of modules in the loader’s - // module instance table. Each URL is resolved to a key by calling - // the loader’s resolve operation. + // + // The set method stores a module or set of modules in the loader's + // module instance table. Each URL is resolved to a key by calling + // the loader's resolve operation. Loader.prototype.set = function (url, mio) { var key = this._resolve(url, this._baseURL); if (typeof url === "string") { @@ -139,9 +139,9 @@ // Loader.prototype.defineBuiltins( [ obj ] ) // - // The defineBuiltins method takes an object and defines all the built-in - // objects and functions of the ES6 standard library associated with this - // loader’s intrinsics as properties on the object. + // The defineBuiltins method takes an object and defines all the built-in + // objects and functions of the ES6 standard library associated with this + // loader's intrinsics as properties on the object. Loader.prototype.defineBuiltins = function (o) { if (typeof o != "object") throw new Error("Expected object"); for (var globalProp in global) { @@ -152,15 +152,15 @@ function Module(o) { - + if (o === null) throw new TypeError("Expected object"); - var obj = Object(o); + var obj = Object(o); if (obj instanceof Module) { - return obj; + return obj; } else { - var mio = Object.create(null); - + var mio = Object.create(null); + for (var key in obj) { (function (key) { Object.defineProperty(mio, key, { @@ -172,7 +172,7 @@ }); })(key); } - + return mio; } }; @@ -215,5 +215,5 @@ // Export the System object global.System = defaultSystemLoader; - -})(window); \ No newline at end of file + +})(window); diff --git a/dist/es6-module-loader.min.js b/dist/es6-module-loader.min.js index fffce9d..6bfa18f 100644 --- a/dist/es6-module-loader.min.js +++ b/dist/es6-module-loader.min.js @@ -1,4 +1,4 @@ -/*! es6-module-loader - v0.1.0 - 5/20/2012 +/*! es6-module-loader - v0.1.0 - 5/22/2012 * https://github.com/addyosmani/es6-module-loader * Copyright (c) 2012 Luke Hogan, Addy Osmani; Licensed MIT */ -(function(global){function Loader(a,b){this._global=b.global||Object.create(null),this._baseURL=b.baseURL||this.global&&this.global.baseURL;if(b.linkedTo===null||b.linkedTo)throw new Error("Setting 'linkedTo' not yet supported.");this._strict=b.string===undefined?!1:!!b.string,this._resolve=b.resolve||a.resolve,this._fetch=b.fetch||a.fetch,this._translate=b.translate||a.translate,this._mios={}}function Module(a){if(a===null)throw new TypeError("Expected object");var b=Object(a);if(b instanceof Module)return b;var c=Object.create(null);for(var d in b)(function(a){Object.defineProperty(c,a,{configurable:!1,enumerable:!0,get:function(){return b[a]}})})(d);return c}Object.defineProperty(Loader.prototype,"global",{configurable:!0,enumerable:!0,get:function(){return this._global}}),Object.defineProperty(Loader.prototype,"baseURL",{configurable:!0,enumerable:!0,get:function(){return this._baseURL}}),Loader.prototype.load=function(url,callback,errback){var key=this._resolve(url,this._baseURL);if(this._mios[key])callback(this._mios[key]);else{var self=this;this._fetch(url,this._baseURL,{fulfill:function(src){var actualSrc,evalSrc;actualSrc=self._translate(src,url,self._baseURL,key),self._strict&&(actualSrc="'use strict';\n"+actualSrc),evalSrc=eval(actualSrc),self.set(url,evalSrc),callback(self._mios[key])},redirect:function(a,b){throw new Error("'redirect' not yet implemented")},reject:function(a){errback(a)}},key)}},Loader.prototype.eval=function(sourceText){with(this._global)eval(sourceText)},Loader.prototype.evalAsync=function(){throw new Error("'evalAsync' is not yet implemented. Its not required until module syntax is natively available.")},Loader.prototype.get=function(a){var b=this._resolve(a,this._baseURL);return this._mios[b]},Loader.prototype.set=function(a,b){var c=this._resolve(a,this._baseURL);if(typeof a=="string")this._mios[c]=Module(b);else for(var d in c)this._mios[d]=Module(c[d])},Loader.prototype.defineBuiltins=function(a){if(typeof a!="object")throw new Error("Expected object");for(var b in global)a[b]=global;return a};var defaultSystemLoader=new Loader(null,{global:window,baseURL:document.URL.substring(0,document.URL.lastIndexOf("/")+1),strict:!1,resolve:function(a,b){var c=b+a;return c},fetch:function(a,b,c,d){var e=b+a,f=new XMLHttpRequest;f.onreadystatechange=function(){f.readyState===4&&(f.status===200?c.fulfill(f.responseText):c.reject(f.statusText))},f.open("GET",e,!0),f.send(null)},translate:function(a,b,c,d){return a}});global.Loader=Loader,global.Module=Module,global.System=defaultSystemLoader})(window) \ No newline at end of file +(function(global){function Loader(a,b){this._global=b.global||Object.create(null),this._baseURL=b.baseURL||this.global&&this.global.baseURL;if(b.linkedTo===null||b.linkedTo)throw new Error("Setting 'linkedTo' not yet supported.");this._strict=b.string===undefined?!1:!!b.string,this._resolve=b.resolve||a.resolve,this._fetch=b.fetch||a.fetch,this._translate=b.translate||a.translate,this._mios={}}function Module(a){if(a===null)throw new TypeError("Expected object");var b=Object(a);if(b instanceof Module)return b;var c=Object.create(null);for(var d in b)(function(a){Object.defineProperty(c,a,{configurable:!1,enumerable:!0,get:function(){return b[a]}})})(d);return c}Object.defineProperty(Loader.prototype,"global",{configurable:!0,enumerable:!0,get:function(){return this._global}}),Object.defineProperty(Loader.prototype,"baseURL",{configurable:!0,enumerable:!0,get:function(){return this._baseURL}}),Loader.prototype.load=function(url,callback,errback){var key=this._resolve(url,this._baseURL);if(this._mios[key])callback(this._mios[key]);else{var self=this;this._fetch(url,this._baseURL,{fulfill:function(src){var actualSrc,evalSrc;actualSrc=self._translate(src,url,self._baseURL,key),self._strict&&(actualSrc="'use strict';\n"+actualSrc),evalSrc=eval(actualSrc),self.set(url,evalSrc),callback(self._mios[key])},redirect:function(a,b){throw new Error("'redirect' not yet implemented")},reject:function(a){errback(a)}},key)}},Loader.prototype.eval=function(sourceText){with(this._global)eval(sourceText)},Loader.prototype.evalAsync=function(){throw new Error("'evalAsync' is not yet implemented. Its not required until module syntax is natively available.")},Loader.prototype.get=function(a){var b=this._resolve(a,this._baseURL);return this._mios[b]},Loader.prototype.set=function(a,b){var c=this._resolve(a,this._baseURL);if(typeof a=="string")this._mios[c]=Module(b);else for(var d in c)this._mios[d]=Module(c[d])},Loader.prototype.defineBuiltins=function(a){if(typeof a!="object")throw new Error("Expected object");for(var b in global)a[b]=global;return a};var defaultSystemLoader=new Loader(null,{global:window,baseURL:document.URL.substring(0,document.URL.lastIndexOf("/")+1),strict:!1,resolve:function(a,b){var c=b+a;return c},fetch:function(a,b,c,d){var e=b+a,f=new XMLHttpRequest;f.onreadystatechange=function(){f.readyState===4&&(f.status===200?c.fulfill(f.responseText):c.reject(f.statusText))},f.open("GET",e,!0),f.send(null)},translate:function(a,b,c,d){return a}});global.Loader=Loader,global.Module=Module,global.System=defaultSystemLoader})(window); \ No newline at end of file diff --git a/lib/es6-module-loader.js b/lib/es6-module-loader.js index 20ff9bd..6a5d5e5 100644 --- a/lib/es6-module-loader.js +++ b/lib/es6-module-loader.js @@ -10,12 +10,12 @@ // new Loader( parent [, options ] ) - Module loader constructor - // The Loader constructor creates a new loader. The first argument is the - // parent loader. The second is an options object + // The Loader constructor creates a new loader. The first argument is the + // parent loader. The second is an options object // - // options.global - The loader’s global object - // options.baseURL - The loader’s base URL - // options.linkedTo - The source of the loader’s intrinsics (not impl) + // options.global - The loader's global object + // options.baseURL - The loader's base URL + // options.linkedTo - The source of the loader's intrinsics (not impl) // options.strict - should code evaluated in the loader be in strict mode? // options.resolve( relURL, baseURL ) - The URL resolution hook // options.fetch( relURL, baseURL, request, resolved ) - The module loading hook @@ -56,11 +56,11 @@ // Loader.prototype.load( url, callback, errback ) - // - // The load method takes a string representing a module URL and a - // callback that receives the result of loading, compiling, and - // executing the module at that URL. The compiled code is statically - // associated with this loader, and its URL is the given URL. The + // + // The load method takes a string representing a module URL and a + // callback that receives the result of loading, compiling, and + // executing the module at that URL. The compiled code is statically + // associated with this loader, and its URL is the given URL. The // additional callback is used if an error occurs. Loader.prototype.load = function (url, callback, errback) { var key = this._resolve(url, this._baseURL); @@ -77,7 +77,7 @@ if (self._strict) { actualSrc = "'use strict';\n" + actualSrc; } - + evalSrc = eval(actualSrc); self.set(url, evalSrc); callback(self._mios[key]); @@ -93,7 +93,7 @@ }; // Loader.prototype.eval( src ) - // The eval method takes a string representing a Program and returns + // The eval method takes a string representing a Program and returns // the result of compiling and executing the program. Loader.prototype.eval = function (sourceText) { with(this._global) { @@ -104,10 +104,10 @@ // Loader.prototype.evalAsync( src, callback, errback ) // - // The evalAsync method takes a string representing a Program and a - // callback that receives the result of compiling and executing the - // program. The compiled code is statically associated with this loader, - // and its URL is the base URL of this loader. The additional callback + // The evalAsync method takes a string representing a Program and a + // callback that receives the result of compiling and executing the + // program. The compiled code is statically associated with this loader, + // and its URL is the base URL of this loader. The additional callback // is used if an error occurs. Loader.prototype.evalAsync = function () { @@ -117,8 +117,8 @@ // Loader.prototype.get( url ) // - // The get method looks up a module in the loader’s module instance table. - // The URL is resolved to a key by calling the loader’s resolve operation. + // The get method looks up a module in the loader's module instance table. + // The URL is resolved to a key by calling the loader's resolve operation. Loader.prototype.get = function (url) { var key = this._resolve(url, this._baseURL); return this._mios[key]; @@ -126,10 +126,10 @@ // Loader.prototype.set( urlOrMods[, mod ] ) - // - // The set method stores a module or set of modules in the loader’s - // module instance table. Each URL is resolved to a key by calling - // the loader’s resolve operation. + // + // The set method stores a module or set of modules in the loader's + // module instance table. Each URL is resolved to a key by calling + // the loader's resolve operation. Loader.prototype.set = function (url, mio) { var key = this._resolve(url, this._baseURL); if (typeof url === "string") { @@ -143,9 +143,9 @@ // Loader.prototype.defineBuiltins( [ obj ] ) // - // The defineBuiltins method takes an object and defines all the built-in - // objects and functions of the ES6 standard library associated with this - // loader’s intrinsics as properties on the object. + // The defineBuiltins method takes an object and defines all the built-in + // objects and functions of the ES6 standard library associated with this + // loader's intrinsics as properties on the object. Loader.prototype.defineBuiltins = function (o) { if (typeof o != "object") throw new Error("Expected object"); for (var globalProp in global) { @@ -156,15 +156,15 @@ function Module(o) { - + if (o === null) throw new TypeError("Expected object"); - var obj = Object(o); + var obj = Object(o); if (obj instanceof Module) { - return obj; + return obj; } else { - var mio = Object.create(null); - + var mio = Object.create(null); + for (var key in obj) { (function (key) { Object.defineProperty(mio, key, { @@ -176,7 +176,7 @@ }); })(key); } - + return mio; } }; @@ -219,5 +219,5 @@ // Export the System object global.System = defaultSystemLoader; - -})(window); \ No newline at end of file + +})(window);