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

Commit 2cc6f36

Browse files
committed
0.14.0
1 parent e616a94 commit 2cc6f36

8 files changed

+100
-39
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Dynamically loads ES6 modules in browsers and [NodeJS](#nodejs-use) with support
55
This project implements dynamic module loading through `System` exactly to the previous ES6-specified loader API at [2014-08-24 ES6 Specification Draft Rev 27, Section 15](http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts#august_24_2014_draft_rev_27) and will continue to track this API as it is re-drafted as a browser specification (currently most likely to be at https://github.com/whatwg/loader).
66

77
* Provides an asynchronous loader (`System.import`) to [dynamically load ES6 modules](#getting-started).
8-
* Supports both [Traceur](https://github.com/google/traceur-compiler) and [6to5](https://6to5.org/) for compiling ES6 modules and syntax into ES5 in the browser with source map support.
8+
* Supports both [Traceur](https://github.com/google/traceur-compiler) and [Babel](https://babel.org/) for compiling ES6 modules and syntax into ES5 in the browser with source map support.
99
* Fully supports [ES6 circular references and live bindings](https://github.com/ModuleLoader/es6-module-loader/wiki/Circular-References-&-Bindings).
1010
* Includes [`baseURL` and `paths` implementations](https://github.com/ModuleLoader/es6-module-loader/wiki/Configuring-the-Loader).
1111
* Can be used as a [tracing tool](https://github.com/ModuleLoader/es6-module-loader/wiki/Tracing-API) for static analysis of modules.
@@ -28,18 +28,18 @@ For an example of a universal module loader based on this polyfill for loading A
2828

2929
### Getting Started
3030

31-
If using ES6 syntax (optional), include `traceur.js` or `6to5.js` in the page first then include `es6-module-loader.js`:
31+
If using ES6 syntax (optional), include `traceur.js` or `babel.js` in the page first then include `es6-module-loader.js`:
3232

3333
```html
3434
<script src="traceur.js"></script>
3535
<script src="es6-module-loader.js"></script>
3636
```
3737

38-
To use 6to5, set the transpiler to `6to5` with the loader configuration:
38+
To use Babel, set the transpiler to `babel` with the loader configuration:
3939

4040
```html
4141
<script>
42-
System.transpiler = '6to5';
42+
System.transpiler = 'babel';
4343
</script>
4444
```
4545

@@ -74,7 +74,7 @@ If using Traceur, these can be set with:
7474
System.traceurOptions = {...};
7575
```
7676

77-
Or with 6to5:
77+
Or with Babel:
7878

7979
```javascript
8080
System.to5Options = {...};
@@ -110,8 +110,8 @@ index.js:
110110
var System = require('es6-module-loader').System;
111111
/*
112112
* Include:
113-
* System.transpiler = '6to5';
114-
* to use 6to5 instead of Traceur
113+
* System.transpiler = 'babel';
114+
* to use Babel instead of Traceur
115115
*/
116116

117117
System.import('some-module').then(function(m) {
@@ -138,8 +138,8 @@ _Also, please don't edit files in the "dist" subdirectory as they are generated
138138
## Testing
139139

140140
- `npm run test:node` will use node to to run the tests
141-
- `npm run test:browser` will run `npm run test:browser-6to5` and `npm run test:browser-traceur`
142-
- `npm run test:browser-[transpiler]` use karma to run the tests with traceur or 6to5.
141+
- `npm run test:browser` will run `npm run test:browser-babel` and `npm run test:browser-traceur`
142+
- `npm run test:browser-[transpiler]` use karma to run the tests with Traceur or Babel.
143143
- `npm run test:browser:perf` will use karma to run benchmarks
144144

145145
`npm run test:browser-[transpiler]` supports options after a double dash (`--`) :

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,12 @@ function logloads(loads) {
381381
for (var i = 0, l = loader.loads.length; i < l; i++) {
382382
if (loader.loads[i].name == name) {
383383
existingLoad = loader.loads[i];
384+
385+
if(step == 'translate' && !existingLoad.source) {
386+
existingLoad.address = stepState.moduleAddress;
387+
proceedToTranslate(loader, existingLoad, Promise.resolve(stepState.moduleSource));
388+
}
389+
384390
return existingLoad.linkSets[0].done.then(function() {
385391
resolve(existingLoad);
386392
});
@@ -1100,7 +1106,7 @@ function logloads(loads) {
11001106
})();
11011107

11021108
/*
1103-
* Traceur and 6to5 transpile hook for Loader
1109+
* Traceur and Babel transpile hook for Loader
11041110
*/
11051111
(function(Loader) {
11061112
// Returns an array of ModuleSpecifiers
@@ -1112,17 +1118,17 @@ function logloads(loads) {
11121118

11131119
Loader.prototype.transpile = function(load) {
11141120
if (!transpiler) {
1115-
if (this.transpiler == '6to5') {
1116-
transpiler = to5Transpile;
1117-
transpilerModule = isNode ? require('6to5-core') : __global.to5;
1121+
if (this.transpiler == 'babel') {
1122+
transpiler = babelTranspile;
1123+
transpilerModule = isNode ? require('babel-core') : __global.babel;
11181124
}
11191125
else {
11201126
transpiler = traceurTranspile;
11211127
transpilerModule = isNode ? require('traceur') : __global.traceur;
11221128
}
11231129

11241130
if (!transpilerModule)
1125-
throw new TypeError('Include Traceur or 6to5 for module syntax support.');
1131+
throw new TypeError('Include Traceur or Babel for module syntax support.');
11261132
}
11271133

11281134
return 'var __moduleAddress = "' + load.address + '";' + transpiler.call(this, load);
@@ -1154,17 +1160,19 @@ function logloads(loads) {
11541160
}
11551161
}
11561162

1157-
function to5Transpile(load) {
1158-
var options = this.to5Options || {};
1163+
function babelTranspile(load) {
1164+
var options = this.babelOptions || {};
11591165
options.modules = 'system';
11601166
options.sourceMap = 'inline';
11611167
options.filename = load.address;
11621168
options.code = true;
11631169
options.ast = false;
1170+
options.blacklist = options.blacklist || [];
1171+
options.blacklist.push('react');
11641172

11651173
var source = transpilerModule.transform(load.source, options).code;
11661174

1167-
// add "!eval" to end of 6to5 sourceURL
1175+
// add "!eval" to end of Babel sourceURL
11681176
// I believe this does something?
11691177
return source + '\n//# sourceURL=' + load.address + '!eval';
11701178
}

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: 68 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ define(function() {
5252
this._async = async;
5353
this._running = false;
5454

55-
this._queue = new Array(1<<16);
55+
this._queue = this;
5656
this._queueLen = 0;
57-
this._afterQueue = new Array(1<<4);
57+
this._afterQueue = {};
5858
this._afterQueueLen = 0;
5959

6060
var self = this;
@@ -126,6 +126,7 @@ define(function(require) {
126126
var format = require('../format');
127127

128128
return function unhandledRejection(Promise) {
129+
129130
var logError = noop;
130131
var logInfo = noop;
131132
var localConsole;
@@ -345,6 +346,7 @@ define(function() {
345346
return function makePromise(environment) {
346347

347348
var tasks = environment.scheduler;
349+
var emitRejection = initEmitRejection();
348350

349351
var objectCreate = Object.create ||
350352
function(proto) {
@@ -811,7 +813,8 @@ define(function() {
811813

812814
Pending.prototype.run = function() {
813815
var q = this.consumers;
814-
var handler = this.join();
816+
var handler = this.handler;
817+
this.handler = this.handler.join();
815818
this.consumers = void 0;
816819

817820
for (var i = 0; i < q.length; ++i) {
@@ -973,6 +976,8 @@ define(function() {
973976
};
974977

975978
Rejected.prototype.fail = function(context) {
979+
this.reported = true;
980+
emitRejection('unhandledRejection', this);
976981
Promise.onFatalRejection(this, context === void 0 ? this.context : context);
977982
};
978983

@@ -982,9 +987,10 @@ define(function() {
982987
}
983988

984989
ReportTask.prototype.run = function() {
985-
if(!this.rejection.handled) {
990+
if(!this.rejection.handled && !this.rejection.reported) {
986991
this.rejection.reported = true;
987-
Promise.onPotentiallyUnhandledRejection(this.rejection, this.context);
992+
emitRejection('unhandledRejection', this.rejection) ||
993+
Promise.onPotentiallyUnhandledRejection(this.rejection, this.context);
988994
}
989995
};
990996

@@ -994,14 +1000,14 @@ define(function() {
9941000

9951001
UnreportTask.prototype.run = function() {
9961002
if(this.rejection.reported) {
997-
Promise.onPotentiallyUnhandledRejectionHandled(this.rejection);
1003+
emitRejection('rejectionHandled', this.rejection) ||
1004+
Promise.onPotentiallyUnhandledRejectionHandled(this.rejection);
9981005
}
9991006
};
10001007

10011008
// Unhandled rejection hooks
10021009
// By default, everything is a noop
10031010

1004-
// TODO: Better names: "annotate"?
10051011
Promise.createContext
10061012
= Promise.enterContext
10071013
= Promise.exitContext
@@ -1214,6 +1220,45 @@ define(function() {
12141220

12151221
function noop() {}
12161222

1223+
function initEmitRejection() {
1224+
/*global process, self, CustomEvent*/
1225+
if(typeof process !== 'undefined' && process !== null
1226+
&& typeof process.emit === 'function') {
1227+
// Returning falsy here means to call the default
1228+
// onPotentiallyUnhandledRejection API. This is safe even in
1229+
// browserify since process.emit always returns falsy in browserify:
1230+
// https://github.com/defunctzombie/node-process/blob/master/browser.js#L40-L46
1231+
return function(type, rejection) {
1232+
return type === 'unhandledRejection'
1233+
? process.emit(type, rejection.value, rejection)
1234+
: process.emit(type, rejection);
1235+
};
1236+
} else if(typeof self !== 'undefined' && typeof CustomEvent === 'function') {
1237+
return (function(noop, self, CustomEvent) {
1238+
var hasCustomEvent = false;
1239+
try {
1240+
var ev = new CustomEvent('unhandledRejection');
1241+
hasCustomEvent = ev instanceof CustomEvent;
1242+
} catch (e) {}
1243+
1244+
return !hasCustomEvent ? noop : function(type, rejection) {
1245+
var ev = new CustomEvent(type, {
1246+
detail: {
1247+
reason: rejection.value,
1248+
key: rejection
1249+
},
1250+
bubbles: false,
1251+
cancelable: true
1252+
});
1253+
1254+
return !self.dispatchEvent(ev);
1255+
};
1256+
}(noop, self, CustomEvent));
1257+
}
1258+
1259+
return noop;
1260+
}
1261+
12171262
return Promise;
12181263
};
12191264
});
@@ -1606,6 +1651,12 @@ function logloads(loads) {
16061651
for (var i = 0, l = loader.loads.length; i < l; i++) {
16071652
if (loader.loads[i].name == name) {
16081653
existingLoad = loader.loads[i];
1654+
1655+
if(step == 'translate' && !existingLoad.source) {
1656+
existingLoad.address = stepState.moduleAddress;
1657+
proceedToTranslate(loader, existingLoad, Promise.resolve(stepState.moduleSource));
1658+
}
1659+
16091660
return existingLoad.linkSets[0].done.then(function() {
16101661
resolve(existingLoad);
16111662
});
@@ -2325,7 +2376,7 @@ function logloads(loads) {
23252376
})();
23262377

23272378
/*
2328-
* Traceur and 6to5 transpile hook for Loader
2379+
* Traceur and Babel transpile hook for Loader
23292380
*/
23302381
(function(Loader) {
23312382
// Returns an array of ModuleSpecifiers
@@ -2337,17 +2388,17 @@ function logloads(loads) {
23372388

23382389
Loader.prototype.transpile = function(load) {
23392390
if (!transpiler) {
2340-
if (this.transpiler == '6to5') {
2341-
transpiler = to5Transpile;
2342-
transpilerModule = isNode ? require('6to5-core') : __global.to5;
2391+
if (this.transpiler == 'babel') {
2392+
transpiler = babelTranspile;
2393+
transpilerModule = isNode ? require('babel-core') : __global.babel;
23432394
}
23442395
else {
23452396
transpiler = traceurTranspile;
23462397
transpilerModule = isNode ? require('traceur') : __global.traceur;
23472398
}
23482399

23492400
if (!transpilerModule)
2350-
throw new TypeError('Include Traceur or 6to5 for module syntax support.');
2401+
throw new TypeError('Include Traceur or Babel for module syntax support.');
23512402
}
23522403

23532404
return 'var __moduleAddress = "' + load.address + '";' + transpiler.call(this, load);
@@ -2379,17 +2430,19 @@ function logloads(loads) {
23792430
}
23802431
}
23812432

2382-
function to5Transpile(load) {
2383-
var options = this.to5Options || {};
2433+
function babelTranspile(load) {
2434+
var options = this.babelOptions || {};
23842435
options.modules = 'system';
23852436
options.sourceMap = 'inline';
23862437
options.filename = load.address;
23872438
options.code = true;
23882439
options.ast = false;
2440+
options.blacklist = options.blacklist || [];
2441+
options.blacklist.push('react');
23892442

23902443
var source = transpilerModule.transform(load.source, options).code;
23912444

2392-
// add "!eval" to end of 6to5 sourceURL
2445+
// add "!eval" to end of Babel sourceURL
23932446
// I believe this does something?
23942447
return source + '\n//# sourceURL=' + load.address + '!eval';
23952448
}

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.13.1",
4+
"version": "0.14.0",
55
"homepage": "https://github.com/ModuleLoader/es6-module-loader",
66
"author": {
77
"name": "Guy Bedford, Luke Hoban, Addy Osmani",

0 commit comments

Comments
 (0)