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

Commit ace2e3a

Browse files
committed
disable auto js extensions
1 parent c32a324 commit ace2e3a

30 files changed

+242
-378
lines changed

dist/es6-module-loader-sans-promises.js

Lines changed: 46 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,7 +2469,7 @@ function logloads(loads) {
24692469
else {
24702470
this.baseURL = process.cwd() + '/';
24712471
}
2472-
this.paths = { '*': '*.js' };
2472+
this.paths = { '*': '*' };
24732473
}
24742474

24752475
SystemLoader.__proto__ = ($__super !== null ? $__super : Function.prototype);
@@ -2497,102 +2497,65 @@ function logloads(loads) {
24972497
if (typeof name != 'string')
24982498
throw new TypeError('Module name must be a string');
24992499

2500-
var segments = name.split('/');
2501-
2502-
if (segments.length == 0)
2503-
throw new TypeError('No module name provided');
2504-
2505-
// current segment
2506-
var i = 0;
2507-
// is the module name relative
2508-
var rel = false;
2509-
// number of backtracking segments
2510-
var dotdots = 0;
2511-
if (segments[0] == '.') {
2512-
i++;
2513-
if (i == segments.length)
2514-
throw new TypeError('Illegal module name "' + name + '"');
2515-
rel = true;
2516-
}
2517-
else {
2518-
while (segments[i] == '..') {
2519-
i++;
2520-
if (i == segments.length)
2521-
throw new TypeError('Illegal module name "' + name + '"');
2522-
}
2523-
if (i)
2524-
rel = true;
2525-
dotdots = i;
2526-
}
2527-
2528-
for (var j = i; j < segments.length; j++) {
2529-
var segment = segments[j];
2530-
if (segment == '' || segment == '.' || segment == '..')
2531-
throw new TypeError('Illegal module name "' + name + '"');
2532-
}
2533-
2534-
if (!rel)
2535-
return name;
2536-
2537-
// build the full module name
2538-
var normalizedParts = [];
2539-
var parentParts = (parentName || '').split('/');
2540-
var normalizedLen = parentParts.length - 1 - dotdots;
2541-
2542-
normalizedParts = normalizedParts.concat(parentParts.splice(0, parentParts.length - 1 - dotdots));
2543-
normalizedParts = normalizedParts.concat(segments.splice(i, segments.length - i));
2544-
2545-
return normalizedParts.join('/');
2546-
},
2547-
2548-
enumerable: false,
2549-
writable: true
2550-
});
2551-
2552-
$__Object$defineProperty(SystemLoader.prototype, "locate", {
2553-
value: function(load) {
2554-
var name = load.name;
2555-
2556-
// NB no specification provided for System.paths, used ideas discussed in https://github.com/jorendorff/js-loaders/issues/25
2500+
// if all names are normalized, then we only ever need to
2501+
// normalize relative to the parent
2502+
// the top-level parent is then just the baseURL
2503+
parentName = parentName || this.baseURL;
25572504

2505+
// if the name does not start with a ./, ../, / or scheme:
2506+
// then we first apply paths configuration with wildcard
2507+
// used ideas discussed in https://github.com/jorendorff/js-loaders/issues/25
25582508
// most specific (longest) match wins
2559-
var pathMatch = '', wildcard;
2560-
2561-
// check to see if we have a paths entry
2562-
for (var p in this.paths) {
2563-
var pathParts = p.split('*');
2564-
if (pathParts.length > 2)
2565-
throw new TypeError('Only one wildcard in a path is permitted');
2566-
2567-
// exact path match
2568-
if (pathParts.length == 1) {
2569-
if (name == p && p.length > pathMatch.length) {
2570-
pathMatch = p;
2571-
break;
2509+
if (name.substr(0, 2) != './' && name.substr(0, 3) != '../' && name.substr(0, 1) != '/' && name.indexOf(':') == -1) {
2510+
var pathMatch = '', wildcard;
2511+
2512+
// check to see if we have a paths entry
2513+
for (var p in this.paths) {
2514+
var pathParts = p.split('*');
2515+
if (pathParts.length > 2)
2516+
throw new TypeError('Only one wildcard in a path is permitted');
2517+
2518+
// exact path match
2519+
if (pathParts.length == 1) {
2520+
if (name == p && p.length > pathMatch.length) {
2521+
pathMatch = p;
2522+
break;
2523+
}
25722524
}
2573-
}
25742525

2575-
// wildcard path match
2576-
else {
2577-
if (name.substr(0, pathParts[0].length) == pathParts[0] && name.substr(name.length - pathParts[1].length) == pathParts[1]) {
2578-
pathMatch = p;
2579-
wildcard = name.substr(pathParts[0].length, name.length - pathParts[1].length - pathParts[0].length);
2526+
// wildcard path match
2527+
else {
2528+
if (name.substr(0, pathParts[0].length) == pathParts[0] && name.substr(name.length - pathParts[1].length) == pathParts[1]) {
2529+
pathMatch = p;
2530+
wildcard = name.substr(pathParts[0].length, name.length - pathParts[1].length - pathParts[0].length);
2531+
}
25802532
}
25812533
}
2534+
name = this.paths[pathMatch];
2535+
if (wildcard)
2536+
name = name.replace('*', wildcard);
25822537
}
25832538

2584-
var outPath = this.paths[pathMatch];
2585-
if (wildcard)
2586-
outPath = outPath.replace('*', wildcard);
2587-
25882539
// percent encode just '#' in module names
25892540
// according to https://github.com/jorendorff/js-loaders/blob/master/browser-loader.js#L238
25902541
// we should encode everything, but it breaks for servers that don't expect it
25912542
// like in (https://github.com/systemjs/systemjs/issues/168)
25922543
if (isBrowser)
2593-
outPath = outPath.replace(/#/g, '%23');
2544+
name = name.replace(/#/g, '%23');
25942545

2595-
return toAbsoluteURL(this.baseURL, outPath);
2546+
return toAbsoluteURL(parentName, name);
2547+
},
2548+
2549+
enumerable: false,
2550+
writable: true
2551+
});
2552+
2553+
$__Object$defineProperty(SystemLoader.prototype, "locate", {
2554+
value: function(load) {
2555+
// it is possible for locate to not to be a fully normalized URL
2556+
// if name was forced into not being of an absolute URL by normalize
2557+
// so we run toAbsoluteURL again just in case
2558+
return toAbsoluteURL(this.baseURL, load.name);
25962559
},
25972560

25982561
enumerable: false,

dist/es6-module-loader-sans-promises.min.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

Lines changed: 46 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,7 +2433,7 @@ function logloads(loads) {
24332433
else {
24342434
this.baseURL = process.cwd() + '/';
24352435
}
2436-
this.paths = { '*': '*.js' };
2436+
this.paths = { '*': '*' };
24372437
}
24382438

24392439
SystemLoader.__proto__ = ($__super !== null ? $__super : Function.prototype);
@@ -2461,102 +2461,65 @@ function logloads(loads) {
24612461
if (typeof name != 'string')
24622462
throw new TypeError('Module name must be a string');
24632463

2464-
var segments = name.split('/');
2465-
2466-
if (segments.length == 0)
2467-
throw new TypeError('No module name provided');
2468-
2469-
// current segment
2470-
var i = 0;
2471-
// is the module name relative
2472-
var rel = false;
2473-
// number of backtracking segments
2474-
var dotdots = 0;
2475-
if (segments[0] == '.') {
2476-
i++;
2477-
if (i == segments.length)
2478-
throw new TypeError('Illegal module name "' + name + '"');
2479-
rel = true;
2480-
}
2481-
else {
2482-
while (segments[i] == '..') {
2483-
i++;
2484-
if (i == segments.length)
2485-
throw new TypeError('Illegal module name "' + name + '"');
2486-
}
2487-
if (i)
2488-
rel = true;
2489-
dotdots = i;
2490-
}
2491-
2492-
for (var j = i; j < segments.length; j++) {
2493-
var segment = segments[j];
2494-
if (segment == '' || segment == '.' || segment == '..')
2495-
throw new TypeError('Illegal module name "' + name + '"');
2496-
}
2497-
2498-
if (!rel)
2499-
return name;
2500-
2501-
// build the full module name
2502-
var normalizedParts = [];
2503-
var parentParts = (parentName || '').split('/');
2504-
var normalizedLen = parentParts.length - 1 - dotdots;
2505-
2506-
normalizedParts = normalizedParts.concat(parentParts.splice(0, parentParts.length - 1 - dotdots));
2507-
normalizedParts = normalizedParts.concat(segments.splice(i, segments.length - i));
2508-
2509-
return normalizedParts.join('/');
2510-
},
2511-
2512-
enumerable: false,
2513-
writable: true
2514-
});
2515-
2516-
$__Object$defineProperty(SystemLoader.prototype, "locate", {
2517-
value: function(load) {
2518-
var name = load.name;
2519-
2520-
// NB no specification provided for System.paths, used ideas discussed in https://github.com/jorendorff/js-loaders/issues/25
2464+
// if all names are normalized, then we only ever need to
2465+
// normalize relative to the parent
2466+
// the top-level parent is then just the baseURL
2467+
parentName = parentName || this.baseURL;
25212468

2469+
// if the name does not start with a ./, ../, / or scheme:
2470+
// then we first apply paths configuration with wildcard
2471+
// used ideas discussed in https://github.com/jorendorff/js-loaders/issues/25
25222472
// most specific (longest) match wins
2523-
var pathMatch = '', wildcard;
2524-
2525-
// check to see if we have a paths entry
2526-
for (var p in this.paths) {
2527-
var pathParts = p.split('*');
2528-
if (pathParts.length > 2)
2529-
throw new TypeError('Only one wildcard in a path is permitted');
2530-
2531-
// exact path match
2532-
if (pathParts.length == 1) {
2533-
if (name == p && p.length > pathMatch.length) {
2534-
pathMatch = p;
2535-
break;
2473+
if (name.substr(0, 2) != './' && name.substr(0, 3) != '../' && name.substr(0, 1) != '/' && name.indexOf(':') == -1) {
2474+
var pathMatch = '', wildcard;
2475+
2476+
// check to see if we have a paths entry
2477+
for (var p in this.paths) {
2478+
var pathParts = p.split('*');
2479+
if (pathParts.length > 2)
2480+
throw new TypeError('Only one wildcard in a path is permitted');
2481+
2482+
// exact path match
2483+
if (pathParts.length == 1) {
2484+
if (name == p && p.length > pathMatch.length) {
2485+
pathMatch = p;
2486+
break;
2487+
}
25362488
}
2537-
}
25382489

2539-
// wildcard path match
2540-
else {
2541-
if (name.substr(0, pathParts[0].length) == pathParts[0] && name.substr(name.length - pathParts[1].length) == pathParts[1]) {
2542-
pathMatch = p;
2543-
wildcard = name.substr(pathParts[0].length, name.length - pathParts[1].length - pathParts[0].length);
2490+
// wildcard path match
2491+
else {
2492+
if (name.substr(0, pathParts[0].length) == pathParts[0] && name.substr(name.length - pathParts[1].length) == pathParts[1]) {
2493+
pathMatch = p;
2494+
wildcard = name.substr(pathParts[0].length, name.length - pathParts[1].length - pathParts[0].length);
2495+
}
25442496
}
25452497
}
2498+
name = this.paths[pathMatch];
2499+
if (wildcard)
2500+
name = name.replace('*', wildcard);
25462501
}
25472502

2548-
var outPath = this.paths[pathMatch];
2549-
if (wildcard)
2550-
outPath = outPath.replace('*', wildcard);
2551-
25522503
// percent encode just '#' in module names
25532504
// according to https://github.com/jorendorff/js-loaders/blob/master/browser-loader.js#L238
25542505
// we should encode everything, but it breaks for servers that don't expect it
25552506
// like in (https://github.com/systemjs/systemjs/issues/168)
25562507
if (isBrowser)
2557-
outPath = outPath.replace(/#/g, '%23');
2508+
name = name.replace(/#/g, '%23');
25582509

2559-
return toAbsoluteURL(this.baseURL, outPath);
2510+
return toAbsoluteURL(parentName, name);
2511+
},
2512+
2513+
enumerable: false,
2514+
writable: true
2515+
});
2516+
2517+
$__Object$defineProperty(SystemLoader.prototype, "locate", {
2518+
value: function(load) {
2519+
// it is possible for locate to not to be a fully normalized URL
2520+
// if name was forced into not being of an absolute URL by normalize
2521+
// so we run toAbsoluteURL again just in case
2522+
return toAbsoluteURL(this.baseURL, load.name);
25602523
},
25612524

25622525
enumerable: false,

dist/es6-module-loader.min.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.

0 commit comments

Comments
 (0)