Skip to content

Commit 2357832

Browse files
authored
Merge pull request #31 from MatAtBread/6.1.3-spec-option
6.1.3 spec option
2 parents 57673a4 + 600cadc commit 2357832

File tree

6 files changed

+35
-9
lines changed

6 files changed

+35
-9
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ With options:
5757
}
5858
```
5959

60+
The option `spec` sets the compiler up to produce the most spec-compatible output (at the expense of some performance) by using the `wrapAwait`, `noRuntime` and `promises` options. Since `noRuntime` is specified, no runtime options are required.
61+
62+
```js
63+
{
64+
"plugins": [
65+
["fast-async", {
66+
"spec":true
67+
}]
68+
]
69+
}
70+
```
71+
72+
6073
Test
6174
----
6275
From the installation directory (e.g. node_modules/fast-async):

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "fast-async",
3-
"version": "6.1.2",
3+
"version": "6.2.0",
44
"dependencies": {
5-
"nodent": ">=2.6.12"
5+
"nodent": ">=3.0.8"
66
},
77
"description": "fast-async/await transformer Babel plugin",
88
"main": "plugin.js",

plugin.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,18 @@ module.exports = function (babel) {
5858
compiler = nodent(envOpts);
5959
compilerOpts = compiler.parseCompilerOptions('"use nodent-promises";', compiler.log);
6060

61-
if (state.opts.compiler && typeof state.opts.compiler==="object") {
62-
Object.keys(state.opts.compiler).forEach(function(k){
63-
compilerOpts[k] = state.opts.compiler[k] ;
61+
var defCompilerOpts = state.opts.compiler ;
62+
if (state.opts.spec) {
63+
defCompilerOpts = {
64+
promises:true,
65+
wrapAwait:true,
66+
noRuntime:true
67+
}
68+
}
69+
70+
if (defCompilerOpts && typeof defCompilerOpts==="object") {
71+
Object.keys(defCompilerOpts).forEach(function(k){
72+
compilerOpts[k] = defCompilerOpts[k] ;
6473
}) ;
6574
}
6675
compilerOpts.babelTree = true;

tests/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
[
2323
"..",
2424
{
25-
"runtimePattern": "test-input\\.js",
26-
"useRuntimeModule": true
25+
"spec":true
2726
}
2827
]
2928
]

tests/test-cli.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node node_modules/babel-cli/bin/babel.js test-input.js

tests/test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ try {
2525
console.log("\nNB:The timings here are only indicative. GC and poor sampling generate variable results. More detailed performance tests can be found in "+"nodent".cyan+"\nStarting tests...");
2626

2727
var nodent = require('nodent') ;
28-
global.Promise = global.Promise || nodent.EagerThenable() ;
28+
var systemPromise = global.Promise || nodent.EagerThenable() ;
29+
30+
global.Promise = nodent.EagerThenable() ;
2931

3032
var testCode = require('fs').readFileSync(__dirname+'/test-input.js').toString() ;
3133

3234
var eagerName = 'fast-async (nodent-'+nodent.EagerThenable().name+')' ;
3335
var transformers = {
34-
'fast-async (es7-lazy)': {plugins:[[require('../plugin.js'),{runtimePatten:'directive',compiler:{promises:false,es7:true,lazyThenables:true}}]]},
36+
'fast-async (es7-lazy)': {plugins:[[require('../plugin.js'),{runtimePatten:'directive',compiler:{promises:false,es7:true,lazyThenables:true}}]]},
37+
'fast-async (spec:true)': {plugins:[[require('../plugin.js'),{runtimePatten:null,compiler:{promises:true,es7:true,noRuntime:true,wrapAwait:true}}]]},
3538
};
3639
transformers[eagerName] = {plugins:[[require('../plugin.js'),{runtimePatten:'directive',compiler:{promises:false,es7:true,lazyThenables:false}}]]} ;
3740

@@ -78,6 +81,7 @@ function loadRegenerator(){
7881
} catch (path) {
7982
global.regeneratorRuntime = require("./"+path);
8083
console.log("Loaded regenerator runtime from "+path+" ",regeneratorRuntime.toString().yellow) ;
84+
global.Promise = systemPromise ;
8185
}
8286
}
8387

0 commit comments

Comments
 (0)