Skip to content
This repository
Browse code

Merge pull request #2 from paulirish/master

improve debugability with @ sourceURL
  • Loading branch information...
commit a619c02beac04df14c5e80f8a15c74aef911f5a6 2 parents 985525d + 16c8d1f
Addy Osmani authored May 23, 2012
68  dist/es6-module-loader.js
... ...
@@ -1,4 +1,4 @@
1  
-/*! es6-module-loader - v0.1.0 - 5/20/2012
  1
+/*! es6-module-loader - v0.1.0 - 5/22/2012
2 2
 * https://github.com/addyosmani/es6-module-loader
3 3
 * Copyright (c) 2012 Luke Hogan, Addy Osmani; Licensed MIT */
4 4
 
@@ -6,12 +6,12 @@
6 6
 
7 7
 
8 8
   // new Loader( parent [, options ] ) - Module loader constructor
9  
-  // The Loader constructor creates a new loader. The first argument is the 
10  
-  // parent loader. The second is an options object 
  9
+  // The Loader constructor creates a new loader. The first argument is the
  10
+  // parent loader. The second is an options object
11 11
   //
12  
-  // options.global - The loader’s global object
13  
-  // options.baseURL - The loader’s base URL
14  
-  // options.linkedTo - The source of the loader’s intrinsics (not impl)
  12
+  // options.global - The loader's global object
  13
+  // options.baseURL - The loader's base URL
  14
+  // options.linkedTo - The source of the loader's intrinsics (not impl)
15 15
   // options.strict -  should code evaluated in the loader be in strict mode?
16 16
   // options.resolve( relURL, baseURL ) - The URL resolution hook
17 17
   // options.fetch( relURL, baseURL, request, resolved ) - The module loading hook
@@ -52,11 +52,11 @@
52 52
 
53 53
 
54 54
   // Loader.prototype.load( url, callback, errback )
55  
-  // 
56  
-  // The load method takes a string representing a module URL and a 
57  
-  // callback that receives the result of loading, compiling, and 
58  
-  // executing the module at that URL. The compiled code is statically 
59  
-  // associated with this loader, and its URL is the given URL. The 
  55
+  //
  56
+  // The load method takes a string representing a module URL and a
  57
+  // callback that receives the result of loading, compiling, and
  58
+  // executing the module at that URL. The compiled code is statically
  59
+  // associated with this loader, and its URL is the given URL. The
60 60
   // additional callback is used if an error occurs.
61 61
   Loader.prototype.load = function (url, callback, errback) {
62 62
     var key = this._resolve(url, this._baseURL);
@@ -73,7 +73,7 @@
73 73
           if (self._strict) {
74 74
             actualSrc = "'use strict';\n" + actualSrc;
75 75
           }
76  
-        
  76
+
77 77
           evalSrc = eval(actualSrc);
78 78
           self.set(url, evalSrc);
79 79
           callback(self._mios[key]);
@@ -89,7 +89,7 @@
89 89
   };
90 90
 
91 91
   // Loader.prototype.eval( src )
92  
-  // The eval method takes a string representing a Program and returns 
  92
+  // The eval method takes a string representing a Program and returns
93 93
   // the result of compiling and executing the program.
94 94
   Loader.prototype.eval = function (sourceText) {
95 95
     with(this._global) {
@@ -100,10 +100,10 @@
100 100
 
101 101
   // Loader.prototype.evalAsync( src, callback, errback )
102 102
   //
103  
-  // The evalAsync method takes a string representing a Program and a 
104  
-  // callback that receives the result of compiling and executing the 
105  
-  // program. The compiled code is statically associated with this loader, 
106  
-  // and its URL is the base URL of this loader. The additional callback 
  103
+  // The evalAsync method takes a string representing a Program and a
  104
+  // callback that receives the result of compiling and executing the
  105
+  // program. The compiled code is statically associated with this loader,
  106
+  // and its URL is the base URL of this loader. The additional callback
107 107
   // is used if an error occurs.
108 108
 
109 109
   Loader.prototype.evalAsync = function () {
@@ -113,8 +113,8 @@
113 113
 
114 114
   // Loader.prototype.get( url )
115 115
   //
116  
-  // The get method looks up a module in the loader’s module instance table. 
117  
-  // The URL is resolved to a key by calling the loader’s resolve operation.
  116
+  // The get method looks up a module in the loader's module instance table.
  117
+  // The URL is resolved to a key by calling the loader's resolve operation.
118 118
   Loader.prototype.get = function (url) {
119 119
     var key = this._resolve(url, this._baseURL);
120 120
     return this._mios[key];
@@ -122,10 +122,10 @@
122 122
 
123 123
 
124 124
   // Loader.prototype.set( urlOrMods[, mod ] )
125  
-  // 
126  
-  // The set method stores a module or set of modules in the loader’s 
127  
-  // module instance table. Each URL is resolved to a key by calling 
128  
-  // the loader’s resolve operation.
  125
+  //
  126
+  // The set method stores a module or set of modules in the loader's
  127
+  // module instance table. Each URL is resolved to a key by calling
  128
+  // the loader's resolve operation.
129 129
   Loader.prototype.set = function (url, mio) {
130 130
     var key = this._resolve(url, this._baseURL);
131 131
     if (typeof url === "string") {
@@ -139,9 +139,9 @@
139 139
 
140 140
   // Loader.prototype.defineBuiltins( [ obj ] )
141 141
   //
142  
-  // The defineBuiltins method takes an object and defines all the built-in 
143  
-  // objects and functions of the ES6 standard library associated with this 
144  
-  // loader’s intrinsics as properties on the object.
  142
+  // The defineBuiltins method takes an object and defines all the built-in
  143
+  // objects and functions of the ES6 standard library associated with this
  144
+  // loader's intrinsics as properties on the object.
145 145
   Loader.prototype.defineBuiltins = function (o) {
146 146
     if (typeof o != "object") throw new Error("Expected object");
147 147
     for (var globalProp in global) {
@@ -152,15 +152,15 @@
152 152
 
153 153
 
154 154
   function Module(o) {
155  
-    
  155
+
156 156
     if (o === null) throw new TypeError("Expected object");
157  
-    var obj = Object(o);  
  157
+    var obj = Object(o);
158 158
     if (obj instanceof Module) {
159  
-      return obj; 
  159
+      return obj;
160 160
     } else {
161 161
 
162  
-      var mio = Object.create(null); 
163  
-    
  162
+      var mio = Object.create(null);
  163
+
164 164
       for (var key in obj) {
165 165
         (function (key) {
166 166
           Object.defineProperty(mio, key, {
@@ -172,7 +172,7 @@
172 172
           });
173 173
         })(key);
174 174
       }
175  
-      
  175
+
176 176
       return mio;
177 177
     }
178 178
   };
@@ -215,5 +215,5 @@
215 215
   // Export the System object
216 216
   global.System = defaultSystemLoader;
217 217
 
218  
-  
219  
-})(window);
  218
+
  219
+})(window);
4  dist/es6-module-loader.min.js
... ...
@@ -1,4 +1,4 @@
1  
-/*! es6-module-loader - v0.1.0 - 5/20/2012
  1
+/*! es6-module-loader - v0.1.0 - 5/22/2012
2 2
 * https://github.com/addyosmani/es6-module-loader
3 3
 * Copyright (c) 2012 Luke Hogan, Addy Osmani; Licensed MIT */
4  
-(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)
  4
+(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);
69  lib/es6-module-loader.js
@@ -10,12 +10,12 @@
10 10
 
11 11
 
12 12
   // new Loader( parent [, options ] ) - Module loader constructor
13  
-  // The Loader constructor creates a new loader. The first argument is the 
14  
-  // parent loader. The second is an options object 
  13
+  // The Loader constructor creates a new loader. The first argument is the
  14
+  // parent loader. The second is an options object
15 15
   //
16  
-  // options.global - The loader’s global object
17  
-  // options.baseURL - The loader’s base URL
18  
-  // options.linkedTo - The source of the loader’s intrinsics (not impl)
  16
+  // options.global - The loader's global object
  17
+  // options.baseURL - The loader's base URL
  18
+  // options.linkedTo - The source of the loader's intrinsics (not impl)
19 19
   // options.strict -  should code evaluated in the loader be in strict mode?
20 20
   // options.resolve( relURL, baseURL ) - The URL resolution hook
21 21
   // options.fetch( relURL, baseURL, request, resolved ) - The module loading hook
@@ -56,11 +56,11 @@
56 56
 
57 57
 
58 58
   // Loader.prototype.load( url, callback, errback )
59  
-  // 
60  
-  // The load method takes a string representing a module URL and a 
61  
-  // callback that receives the result of loading, compiling, and 
62  
-  // executing the module at that URL. The compiled code is statically 
63  
-  // associated with this loader, and its URL is the given URL. The 
  59
+  //
  60
+  // The load method takes a string representing a module URL and a
  61
+  // callback that receives the result of loading, compiling, and
  62
+  // executing the module at that URL. The compiled code is statically
  63
+  // associated with this loader, and its URL is the given URL. The
64 64
   // additional callback is used if an error occurs.
65 65
   Loader.prototype.load = function (url, callback, errback) {
66 66
     var key = this._resolve(url, this._baseURL);
@@ -77,7 +77,10 @@
77 77
           if (self._strict) {
78 78
             actualSrc = "'use strict';\n" + actualSrc;
79 79
           }
80  
-        
  80
+
  81
+          // add sourceURL so these are treated as script files in a debugger
  82
+          actualSrc += '\n//@ sourceURL=' + self._baseURL + url;
  83
+
81 84
           evalSrc = eval(actualSrc);
82 85
           self.set(url, evalSrc);
83 86
           callback(self._mios[key]);
@@ -93,7 +96,7 @@
93 96
   };
94 97
 
95 98
   // Loader.prototype.eval( src )
96  
-  // The eval method takes a string representing a Program and returns 
  99
+  // The eval method takes a string representing a Program and returns
97 100
   // the result of compiling and executing the program.
98 101
   Loader.prototype.eval = function (sourceText) {
99 102
     with(this._global) {
@@ -104,10 +107,10 @@
104 107
 
105 108
   // Loader.prototype.evalAsync( src, callback, errback )
106 109
   //
107  
-  // The evalAsync method takes a string representing a Program and a 
108  
-  // callback that receives the result of compiling and executing the 
109  
-  // program. The compiled code is statically associated with this loader, 
110  
-  // and its URL is the base URL of this loader. The additional callback 
  110
+  // The evalAsync method takes a string representing a Program and a
  111
+  // callback that receives the result of compiling and executing the
  112
+  // program. The compiled code is statically associated with this loader,
  113
+  // and its URL is the base URL of this loader. The additional callback
111 114
   // is used if an error occurs.
112 115
 
113 116
   Loader.prototype.evalAsync = function () {
@@ -117,8 +120,8 @@
117 120
 
118 121
   // Loader.prototype.get( url )
119 122
   //
120  
-  // The get method looks up a module in the loader’s module instance table. 
121  
-  // The URL is resolved to a key by calling the loader’s resolve operation.
  123
+  // The get method looks up a module in the loader's module instance table.
  124
+  // The URL is resolved to a key by calling the loader's resolve operation.
122 125
   Loader.prototype.get = function (url) {
123 126
     var key = this._resolve(url, this._baseURL);
124 127
     return this._mios[key];
@@ -126,10 +129,10 @@
126 129
 
127 130
 
128 131
   // Loader.prototype.set( urlOrMods[, mod ] )
129  
-  // 
130  
-  // The set method stores a module or set of modules in the loader’s 
131  
-  // module instance table. Each URL is resolved to a key by calling 
132  
-  // the loader’s resolve operation.
  132
+  //
  133
+  // The set method stores a module or set of modules in the loader's
  134
+  // module instance table. Each URL is resolved to a key by calling
  135
+  // the loader's resolve operation.
133 136
   Loader.prototype.set = function (url, mio) {
134 137
     var key = this._resolve(url, this._baseURL);
135 138
     if (typeof url === "string") {
@@ -143,9 +146,9 @@
143 146
 
144 147
   // Loader.prototype.defineBuiltins( [ obj ] )
145 148
   //
146  
-  // The defineBuiltins method takes an object and defines all the built-in 
147  
-  // objects and functions of the ES6 standard library associated with this 
148  
-  // loader’s intrinsics as properties on the object.
  149
+  // The defineBuiltins method takes an object and defines all the built-in
  150
+  // objects and functions of the ES6 standard library associated with this
  151
+  // loader's intrinsics as properties on the object.
149 152
   Loader.prototype.defineBuiltins = function (o) {
150 153
     if (typeof o != "object") throw new Error("Expected object");
151 154
     for (var globalProp in global) {
@@ -156,15 +159,15 @@
156 159
 
157 160
 
158 161
   function Module(o) {
159  
-    
  162
+
160 163
     if (o === null) throw new TypeError("Expected object");
161  
-    var obj = Object(o);  
  164
+    var obj = Object(o);
162 165
     if (obj instanceof Module) {
163  
-      return obj; 
  166
+      return obj;
164 167
     } else {
165 168
 
166  
-      var mio = Object.create(null); 
167  
-    
  169
+      var mio = Object.create(null);
  170
+
168 171
       for (var key in obj) {
169 172
         (function (key) {
170 173
           Object.defineProperty(mio, key, {
@@ -176,7 +179,7 @@
176 179
           });
177 180
         })(key);
178 181
       }
179  
-      
  182
+
180 183
       return mio;
181 184
     }
182 185
   };
@@ -219,5 +222,5 @@
219 222
   // Export the System object
220 223
   global.System = defaultSystemLoader;
221 224
 
222  
-  
223  
-})(window);
  225
+
  226
+})(window);

0 notes on commit a619c02

Please sign in to comment.
Something went wrong with that request. Please try again.