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

Commit 9e48717

Browse files
committed
remove js extension adding, simplify System
1 parent 7d4cd50 commit 9e48717

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+274
-335
lines changed

src/loader.js

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -100,35 +100,6 @@ function logloads(loads) {
100100
}
101101
}
102102
} */
103-
var Promise = __global.Promise || require('when/es6-shim/Promise');
104-
if (__global.console)
105-
console.assert = console.assert || function() {};
106-
107-
// IE8 support
108-
var indexOf = Array.prototype.indexOf || function(item) {
109-
for (var i = 0, thisLen = this.length; i < thisLen; i++) {
110-
if (this[i] === item) {
111-
return i;
112-
}
113-
}
114-
return -1;
115-
};
116-
117-
var defineProperty;
118-
(function () {
119-
try {
120-
if (!!Object.defineProperty({}, 'a', {}))
121-
defineProperty = Object.defineProperty;
122-
}
123-
catch (e) {
124-
defineProperty = function(obj, prop, opt) {
125-
try {
126-
obj[prop] = opt.value || opt.get.call(obj);
127-
}
128-
catch(e) {}
129-
}
130-
}
131-
})();
132103

133104
// 15.2.3 - Runtime Semantics: Loader State
134105

@@ -612,9 +583,6 @@ function logloads(loads) {
612583

613584
// 26.3.1.1
614585
function Loader(options) {
615-
if (typeof options != 'object')
616-
throw new TypeError('Options must be an object');
617-
618586
if (options.normalize)
619587
this.normalize = options.normalize;
620588
if (options.locate)
@@ -787,7 +755,6 @@ function logloads(loads) {
787755
},
788756
// 26.3.3.18.3
789757
fetch: function(load) {
790-
throw new TypeError('Fetch not implemented');
791758
},
792759
// 26.3.3.18.4
793760
translate: function(load) {
@@ -799,12 +766,3 @@ function logloads(loads) {
799766
};
800767

801768
var _newModule = Loader.prototype.newModule;
802-
803-
if (typeof exports === 'object')
804-
module.exports = Loader;
805-
806-
__global.Reflect = __global.Reflect || {};
807-
__global.Reflect.Loader = __global.Reflect.Loader || Loader;
808-
__global.Reflect.global = __global.Reflect.global || __global;
809-
__global.LoaderPolyfill = Loader;
810-

src/module-tag.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,4 @@
3232
document.addEventListener('DOMContentLoaded', completed, false);
3333
window.addEventListener('load', completed, false);
3434
}
35-
36-
// run the data-init function on the script tag
37-
if (curScript.getAttribute('data-init'))
38-
window[curScript.getAttribute('data-init')]();
3935
}

src/polyfill-wrapper-end.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// -- exporting --
2+
3+
if (typeof exports === 'object')
4+
module.exports = Loader;
5+
6+
__global.Reflect = __global.Reflect || {};
7+
__global.Reflect.Loader = __global.Reflect.Loader || Loader;
8+
__global.Reflect.global = __global.Reflect.global || __global;
9+
__global.LoaderPolyfill = Loader;
10+
11+
if (typeof exports === 'object')
12+
module.exports = System;
13+
14+
__global.System = System;
115

216
})();
317

src/polyfill-wrapper-start.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,35 @@
11
(function(__global) {
2-
(function() {
2+
(function() {
3+
4+
var isWorker = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
5+
var isBrowser = typeof window != 'undefined' && !isWorker;
6+
var isWindows = typeof process != 'undefined' && !!process.platform.match(/^win/);
7+
8+
if (__global.console)
9+
console.assert = console.assert || function() {};
10+
11+
// IE8 support
12+
var indexOf = Array.prototype.indexOf || function(item) {
13+
for (var i = 0, thisLen = this.length; i < thisLen; i++) {
14+
if (this[i] === item) {
15+
return i;
16+
}
17+
}
18+
return -1;
19+
};
20+
21+
var defineProperty;
22+
(function () {
23+
try {
24+
if (!!Object.defineProperty({}, 'a', {}))
25+
defineProperty = Object.defineProperty;
26+
}
27+
catch (e) {
28+
defineProperty = function(obj, prop, opt) {
29+
try {
30+
obj[prop] = opt.value || opt.get.call(obj);
31+
}
32+
catch(e) {}
33+
}
34+
}
35+
})();

src/system.js

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
*********************************************************************************************
1111
*/
1212

13-
var isWorker = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
14-
var isBrowser = typeof window != 'undefined' && !isWorker;
15-
var isWindows = typeof process != 'undefined' && !!process.platform.match(/^win/);
16-
var Promise = __global.Promise || require('when/es6-shim/Promise');
17-
1813
var fetchTextFromURL;
1914
if (typeof XMLHttpRequest != 'undefined') {
2015
fetchTextFromURL = function(url, fulfill, reject) {
@@ -63,24 +58,25 @@
6358
}, 0);
6459

6560
xhr.send(null);
66-
}
61+
};
6762
}
6863
else if (typeof require != 'undefined') {
6964
var fs;
7065
fetchTextFromURL = function(url, fulfill, reject) {
71-
if (url.substr(0, 5) != 'file:')
72-
throw 'Only file URLs of the form file: allowed running in Node.';
66+
if (url.substr(0, 8) != 'file:///')
67+
throw 'Only file URLs of the form file:/// allowed running in Node.';
7368
fs = fs || require('fs');
74-
url = url.substr(5);
7569
if (isWindows)
76-
url = url.replace(/\//g, '\\');
70+
url = url.replace(/\//g, '\\').substr(8);
71+
else
72+
url = url.substr(7);
7773
return fs.readFile(url, function(err, data) {
7874
if (err)
7975
return reject(err);
8076
else
8177
fulfill(data + '');
8278
});
83-
}
79+
};
8480
}
8581
else {
8682
throw new TypeError('No environment fetch API available.');
@@ -95,32 +91,27 @@
9591
this.baseURL = href.substring(0, href.lastIndexOf('/') + 1);
9692
}
9793
else if (typeof process != 'undefined' && process.cwd) {
98-
this.baseURL = 'file:' + process.cwd() + '/';
94+
this.baseURL = 'file://' + (isWindows ? '/' : '') + process.cwd() + '/';
9995
if (isWindows)
10096
this.baseURL = this.baseURL.replace(/\\/g, '/');
10197
}
10298
else {
10399
throw new TypeError('No environment baseURL');
104100
}
105-
this.paths = { '*': '*.js' };
101+
this.paths = {};
106102
};
107103

108104
// inline Object.create-style class extension
109105
function LoaderProto() {}
110106
LoaderProto.prototype = Loader.prototype;
111107
SystemLoader.prototype = new LoaderProto();
112108

113-
SystemLoader.prototype.global = isBrowser ? window : (isWorker ? self : __global);
114-
115109
SystemLoader.prototype.normalize = function(name, parentName, parentAddress) {
116110
if (typeof name != 'string')
117111
throw new TypeError('Module name must be a string');
118112

119113
var segments = name.split('/');
120114

121-
if (segments.length == 0)
122-
throw new TypeError('No module name provided');
123-
124115
// current segment
125116
var i = 0;
126117
// is the module name relative
@@ -129,27 +120,17 @@
129120
var dotdots = 0;
130121
if (segments[0] == '.') {
131122
i++;
132-
if (i == segments.length)
133-
throw new TypeError('Illegal module name "' + name + '"');
134123
rel = true;
135124
}
136125
else {
137126
while (segments[i] == '..') {
138127
i++;
139-
if (i == segments.length)
140-
throw new TypeError('Illegal module name "' + name + '"');
141128
}
142129
if (i)
143130
rel = true;
144131
dotdots = i;
145132
}
146133

147-
for (var j = i; j < segments.length; j++) {
148-
var segment = segments[j];
149-
if (segment == '' || segment == '.' || segment == '..')
150-
throw new TypeError('Illegal module name "' + name + '"');
151-
}
152-
153134
if (!rel)
154135
return name;
155136

@@ -162,7 +143,9 @@
162143
normalizedParts = normalizedParts.concat(segments.splice(i, segments.length - i));
163144

164145
return normalizedParts.join('/');
165-
}
146+
};
147+
148+
var baseURLCache = {};
166149

167150
SystemLoader.prototype.locate = function(load) {
168151
var name = load.name;
@@ -195,7 +178,7 @@
195178
}
196179
}
197180

198-
var outPath = this.paths[pathMatch];
181+
var outPath = this.paths[pathMatch] || name;
199182
if (wildcard)
200183
outPath = outPath.replace('*', wildcard);
201184

@@ -206,22 +189,13 @@
206189
if (isBrowser)
207190
outPath = outPath.replace(/#/g, '%23');
208191

209-
return toAbsoluteURL(this.baseURL, outPath);
210-
}
192+
return new URLUtils(outPath, baseURLCache[this.baseURL] = baseURLCache[this.baseURL] || new URLUtils(this.baseURL)).href;
193+
};
211194

212195
SystemLoader.prototype.fetch = function(load) {
213-
var self = this;
214196
return new Promise(function(resolve, reject) {
215-
fetchTextFromURL(toAbsoluteURL(self.baseURL, load.address), function(source) {
216-
resolve(source);
217-
}, reject);
197+
fetchTextFromURL(load.address, resolve, reject);
218198
});
219-
}
199+
};
220200

221201
var System = new SystemLoader();
222-
223-
// note we have to export before runing "init" below
224-
if (typeof exports === 'object')
225-
module.exports = System;
226-
227-
__global.System = System;

src/transpiler.js

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

0 commit comments

Comments
 (0)