Skip to content

Commit 58a2e68

Browse files
committed
Use babel-preset-node6 on Node.js 6 and higher
Less transpilation, better performance, better stack traces, and less dependencies \o/
1 parent b0b8b65 commit 58a2e68

File tree

8 files changed

+30
-23
lines changed

8 files changed

+30
-23
lines changed

docs/recipes/babelrc.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ There are multiple options for configuring how AVA transpiles your tests using B
1414

1515
## AVA's default transpiler behavior
1616

17-
By default, AVA transpiles your tests (and only your tests) using the [`es2015`](http://babeljs.io/docs/plugins/preset-es2015/) and [`stage-2`](http://babeljs.io/docs/plugins/preset-stage-2/) Babel presets. This is a great option for small modules where you do not desire a build step to transpile your source before deploying to `npm`.
17+
By default, AVA transpiles your tests (and only your tests) using the [`es2015-node4`](https://github.com/jbach/babel-preset-es2015-node4) on Node.js 4 or [`node6`](https://github.com/salakar/babel-preset-node6) on Node.js 6 and higher, and [`stage-2`](http://babeljs.io/docs/plugins/preset-stage-2/) Babel presets. This is a great option for small modules where you do not desire a build step to transpile your source before deploying to `npm`.
1818

1919
## Customizing how AVA transpiles your tests
2020

@@ -25,7 +25,7 @@ You can override the default Babel configuration AVA uses for test transpilation
2525
"ava": {
2626
"babel": {
2727
"plugins": ["rewire"],
28-
"presets": ["es2015", "stage-3"]
28+
"presets": ["es2015-node4", "stage-3"]
2929
}
3030
}
3131
}
@@ -43,7 +43,7 @@ To transpile your sources, you will need to define a [`babel config` ](http://ba
4343
"require": ["babel-register"]
4444
},
4545
"babel": {
46-
"presets": ["es2015"]
46+
"presets": ["es2015-node4"]
4747
}
4848
}
4949
```
@@ -63,12 +63,12 @@ Using the `"inherit"` shortcut will cause your tests to be transpiled the same a
6363
"babel": "inherit"
6464
},
6565
"babel": {
66-
"presets": ["es2015", "react"]
66+
"presets": ["es2015-node4", "react"]
6767
}
6868
}
6969
```
7070

71-
In the above example, both tests and sources will be transpiled using the [`es2015`](http://babeljs.io/docs/plugins/preset-es2015/) and [`react`](http://babeljs.io/docs/plugins/preset-react/) presets.
71+
In the above example, both tests and sources will be transpiled using the [`es2015-node4`](https://github.com/jbach/babel-preset-es2015-node4) and [`react`](http://babeljs.io/docs/plugins/preset-react/) presets.
7272

7373
## Extend your source transpilation configuration
7474

@@ -87,12 +87,12 @@ When specifying the Babel config for your tests, you can set the `babelrc` optio
8787
}
8888
},
8989
"babel": {
90-
"presets": ["es2015", "react"]
90+
"presets": ["es2015-node4", "react"]
9191
}
9292
}
9393
```
9494

95-
In the above example, *sources* are compiled use [`es2015`](http://babeljs.io/docs/plugins/preset-es2015/) and [`react`](http://babeljs.io/docs/plugins/preset-react/), *tests* use those same plugins, plus the additional `custom` plugins specified.
95+
In the above example, *sources* are compiled use [`es2015-node4`](https://github.com/jbach/babel-preset-es2015-node4) and [`react`](http://babeljs.io/docs/plugins/preset-react/), *tests* use those same plugins, plus the additional `custom` plugins specified.
9696

9797
## Extend an alternate config file.
9898

lib/babel-config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ function lazy(initFn) {
4040
}
4141

4242
const defaultPresets = lazy(() => {
43-
const esPreset = semver.satisfies(process.version, '>=4') ?
44-
'babel-preset-es2015-node4' :
45-
'babel-preset-es2015';
43+
const esPreset = semver.satisfies(process.version, '>=6') ?
44+
'babel-preset-node6' :
45+
'babel-preset-es2015-node4';
4646

4747
return [
4848
require('babel-preset-stage-2'),

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"test-win": "tap --no-cov --reporter=classic --timeout=150 test/*.js test/reporters/*.js",
4848
"visual": "node test/visual/run-visual-tests.js",
4949
"prepublish": "npm run make-ts",
50-
"make-ts": "babel-node --presets=babel-preset-es2015 --plugins=transform-runtime types/make.js"
50+
"make-ts": "babel-node --presets=babel-preset-es2015-node4 --plugins=transform-runtime types/make.js"
5151
},
5252
"files": [
5353
"lib",
@@ -99,8 +99,8 @@
9999
"babel-plugin-detective": "^2.0.0",
100100
"babel-plugin-espower": "^2.3.1",
101101
"babel-plugin-transform-runtime": "^6.15.0",
102-
"babel-preset-es2015": "^6.16.0",
103102
"babel-preset-es2015-node4": "^2.1.0",
103+
"babel-preset-node6": "^11.0.0",
104104
"babel-preset-stage-2": "^6.17.0",
105105
"babel-runtime": "^6.11.6",
106106
"bluebird": "^3.0.0",

test/api.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ function generateTests(prefix, apiCreator) {
666666

667667
var api = apiCreator({
668668
babelConfig: {
669-
presets: ['react', 'es2015', 'stage-2']
669+
presets: ['react', 'es2015-node4', 'stage-2']
670670
}
671671
});
672672

@@ -840,7 +840,7 @@ function generateTests(prefix, apiCreator) {
840840

841841
var api = apiCreator({
842842
babelConfig: {
843-
presets: ['es2015', 'stage-2'],
843+
presets: ['es2015-node4', 'stage-2'],
844844
plugins: [testCapitalizerPlugin]
845845
},
846846
cacheEnabled: false

test/babel-config.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test('uses babelConfig for babel options when babelConfig is an object', t => {
3535
});
3636

3737
const babelConfig = {
38-
presets: ['stage-2', 'es2015'],
38+
presets: ['stage-2', 'es2015-node4'],
3939
plugins: [customPlugin]
4040
};
4141

@@ -50,7 +50,7 @@ test('uses babelConfig for babel options when babelConfig is an object', t => {
5050
t.false(options.ast);
5151
t.true('inputSourceMap' in options);
5252
t.false(options.babelrc);
53-
t.strictDeepEqual(options.presets, ['stage-2', 'es2015']);
53+
t.strictDeepEqual(options.presets, ['stage-2', 'es2015-node4']);
5454
t.strictDeepEqual(options.plugins, [customPlugin, setup.powerAssert, throwsHelper, setup.rewrite, transformRuntime]);
5555
t.end();
5656
});
@@ -65,7 +65,7 @@ test('should reuse existing source maps', t => {
6565
});
6666

6767
const babelConfig = {
68-
presets: ['stage-2', 'es2015'],
68+
presets: ['stage-2', 'es2015-node4'],
6969
plugins: [customPlugin]
7070
};
7171

@@ -79,7 +79,7 @@ test('should reuse existing source maps', t => {
7979
t.true(options.sourceMaps);
8080
t.false(options.ast);
8181
t.true('inputSourceMap' in options);
82-
t.strictDeepEqual(options.presets, ['stage-2', 'es2015']);
82+
t.strictDeepEqual(options.presets, ['stage-2', 'es2015-node4']);
8383
t.strictDeepEqual(options.plugins, [customPlugin, setup.powerAssert, throwsHelper, setup.rewrite, transformRuntime]);
8484
t.end();
8585
});
@@ -94,7 +94,7 @@ test('should disable power-assert when powerAssert is false', t => {
9494
});
9595

9696
const babelConfig = {
97-
presets: ['stage-2', 'es2015'],
97+
presets: ['stage-2', 'es2015-node4'],
9898
plugins: [customPlugin]
9999
};
100100

test/fixture/babelrc/.alt-babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"presets": ["es2015", "stage-2"],
2+
"presets": ["es2015-node4", "stage-2"],
33
"plugins": ["../babel-plugin-foo-to-bar"]
44
}

test/fixture/babelrc/.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"presets": ["es2015", "stage-2"],
2+
"presets": ["es2015-node4", "stage-2"],
33
"plugins": ["../babel-plugin-test-doubler"]
44
}

test/fixture/babelrc/test.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
import test from '../../../'
1+
import test from '../../../';
22

3-
test('foo', t => t.pass());
3+
const fixture = [1, 2];
4+
5+
test('foo', t => {
6+
// using destructuring to ensure it transpiles on Node.js 4
7+
// since that is a Node.js 6 feature
8+
const [one, two] = fixture;
9+
t.pass();
10+
});

0 commit comments

Comments
 (0)