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

Commit b71f22f

Browse files
committed
v0.17.9
1 parent 380a70f commit b71f22f

7 files changed

+109
-51
lines changed

dist/es6-module-loader-dev.js

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -529,13 +529,14 @@ function logloads(loads) {
529529
if (loader.loads[i].name == name) {
530530
existingLoad = loader.loads[i];
531531

532-
if(step == 'translate' && !existingLoad.source) {
532+
if (step == 'translate' && !existingLoad.source) {
533533
existingLoad.address = stepState.moduleAddress;
534534
proceedToTranslate(loader, existingLoad, Promise.resolve(stepState.moduleSource));
535535
}
536536

537-
// a primary load -> use that existing linkset
538-
if (existingLoad.linkSets.length)
537+
// a primary load -> use that existing linkset if it is for the direct load here
538+
// otherwise create a new linkset unit
539+
if (existingLoad.linkSets.length && existingLoad.linkSets[0].loads[0].name == existingLoad.name)
539540
return existingLoad.linkSets[0].done.then(function() {
540541
resolve(existingLoad);
541542
});
@@ -903,19 +904,14 @@ function logloads(loads) {
903904
if (typeof obj != 'object')
904905
throw new TypeError('Expected object');
905906

906-
// we do this to be able to tell if a module is a module privately in ES5
907-
// by doing m instanceof Module
908907
var m = new Module();
909908

910-
var pNames;
911-
if (Object.getOwnPropertyNames && obj != null) {
909+
var pNames = [];
910+
if (Object.getOwnPropertyNames && obj != null)
912911
pNames = Object.getOwnPropertyNames(obj);
913-
}
914-
else {
915-
pNames = [];
912+
else
916913
for (var key in obj)
917914
pNames.push(key);
918-
}
919915

920916
for (var i = 0; i < pNames.length; i++) (function(key) {
921917
defineProperty(m, key, {
@@ -927,9 +923,6 @@ function logloads(loads) {
927923
});
928924
})(pNames[i]);
929925

930-
if (Object.preventExtensions)
931-
Object.preventExtensions(m);
932-
933926
return m;
934927
},
935928
// 26.3.3.14
@@ -1126,7 +1119,7 @@ function logloads(loads) {
11261119

11271120
module.locked = false;
11281121
return value;
1129-
});
1122+
}, load.name);
11301123

11311124
// setup our setters and execution function
11321125
module.setters = registryEntry.setters;
@@ -1336,7 +1329,7 @@ var transpile = (function() {
13361329
options.target = options.target || ts.ScriptTarget.ES5;
13371330
if (options.sourceMap === undefined)
13381331
options.sourceMap = true;
1339-
if (options.sourceMap)
1332+
if (options.sourceMap && options.inlineSourceMap !== false)
13401333
options.inlineSourceMap = true;
13411334

13421335
options.module = ts.ModuleKind.System;
@@ -1369,7 +1362,7 @@ function SystemLoader() {
13691362
// NB no specification provided for System.paths, used ideas discussed in https://github.com/jorendorff/js-loaders/issues/25
13701363
function applyPaths(paths, name) {
13711364
// most specific (most number of slashes in path) match wins
1372-
var pathMatch = '', wildcard, maxSlashCount = 0;
1365+
var pathMatch = '', wildcard, maxWildcardPrefixLen = 0;
13731366

13741367
// check to see if we have a paths entry
13751368
for (var p in paths) {
@@ -1386,11 +1379,11 @@ function applyPaths(paths, name) {
13861379
}
13871380
// wildcard path match
13881381
else {
1389-
var slashCount = p.split('/').length;
1390-
if (slashCount >= maxSlashCount &&
1382+
var wildcardPrefixLen = pathParts[0].length;
1383+
if (wildcardPrefixLen >= maxWildcardPrefixLen &&
13911384
name.substr(0, pathParts[0].length) == pathParts[0] &&
13921385
name.substr(name.length - pathParts[1].length) == pathParts[1]) {
1393-
maxSlashCount = slashCount;
1386+
maxWildcardPrefixLen = wildcardPrefixLen;
13941387
pathMatch = p;
13951388
wildcard = name.substr(pathParts[0].length, name.length - pathParts[1].length - pathParts[0].length);
13961389
}
@@ -1487,9 +1480,22 @@ SystemLoader.prototype.instantiate = function(load) {
14871480

14881481
xhr.onreadystatechange = function () {
14891482
if (xhr.readyState === 4) {
1490-
if (xhr.status === 200 || (xhr.status == 0 && xhr.responseText)) {
1483+
// in Chrome on file:/// URLs, status is 0
1484+
if (xhr.status == 0) {
1485+
if (xhr.responseText) {
1486+
load();
1487+
}
1488+
else {
1489+
// when responseText is empty, wait for load or error event
1490+
// to inform if it is a 404 or empty file
1491+
xhr.addEventListener('error', error);
1492+
xhr.addEventListener('load', load);
1493+
}
1494+
}
1495+
else if (xhr.status === 200) {
14911496
load();
1492-
} else {
1497+
}
1498+
else {
14931499
error();
14941500
}
14951501
}
@@ -1515,7 +1521,7 @@ SystemLoader.prototype.instantiate = function(load) {
15151521
}
15161522
};
15171523
}
1518-
else if (typeof require != 'undefined') {
1524+
else if (typeof require != 'undefined' && typeof process != 'undefined') {
15191525
var fs;
15201526
fetchTextFromURL = function(url, authorization, fulfill, reject) {
15211527
if (url.substr(0, 8) != 'file:///')
@@ -1540,6 +1546,29 @@ SystemLoader.prototype.instantiate = function(load) {
15401546
});
15411547
};
15421548
}
1549+
else if (typeof self != 'undefined' && typeof self.fetch != 'undefined') {
1550+
fetchTextFromURL = function(url, authorization, fulfill, reject) {
1551+
var opts = {
1552+
headers: {'Accept': 'application/x-es-module, */*'}
1553+
};
1554+
1555+
if (authorization) {
1556+
if (typeof authorization == 'string')
1557+
opts.headers['Authorization'] = authorization;
1558+
opts.credentials = 'include';
1559+
}
1560+
1561+
fetch(url, opts)
1562+
.then(function (r) {
1563+
if (r.ok) {
1564+
return r.text();
1565+
} else {
1566+
throw new Error('Fetch error: ' + r.status + ' ' + r.statusText);
1567+
}
1568+
})
1569+
.then(fulfill, reject);
1570+
}
1571+
}
15431572
else {
15441573
throw new TypeError('No environment fetch API available.');
15451574
}

dist/es6-module-loader.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/es6-module-loader.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/es6-module-loader.src.js

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -529,13 +529,14 @@ function logloads(loads) {
529529
if (loader.loads[i].name == name) {
530530
existingLoad = loader.loads[i];
531531

532-
if(step == 'translate' && !existingLoad.source) {
532+
if (step == 'translate' && !existingLoad.source) {
533533
existingLoad.address = stepState.moduleAddress;
534534
proceedToTranslate(loader, existingLoad, Promise.resolve(stepState.moduleSource));
535535
}
536536

537-
// a primary load -> use that existing linkset
538-
if (existingLoad.linkSets.length)
537+
// a primary load -> use that existing linkset if it is for the direct load here
538+
// otherwise create a new linkset unit
539+
if (existingLoad.linkSets.length && existingLoad.linkSets[0].loads[0].name == existingLoad.name)
539540
return existingLoad.linkSets[0].done.then(function() {
540541
resolve(existingLoad);
541542
});
@@ -903,19 +904,14 @@ function logloads(loads) {
903904
if (typeof obj != 'object')
904905
throw new TypeError('Expected object');
905906

906-
// we do this to be able to tell if a module is a module privately in ES5
907-
// by doing m instanceof Module
908907
var m = new Module();
909908

910-
var pNames;
911-
if (Object.getOwnPropertyNames && obj != null) {
909+
var pNames = [];
910+
if (Object.getOwnPropertyNames && obj != null)
912911
pNames = Object.getOwnPropertyNames(obj);
913-
}
914-
else {
915-
pNames = [];
912+
else
916913
for (var key in obj)
917914
pNames.push(key);
918-
}
919915

920916
for (var i = 0; i < pNames.length; i++) (function(key) {
921917
defineProperty(m, key, {
@@ -927,9 +923,6 @@ function logloads(loads) {
927923
});
928924
})(pNames[i]);
929925

930-
if (Object.preventExtensions)
931-
Object.preventExtensions(m);
932-
933926
return m;
934927
},
935928
// 26.3.3.14
@@ -1027,7 +1020,7 @@ function SystemLoader() {
10271020
// NB no specification provided for System.paths, used ideas discussed in https://github.com/jorendorff/js-loaders/issues/25
10281021
function applyPaths(paths, name) {
10291022
// most specific (most number of slashes in path) match wins
1030-
var pathMatch = '', wildcard, maxSlashCount = 0;
1023+
var pathMatch = '', wildcard, maxWildcardPrefixLen = 0;
10311024

10321025
// check to see if we have a paths entry
10331026
for (var p in paths) {
@@ -1044,11 +1037,11 @@ function applyPaths(paths, name) {
10441037
}
10451038
// wildcard path match
10461039
else {
1047-
var slashCount = p.split('/').length;
1048-
if (slashCount >= maxSlashCount &&
1040+
var wildcardPrefixLen = pathParts[0].length;
1041+
if (wildcardPrefixLen >= maxWildcardPrefixLen &&
10491042
name.substr(0, pathParts[0].length) == pathParts[0] &&
10501043
name.substr(name.length - pathParts[1].length) == pathParts[1]) {
1051-
maxSlashCount = slashCount;
1044+
maxWildcardPrefixLen = wildcardPrefixLen;
10521045
pathMatch = p;
10531046
wildcard = name.substr(pathParts[0].length, name.length - pathParts[1].length - pathParts[0].length);
10541047
}
@@ -1145,9 +1138,22 @@ SystemLoader.prototype.instantiate = function(load) {
11451138

11461139
xhr.onreadystatechange = function () {
11471140
if (xhr.readyState === 4) {
1148-
if (xhr.status === 200 || (xhr.status == 0 && xhr.responseText)) {
1141+
// in Chrome on file:/// URLs, status is 0
1142+
if (xhr.status == 0) {
1143+
if (xhr.responseText) {
1144+
load();
1145+
}
1146+
else {
1147+
// when responseText is empty, wait for load or error event
1148+
// to inform if it is a 404 or empty file
1149+
xhr.addEventListener('error', error);
1150+
xhr.addEventListener('load', load);
1151+
}
1152+
}
1153+
else if (xhr.status === 200) {
11491154
load();
1150-
} else {
1155+
}
1156+
else {
11511157
error();
11521158
}
11531159
}
@@ -1173,7 +1179,7 @@ SystemLoader.prototype.instantiate = function(load) {
11731179
}
11741180
};
11751181
}
1176-
else if (typeof require != 'undefined') {
1182+
else if (typeof require != 'undefined' && typeof process != 'undefined') {
11771183
var fs;
11781184
fetchTextFromURL = function(url, authorization, fulfill, reject) {
11791185
if (url.substr(0, 8) != 'file:///')
@@ -1198,6 +1204,29 @@ SystemLoader.prototype.instantiate = function(load) {
11981204
});
11991205
};
12001206
}
1207+
else if (typeof self != 'undefined' && typeof self.fetch != 'undefined') {
1208+
fetchTextFromURL = function(url, authorization, fulfill, reject) {
1209+
var opts = {
1210+
headers: {'Accept': 'application/x-es-module, */*'}
1211+
};
1212+
1213+
if (authorization) {
1214+
if (typeof authorization == 'string')
1215+
opts.headers['Authorization'] = authorization;
1216+
opts.credentials = 'include';
1217+
}
1218+
1219+
fetch(url, opts)
1220+
.then(function (r) {
1221+
if (r.ok) {
1222+
return r.text();
1223+
} else {
1224+
throw new Error('Fetch error: ' + r.status + ' ' + r.statusText);
1225+
}
1226+
})
1227+
.then(fulfill, reject);
1228+
}
1229+
}
12011230
else {
12021231
throw new TypeError('No environment fetch API available.');
12031232
}

package.json

Lines changed: 1 addition & 1 deletion
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.8",
4+
"version": "0.17.9",
55
"homepage": "https://github.com/ModuleLoader/es6-module-loader",
66
"author": {
77
"name": "Guy Bedford, Luke Hoban, Addy Osmani",

0 commit comments

Comments
 (0)