Permalink
Browse files

Merge pull request #2 from paulirish/master

improve debugability with @ sourceURL
  • Loading branch information...
2 parents 985525d + 16c8d1f commit a619c02beac04df14c5e80f8a15c74aef911f5a6 @addyosmani addyosmani committed May 23, 2012
Showing with 72 additions and 69 deletions.
  1. +34 −34 dist/es6-module-loader.js
  2. +2 −2 dist/es6-module-loader.min.js
  3. +36 −33 lib/es6-module-loader.js
View
@@ -1,17 +1,17 @@
-/*! 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) {
// 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 loaders global object
- // options.baseURL - The loaders base URL
- // options.linkedTo - The source of the loaders 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,19 +113,19 @@
// Loader.prototype.get( url )
//
- // The get method looks up a module in the loaders module instance table.
- // The URL is resolved to a key by calling the loaders 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];
};
// 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 loaders 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
- // loaders 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);
+
+})(window);

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -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 loaders global object
- // options.baseURL - The loaders base URL
- // options.linkedTo - The source of the loaders 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,10 @@
if (self._strict) {
actualSrc = "'use strict';\n" + actualSrc;
}
-
+
+ // add sourceURL so these are treated as script files in a debugger
+ actualSrc += '\n//@ sourceURL=' + self._baseURL + url;
+
evalSrc = eval(actualSrc);
self.set(url, evalSrc);
callback(self._mios[key]);
@@ -93,7 +96,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 +107,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,19 +120,19 @@
// Loader.prototype.get( url )
//
- // The get method looks up a module in the loaders module instance table.
- // The URL is resolved to a key by calling the loaders 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];
};
// 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 loaders 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 +146,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
- // loaders 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 +159,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 +179,7 @@
});
})(key);
}
-
+
return mio;
}
};
@@ -219,5 +222,5 @@
// Export the System object
global.System = defaultSystemLoader;
-
-})(window);
+
+})(window);

0 comments on commit a619c02

Please sign in to comment.