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

Commit 1e6e9c0

Browse files
committed
global build public/private scoping
1 parent db5c1eb commit 1e6e9c0

File tree

7 files changed

+89
-71
lines changed

7 files changed

+89
-71
lines changed

src/declarative.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,5 @@
281281

282282
module.execute = undefined;
283283
return err;
284-
}
284+
}
285+
})();

src/dynamic-only.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@
2727

2828
function evaluateLoadedModule(loader, load) {
2929
return load.module.module;
30-
}
30+
}
31+
32+
})();

src/loader.js

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,39 @@
1818
*********************************************************************************************
1919
*/
2020

21+
function Module() {}
22+
function Loader(options) {
23+
if (options.normalize)
24+
this.normalize = options.normalize;
25+
if (options.locate)
26+
this.locate = options.locate;
27+
if (options.fetch)
28+
this.fetch = options.fetch;
29+
if (options.translate)
30+
this.translate = options.translate;
31+
if (options.instantiate)
32+
this.instantiate = options.instantiate;
33+
34+
this._loader = {
35+
loaderObj: this,
36+
loads: [],
37+
modules: {},
38+
importPromises: {},
39+
moduleRecords: {}
40+
};
41+
42+
// 26.3.3.6
43+
defineProperty(this, 'global', {
44+
get: function() {
45+
return __global;
46+
}
47+
});
48+
49+
// 26.3.3.13 realm not implemented
50+
}
51+
52+
(function() {
53+
2154
// Some Helpers
2255

2356
// logs a linkset snapshot for debugging
@@ -576,37 +609,7 @@ function logloads(loads) {
576609
// 26.3 Loader
577610

578611
// 26.3.1.1
579-
function Loader(options) {
580-
if (options.normalize)
581-
this.normalize = options.normalize;
582-
if (options.locate)
583-
this.locate = options.locate;
584-
if (options.fetch)
585-
this.fetch = options.fetch;
586-
if (options.translate)
587-
this.translate = options.translate;
588-
if (options.instantiate)
589-
this.instantiate = options.instantiate;
590-
591-
this._loader = {
592-
loaderObj: this,
593-
loads: [],
594-
modules: {},
595-
importPromises: {},
596-
moduleRecords: {}
597-
};
598-
599-
// 26.3.3.6
600-
defineProperty(this, 'global', {
601-
get: function() {
602-
return __global;
603-
}
604-
});
605-
606-
// 26.3.3.13 realm not implemented
607-
}
608-
609-
function Module() {}
612+
// defined at top
610613

611614
// importPromises adds ability to import a module twice without error - https://bugs.ecmascript.org/show_bug.cgi?id=2601
612615
function createImportPromise(loader, name, promise) {

src/module-tag.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
(function() {
12
// <script type="module"> support
23
// allow a data-init function callback once loaded
34
if (isBrowser && typeof document.getElementsByTagName != 'undefined') {
@@ -32,4 +33,5 @@
3233
document.addEventListener('DOMContentLoaded', completed, false);
3334
window.addEventListener('load', completed, false);
3435
}
35-
}
36+
}
37+
})();

src/system.js

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

13+
var System;
14+
15+
function SystemLoader(options) {
16+
Loader.call(this, options || {});
17+
18+
var baseURL;
19+
// Set default baseURL and paths
20+
if (isWorker) {
21+
baseURL = __global.location.href;
22+
}
23+
else if (typeof document != 'undefined') {
24+
baseURL = document.baseURI;
25+
26+
if (!baseURL) {
27+
var bases = document.getElementsByTagName('base');
28+
baseURL = bases[0] && bases[0].href || window.location.href;
29+
}
30+
31+
// sanitize out the hash and querystring
32+
// removes the username and password, which could be adjusted
33+
baseURL = new URL(baseURL);
34+
baseURL = baseURL.origin + baseURL.pathname.substr(0, baseURL.pathname.lastIndexOf('/') + 1);
35+
}
36+
else if (typeof process != 'undefined' && process.cwd) {
37+
baseURL = 'file://' + (isWindows ? '/' : '') + process.cwd() + '/';
38+
if (isWindows)
39+
baseURL = baseURL.replace(/\\/g, '/');
40+
}
41+
else {
42+
throw new TypeError('No environment baseURL');
43+
}
44+
45+
this.baseURL = baseURL;
46+
this.paths = {};
47+
}
48+
49+
(function() {
1350
var fetchTextFromURL;
1451
if (typeof XMLHttpRequest != 'undefined') {
1552
fetchTextFromURL = function(url, fulfill, reject) {
@@ -82,40 +119,6 @@
82119
throw new TypeError('No environment fetch API available.');
83120
}
84121

85-
var SystemLoader = function(options) {
86-
Loader.call(this, options || {});
87-
88-
var baseURL;
89-
// Set default baseURL and paths
90-
if (isWorker) {
91-
baseURL = __global.location.href;
92-
}
93-
else if (typeof document != 'undefined') {
94-
baseURL = document.baseURI;
95-
96-
if (!baseURL) {
97-
var bases = document.getElementsByTagName('base');
98-
baseURL = bases[0] && bases[0].href || window.location.href;
99-
}
100-
101-
// sanitize out the hash and querystring
102-
// removes the username and password, which could be adjusted
103-
baseURL = new URL(baseURL);
104-
baseURL = baseURL.origin + baseURL.pathname.substr(0, baseURL.pathname.lastIndexOf('/') + 1);
105-
}
106-
else if (typeof process != 'undefined' && process.cwd) {
107-
baseURL = 'file://' + (isWindows ? '/' : '') + process.cwd() + '/';
108-
if (isWindows)
109-
baseURL = baseURL.replace(/\\/g, '/');
110-
}
111-
else {
112-
throw new TypeError('No environment baseURL');
113-
}
114-
115-
this.baseURL = baseURL;
116-
this.paths = {};
117-
};
118-
119122
// inline Object.create-style class extension
120123
function LoaderProto() {}
121124
LoaderProto.prototype = Loader.prototype;
@@ -213,4 +216,4 @@
213216
});
214217
};
215218

216-
var System = new SystemLoader();
219+
})();

src/transpiler.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/*
22
* Traceur and Babel transpile hook for Loader
33
*/
4-
4+
var transpile = (function() {
5+
56
function getTranspilerModule(loader, globalName) {
67
return loader.newModule({ 'default': __global[globalName], __useDefault: true });
78
}
@@ -96,4 +97,7 @@
9697
options.blacklist = ['react'];
9798

9899
return babel.transform(load.source, options).code;
99-
}
100+
}
101+
102+
return transpile;
103+
})();

src/wrapper-end.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
__global.Reflect.global = __global.Reflect.global || __global;
99
__global.LoaderPolyfill = Loader;
1010

11+
if (!System)
12+
System = new SystemLoader();
13+
1114
if (typeof exports === 'object')
1215
module.exports = System;
1316

0 commit comments

Comments
 (0)