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

Commit dc6c3cd

Browse files
committed
promises update, spec fixes, 0.7.0 prep
1 parent 5e96be9 commit dc6c3cd

13 files changed

+1370
-768
lines changed

Gruntfile.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@ module.exports = function (grunt) {
2121
concat: {
2222
dist: {
2323
src: [
24-
'node_modules/es6-promise/dist/promise-1.0.0.js',
25-
'lib/module.js',
24+
// 'node_modules/rsvp/dist/rsvp.js',
25+
'node_modules/when/es6-shim/Promise.js',
2626
'lib/loader.js',
2727
'lib/system.js'
2828
],
2929
dest: 'dist/<%= pkg.name %>.js'
3030
},
3131
polyfillOnly: {
3232
src: [
33-
'lib/module.js',
3433
'lib/loader.js',
3534
'lib/system.js'
3635
],

LICENSE-MIT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2013 Guy Bedford, Luke Hoban, Addy Osmani
1+
Copyright (c) 2013-2014 Guy Bedford, Luke Hoban, Addy Osmani
22

33
Permission is hereby granted, free of charge, to any person
44
obtaining a copy of this software and associated documentation

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22

33
Dynamically loads ES6 modules in NodeJS and current browsers.
44

5-
* Implemented exactly to the April 27 2014 ES6 specification draft.
5+
* Implemented exactly to the May 22 2014 ES6 specification draft.
66
* Provides an asynchronous loader (`System.import`) to [dynamically load ES6 modules](#basic-use).
77
* Uses [Traceur](https://github.com/google/traceur-compiler) for compiling ES6 modules and syntax into ES5 in the browser with source map support.
88
* Fully supports [ES6 circular references and bindings](#circular-references--bindings).
99
* Polyfills ES6 Promises in the browser with a bundled [es6-promise](https://github.com/jakearchibald/es6-promise) implementation.
1010
* [Compatible with NodeJS](#nodejs-usage) allowing for server-side module loading and tracing extensions.
1111
* Supports ES6 module loading in IE9+, and dynamic module formats in IE8+.
12-
* The complete combined polyfill comes to 7KB minified and gzipped, making it suitable for production use, provided that modules are [built into ES5 making them independent of Traceur](#moving-to-production).
12+
* The complete combined polyfill comes to 8.7KB minified and gzipped, making it suitable for production use, provided that modules are [built into ES5 making them independent of Traceur](#moving-to-production).
1313

1414
For an overview of build workflows, [see the production guide](#moving-to-production).
1515

1616
See the [demo folder](https://github.com/ModuleLoader/es6-module-loader/blob/master/demo/index.html) in this repo for a working example demonstrating both module loading the module tag in the browser.
1717

1818
For an example of a universal module loader based on this polyfill for loading AMD, CommonJS and globals, see [SystemJS](https://github.com/systemjs/systemjs).
1919

20-
_The current version is tested against **[Traceur 0.0.42](https://github.com/google/traceur-compiler/tree/0.0.42)**._
20+
_The current version is tested against **[Traceur 0.0.45](https://github.com/google/traceur-compiler/tree/0.0.45)**._
2121

2222
_Note the ES6 module specification is still in draft, and subject to change._
2323

2424
### Basic Use
2525

26-
Download both [es6-module-loader.js](https://raw.githubusercontent.com/ModuleLoader/es6-module-loader/v0.6.0/dist/es6-module-loader.js) and [traceur.js](https://raw.githubusercontent.com/google/traceur-compiler/traceur@0.0.42/bin/traceur.js) into the same folder.
26+
Download both [es6-module-loader.js](https://raw.githubusercontent.com/ModuleLoader/es6-module-loader/v0.7.0/dist/es6-module-loader.js) and [traceur.js](https://raw.githubusercontent.com/jmcriffey/bower-traceur/0.0.45/traceur.js) into the same folder.
2727

2828
If using ES6 syntax (optional), include `traceur.js` in the page first then include `es6-module-loader.js`:
2929

@@ -181,7 +181,7 @@ A basic example of using this extension with a build would be the following:
181181
traceur --out app-build.js app/app.js --modules=instantiate
182182
```
183183

184-
2. If using additional ES6 features apart from modules syntax, load `traceur-runtime.js` (included in the `bin` folder when installing Traceur through Bower or npm). Then include `es6-module-loader.js` and then apply the register extension before doing the import or loading the bundle as a script:
184+
2. If using additional ES6 features apart from modules syntax, load [`traceur-runtime.js`](https://raw.githubusercontent.com/jmcriffey/bower-traceur/0.0.45/traceur-runtime.js) (also included in the `bin` folder when installing Traceur through Bower or npm). Then include `es6-module-loader.js` and then apply the register extension before doing the import or loading the bundle as a script:
185185

186186
```html
187187
<script src="traceur-runtime.js"></script>
@@ -208,6 +208,9 @@ A basic example of using this extension with a build would be the following:
208208
</script>
209209
```
210210

211+
* Note that `app-build.js` must be at the base-level for this to work.
212+
* Also, the name we import, `app/app` must be the same name given to Traceur's compiler.
213+
211214
#### Building into separate files
212215

213216
We can also build separate files with:
@@ -224,7 +227,7 @@ With the above, we can load from the separate files identical to loading ES6.
224227
npm install es6-module-loader
225228
```
226229

227-
For use in NodeJS, the `Module`, `LoaderPolyfill` and `System` globals are provided as exports:
230+
For use in NodeJS, the `Loader` and `System` globals are provided as exports:
228231

229232
index.js:
230233
```javascript

bower.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
{
22
"name": "es6-module-loader",
3-
"version": "0.6.1",
3+
"version": "0.7.0",
44
"description": "An ES6 Module Loader polyfill based on the latest spec.",
55
"homepage": "https://github.com/ModuleLoader/es6-module-loader",
66
"main": "dist/es6-module-loader-sans-promises.js",
77
"dependencies": {
8-
"es6-promise": "^1.0",
9-
"traceur": "0.0.41"
8+
"traceur": "0.0.45"
109
},
1110
"keywords": [
1211
"es6",

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

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function logloads(loads) {
105105

106106
(function (__global) {
107107
(function() {
108-
var Promise = __global.Promise || require('es6-promise').Promise;
108+
var Promise = __global.Promise || require('when/es6-shim/Promise');
109109

110110
var traceur;
111111

@@ -566,7 +566,8 @@ function logloads(loads) {
566566
link(linkSet);
567567
}
568568
catch(exc) {
569-
return linkSetFailed(linkSet, exc);
569+
linkSetFailed(linkSet, exc);
570+
return true;
570571
}
571572
}
572573

@@ -593,10 +594,10 @@ function logloads(loads) {
593594
for (var i = 0; i < loads.length; i++) {
594595
var load = loads[i];
595596
load.module = load.kind == 'dynamic' ? {
596-
module: Module({})
597+
module: _newModule({})
597598
} : {
598599
name: load.name,
599-
module: Module({}),
600+
module: _newModule({}),
600601
evaluated: true
601602
};
602603
load.status = 'linked';
@@ -606,7 +607,10 @@ function logloads(loads) {
606607
}
607608
/***/
608609

609-
doLink(linkSet);
610+
var abrupt = doLink(linkSet);
611+
612+
if (abrupt)
613+
return;
610614

611615
console.assert(linkSet.loads.length == 0, 'loads cleared');
612616

@@ -762,7 +766,7 @@ function logloads(loads) {
762766
// 15.2.5.6 LinkDynamicModules adjusted
763767
else {
764768
var module = load.execute();
765-
if (!module || !(module instanceof ModuleConstructor))
769+
if (!module || !(module instanceof Module))
766770
throw new TypeError('Execution must define a Module instance');
767771
load.module = {
768772
module: module
@@ -864,6 +868,7 @@ function logloads(loads) {
864868
// 15.2.6.1
865869
function evaluateLoadedModule(loader, load) {
866870
console.assert(load.status == 'linked', 'is linked ' + load.name);
871+
867872
ensureEvaluated(load.module, [], loader);
868873
return load.module.module;
869874
}
@@ -877,6 +882,19 @@ function logloads(loads) {
877882
*
878883
*/
879884

885+
// execution errors don't propogate in the pipeline
886+
// see https://bugs.ecmascript.org/show_bug.cgi?id=2993
887+
function doExecute(module) {
888+
try {
889+
module.execute.call(__global);
890+
}
891+
catch(e) {
892+
setTimeout(function() {
893+
throw e;
894+
});
895+
}
896+
}
897+
880898
// 15.2.6.2 EnsureEvaluated adjusted
881899
function ensureEvaluated(module, seen, loader) {
882900
if (module.evaluated || !module.dependencies)
@@ -896,8 +914,8 @@ function logloads(loads) {
896914
return;
897915

898916
module.evaluated = true;
899-
module.execute.call(__global);
900-
module.module = Module(module.exports);
917+
doExecute(module);
918+
module.module = _newModule(module.exports);
901919
delete module.execute;
902920
}
903921

@@ -935,7 +953,7 @@ function logloads(loads) {
935953
// 26.3.3.13 realm not implemented
936954
}
937955

938-
function ModuleConstructor() {}
956+
function Module() {}
939957

940958
// importPromises adds ability to import a module twice without error - https://bugs.ecmascript.org/show_bug.cgi?id=2601
941959
var importPromises = {};
@@ -995,7 +1013,7 @@ function logloads(loads) {
9951013

9961014
if (loader.modules[name]) {
9971015
ensureEvaluated(loader.modules[name], [], loader._loader);
998-
return Promise.resolve(loader.modules[name].module);
1016+
return loader.modules[name].module;
9991017
}
10001018

10011019
return importPromises[name] || createImportPromise(name,
@@ -1034,8 +1052,8 @@ function logloads(loads) {
10341052
throw new TypeError('Expected object');
10351053

10361054
// we do this to be able to tell if a module is a module privately in ES5
1037-
// by doing m instanceof ModuleConstructor
1038-
var m = new ModuleConstructor();
1055+
// by doing m instanceof Module
1056+
var m = new Module();
10391057

10401058
for (var key in obj) {
10411059
(function (key) {
@@ -1056,7 +1074,7 @@ function logloads(loads) {
10561074
},
10571075
// 26.3.3.14
10581076
set: function(name, module) {
1059-
if (!(module instanceof ModuleConstructor))
1077+
if (!(module instanceof Module))
10601078
throw new TypeError('Set must be a module');
10611079
this._loader.modules[name] = {
10621080
module: module
@@ -1087,15 +1105,14 @@ function logloads(loads) {
10871105
}
10881106
};
10891107

1090-
var Module = Loader.prototype.newModule;
1108+
var _newModule = Loader.prototype.newModule;
10911109

10921110
if (typeof exports === 'object')
10931111
module.exports = Loader;
10941112

10951113
__global.Reflect = __global.Reflect || {};
10961114
__global.Reflect.Loader = __global.Reflect.Loader || Loader;
10971115
__global.LoaderPolyfill = Loader;
1098-
__global.Module = Module;
10991116

11001117
})();
11011118

0 commit comments

Comments
 (0)