Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit c08dc75

Browse files
committed
v0.17.11
1 parent 0094358 commit c08dc75

7 files changed

+63
-77
lines changed

dist/es6-module-loader-dev.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/es6-module-loader-dev.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/es6-module-loader-dev.src.js

+28-35
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ function URLPolyfill(url, baseURL) {
44
if (typeof url != 'string')
55
throw new TypeError('URL must be a string');
66
var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@\/?#]*)(?::([^:@\/?#]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
7-
if (!m) {
8-
throw new RangeError();
9-
}
7+
if (!m)
8+
throw new RangeError('Invalid URL format');
109
var protocol = m[1] || "";
1110
var username = m[2] || "";
1211
var password = m[3] || "";
@@ -18,44 +17,40 @@ function URLPolyfill(url, baseURL) {
1817
var hash = m[9] || "";
1918
if (baseURL !== undefined) {
2019
var base = baseURL instanceof URLPolyfill ? baseURL : new URLPolyfill(baseURL);
21-
var flag = protocol === "" && host === "" && username === "";
22-
if (flag && pathname === "" && search === "") {
20+
var flag = !protocol && !host && !username;
21+
if (flag && !pathname && !search)
2322
search = base.search;
24-
}
25-
if (flag && pathname.charAt(0) !== "/") {
26-
pathname = (pathname !== "" ? (((base.host !== "" || base.username !== "") && base.pathname === "" ? "/" : "") + base.pathname.slice(0, base.pathname.lastIndexOf("/") + 1) + pathname) : base.pathname);
27-
}
23+
if (flag && pathname[0] !== "/")
24+
pathname = (pathname ? (((base.host || base.username) && !base.pathname ? "/" : "") + base.pathname.slice(0, base.pathname.lastIndexOf("/") + 1) + pathname) : base.pathname);
2825
// dot segments removal
2926
var output = [];
3027
pathname.replace(/^(\.\.?(\/|$))+/, "")
3128
.replace(/\/(\.(\/|$))+/g, "/")
3229
.replace(/\/\.\.$/, "/../")
3330
.replace(/\/?[^\/]*/g, function (p) {
34-
if (p === "/..") {
31+
if (p === "/..")
3532
output.pop();
36-
} else {
33+
else
3734
output.push(p);
38-
}
3935
});
40-
pathname = output.join("").replace(/^\//, pathname.charAt(0) === "/" ? "/" : "");
36+
pathname = output.join("").replace(/^\//, pathname[0] === "/" ? "/" : "");
4137
if (flag) {
4238
port = base.port;
4339
hostname = base.hostname;
4440
host = base.host;
4541
password = base.password;
4642
username = base.username;
4743
}
48-
if (protocol === "") {
44+
if (!protocol)
4945
protocol = base.protocol;
50-
}
5146
}
5247

5348
// convert windows file URLs to use /
5449
if (protocol == 'file:')
5550
pathname = pathname.replace(/\\/g, '/');
5651

57-
this.origin = protocol + (protocol !== "" || host !== "" ? "//" : "") + host;
58-
this.href = protocol + (protocol !== "" || host !== "" ? "//" : "") + (username !== "" ? username + (password !== "" ? ":" + password : "") + "@" : "") + host + pathname + search + hash;
52+
this.origin = host ? protocol + (protocol !== "" || host !== "" ? "//" : "") + host : "";
53+
this.href = protocol + (protocol && host || protocol == "file:" ? "//" : "") + (username !== "" ? username + (password !== "" ? ":" + password : "") + "@" : "") + host + pathname + search + hash;
5954
this.protocol = protocol;
6055
this.username = username;
6156
this.password = password;
@@ -104,24 +99,14 @@ global.URLPolyfill = URLPolyfill;
10499
})();
105100

106101
function addToError(err, msg) {
107-
var newErr;
108102
if (err instanceof Error) {
109-
newErr = new Error(err.message, err.fileName, err.lineNumber);
110-
if (isBrowser) {
111-
newErr.message = err.message + '\n\t' + msg;
112-
newErr.stack = err.stack;
113-
}
114-
else {
115-
// node errors only look correct with the stack modified
116-
newErr.message = err.message;
117-
newErr.stack = err.stack + '\n\t' + msg;
118-
}
103+
err.message = msg + '\n\t' + err.message;
104+
Error.call(err, err.message);
119105
}
120106
else {
121-
newErr = err + '\n\t' + msg;
107+
err = msg + '\n\t' + err;
122108
}
123-
124-
return newErr;
109+
return err;
125110
}
126111

127112
function __eval(source, debugName, context) {
@@ -922,10 +907,16 @@ function logloads(loads) {
922907
enumerable: true,
923908
get: function () {
924909
return obj[key];
910+
},
911+
set: function() {
912+
throw new Error('Module exports cannot be changed externally.');
925913
}
926914
});
927915
})(pNames[i]);
928916

917+
if (Object.freeze)
918+
Object.freeze(m);
919+
929920
return m;
930921
},
931922
// 26.3.3.14
@@ -1379,10 +1370,12 @@ function applyPaths(paths, name) {
13791370

13801371
// exact path match
13811372
if (pathParts.length == 1) {
1382-
if (name == p) {
1383-
pathMatch = p;
1384-
break;
1385-
}
1373+
if (name == p)
1374+
return paths[p];
1375+
1376+
// support trailing / in paths rules
1377+
else if (name.substr(0, p.length - 1) == p.substr(0, p.length - 1) && (name.length < p.length || name[p.length - 1] == p[p.length - 1]) && paths[p][paths[p].length - 1] == '/')
1378+
return paths[p].substr(0, paths[p].length - 1) + (name.length > p.length ? '/' + name.substr(p.length) : '');
13861379
}
13871380
// wildcard path match
13881381
else {

dist/es6-module-loader.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/es6-module-loader.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/es6-module-loader.src.js

+28-35
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ function URLPolyfill(url, baseURL) {
44
if (typeof url != 'string')
55
throw new TypeError('URL must be a string');
66
var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@\/?#]*)(?::([^:@\/?#]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
7-
if (!m) {
8-
throw new RangeError();
9-
}
7+
if (!m)
8+
throw new RangeError('Invalid URL format');
109
var protocol = m[1] || "";
1110
var username = m[2] || "";
1211
var password = m[3] || "";
@@ -18,44 +17,40 @@ function URLPolyfill(url, baseURL) {
1817
var hash = m[9] || "";
1918
if (baseURL !== undefined) {
2019
var base = baseURL instanceof URLPolyfill ? baseURL : new URLPolyfill(baseURL);
21-
var flag = protocol === "" && host === "" && username === "";
22-
if (flag && pathname === "" && search === "") {
20+
var flag = !protocol && !host && !username;
21+
if (flag && !pathname && !search)
2322
search = base.search;
24-
}
25-
if (flag && pathname.charAt(0) !== "/") {
26-
pathname = (pathname !== "" ? (((base.host !== "" || base.username !== "") && base.pathname === "" ? "/" : "") + base.pathname.slice(0, base.pathname.lastIndexOf("/") + 1) + pathname) : base.pathname);
27-
}
23+
if (flag && pathname[0] !== "/")
24+
pathname = (pathname ? (((base.host || base.username) && !base.pathname ? "/" : "") + base.pathname.slice(0, base.pathname.lastIndexOf("/") + 1) + pathname) : base.pathname);
2825
// dot segments removal
2926
var output = [];
3027
pathname.replace(/^(\.\.?(\/|$))+/, "")
3128
.replace(/\/(\.(\/|$))+/g, "/")
3229
.replace(/\/\.\.$/, "/../")
3330
.replace(/\/?[^\/]*/g, function (p) {
34-
if (p === "/..") {
31+
if (p === "/..")
3532
output.pop();
36-
} else {
33+
else
3734
output.push(p);
38-
}
3935
});
40-
pathname = output.join("").replace(/^\//, pathname.charAt(0) === "/" ? "/" : "");
36+
pathname = output.join("").replace(/^\//, pathname[0] === "/" ? "/" : "");
4137
if (flag) {
4238
port = base.port;
4339
hostname = base.hostname;
4440
host = base.host;
4541
password = base.password;
4642
username = base.username;
4743
}
48-
if (protocol === "") {
44+
if (!protocol)
4945
protocol = base.protocol;
50-
}
5146
}
5247

5348
// convert windows file URLs to use /
5449
if (protocol == 'file:')
5550
pathname = pathname.replace(/\\/g, '/');
5651

57-
this.origin = protocol + (protocol !== "" || host !== "" ? "//" : "") + host;
58-
this.href = protocol + (protocol !== "" || host !== "" ? "//" : "") + (username !== "" ? username + (password !== "" ? ":" + password : "") + "@" : "") + host + pathname + search + hash;
52+
this.origin = host ? protocol + (protocol !== "" || host !== "" ? "//" : "") + host : "";
53+
this.href = protocol + (protocol && host || protocol == "file:" ? "//" : "") + (username !== "" ? username + (password !== "" ? ":" + password : "") + "@" : "") + host + pathname + search + hash;
5954
this.protocol = protocol;
6055
this.username = username;
6156
this.password = password;
@@ -104,24 +99,14 @@ global.URLPolyfill = URLPolyfill;
10499
})();
105100

106101
function addToError(err, msg) {
107-
var newErr;
108102
if (err instanceof Error) {
109-
newErr = new Error(err.message, err.fileName, err.lineNumber);
110-
if (isBrowser) {
111-
newErr.message = err.message + '\n\t' + msg;
112-
newErr.stack = err.stack;
113-
}
114-
else {
115-
// node errors only look correct with the stack modified
116-
newErr.message = err.message;
117-
newErr.stack = err.stack + '\n\t' + msg;
118-
}
103+
err.message = msg + '\n\t' + err.message;
104+
Error.call(err, err.message);
119105
}
120106
else {
121-
newErr = err + '\n\t' + msg;
107+
err = msg + '\n\t' + err;
122108
}
123-
124-
return newErr;
109+
return err;
125110
}
126111

127112
function __eval(source, debugName, context) {
@@ -922,10 +907,16 @@ function logloads(loads) {
922907
enumerable: true,
923908
get: function () {
924909
return obj[key];
910+
},
911+
set: function() {
912+
throw new Error('Module exports cannot be changed externally.');
925913
}
926914
});
927915
})(pNames[i]);
928916

917+
if (Object.freeze)
918+
Object.freeze(m);
919+
929920
return m;
930921
},
931922
// 26.3.3.14
@@ -1033,10 +1024,12 @@ function applyPaths(paths, name) {
10331024

10341025
// exact path match
10351026
if (pathParts.length == 1) {
1036-
if (name == p) {
1037-
pathMatch = p;
1038-
break;
1039-
}
1027+
if (name == p)
1028+
return paths[p];
1029+
1030+
// support trailing / in paths rules
1031+
else if (name.substr(0, p.length - 1) == p.substr(0, p.length - 1) && (name.length < p.length || name[p.length - 1] == p[p.length - 1]) && paths[p][paths[p].length - 1] == '/')
1032+
return paths[p].substr(0, paths[p].length - 1) + (name.length > p.length ? '/' + name.substr(p.length) : '');
10401033
}
10411034
// wildcard path match
10421035
else {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "es6-module-loader",
33
"description": "An ES6 Module Loader shim",
4-
"version": "0.17.10",
4+
"version": "0.17.11",
55
"homepage": "https://github.com/ModuleLoader/es6-module-loader",
66
"author": {
77
"name": "Guy Bedford, Luke Hoban, Addy Osmani",

0 commit comments

Comments
 (0)