From 5158ac8bb0d0a79acde12c1bf6dfc1bbf32fd71e Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 22 Nov 2016 20:21:16 +0700 Subject: [PATCH] Use `babel-preset-node6` on Node.js 6 and higher Less transpilation, better performance, better stack traces, and less dependencies \o/ --- docs/recipes/babelrc.md | 14 +++++++------- lib/babel-config.js | 6 +++--- package.json | 4 ++-- test/api.js | 4 ++-- test/babel-config.js | 10 +++++----- test/fixture/babelrc/.alt-babelrc | 2 +- test/fixture/babelrc/.babelrc | 2 +- test/fixture/babelrc/test.js | 11 +++++++++-- 8 files changed, 30 insertions(+), 23 deletions(-) diff --git a/docs/recipes/babelrc.md b/docs/recipes/babelrc.md index 9784098e9..2973f6fe1 100644 --- a/docs/recipes/babelrc.md +++ b/docs/recipes/babelrc.md @@ -14,7 +14,7 @@ There are multiple options for configuring how AVA transpiles your tests using B ## AVA's default transpiler behavior -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`. +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`. ## Customizing how AVA transpiles your tests @@ -25,7 +25,7 @@ You can override the default Babel configuration AVA uses for test transpilation "ava": { "babel": { "plugins": ["rewire"], - "presets": ["es2015", "stage-3"] + "presets": ["es2015-node4", "stage-3"] } } } @@ -43,7 +43,7 @@ To transpile your sources, you will need to define a [`babel config` ](http://ba "require": ["babel-register"] }, "babel": { - "presets": ["es2015"] + "presets": ["es2015-node4"] } } ``` @@ -63,12 +63,12 @@ Using the `"inherit"` shortcut will cause your tests to be transpiled the same a "babel": "inherit" }, "babel": { - "presets": ["es2015", "react"] + "presets": ["es2015-node4", "react"] } } ``` -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. +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. ## Extend your source transpilation configuration @@ -87,12 +87,12 @@ When specifying the Babel config for your tests, you can set the `babelrc` optio } }, "babel": { - "presets": ["es2015", "react"] + "presets": ["es2015-node4", "react"] } } ``` -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. +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. ## Extend an alternate config file. diff --git a/lib/babel-config.js b/lib/babel-config.js index faf7982e9..962e1da97 100644 --- a/lib/babel-config.js +++ b/lib/babel-config.js @@ -40,9 +40,9 @@ function lazy(initFn) { } const defaultPresets = lazy(() => { - const esPreset = semver.satisfies(process.version, '>=4') ? - 'babel-preset-es2015-node4' : - 'babel-preset-es2015'; + const esPreset = semver.satisfies(process.version, '>=6') ? + 'babel-preset-node6' : + 'babel-preset-es2015-node4'; return [ require('babel-preset-stage-2'), diff --git a/package.json b/package.json index 069f2ce1b..5f514c53e 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "test-win": "tap --no-cov --reporter=classic --timeout=150 test/*.js test/reporters/*.js", "visual": "node test/visual/run-visual-tests.js", "prepublish": "npm run make-ts", - "make-ts": "babel-node --presets=babel-preset-es2015 --plugins=transform-runtime types/make.js" + "make-ts": "babel-node --presets=babel-preset-es2015-node4 --plugins=transform-runtime types/make.js" }, "files": [ "lib", @@ -99,8 +99,8 @@ "babel-plugin-detective": "^2.0.0", "babel-plugin-espower": "^2.3.1", "babel-plugin-transform-runtime": "^6.15.0", - "babel-preset-es2015": "^6.16.0", "babel-preset-es2015-node4": "^2.1.0", + "babel-preset-node6": "^11.0.0", "babel-preset-stage-2": "^6.17.0", "babel-runtime": "^6.11.6", "bluebird": "^3.0.0", diff --git a/test/api.js b/test/api.js index e9a9b3186..3df118f5d 100644 --- a/test/api.js +++ b/test/api.js @@ -666,7 +666,7 @@ function generateTests(prefix, apiCreator) { var api = apiCreator({ babelConfig: { - presets: ['react', 'es2015', 'stage-2'] + presets: ['react', 'es2015-node4', 'stage-2'] } }); @@ -840,7 +840,7 @@ function generateTests(prefix, apiCreator) { var api = apiCreator({ babelConfig: { - presets: ['es2015', 'stage-2'], + presets: ['es2015-node4', 'stage-2'], plugins: [testCapitalizerPlugin] }, cacheEnabled: false diff --git a/test/babel-config.js b/test/babel-config.js index 4ac1f9623..db54a053f 100644 --- a/test/babel-config.js +++ b/test/babel-config.js @@ -35,7 +35,7 @@ test('uses babelConfig for babel options when babelConfig is an object', t => { }); const babelConfig = { - presets: ['stage-2', 'es2015'], + presets: ['stage-2', 'es2015-node4'], plugins: [customPlugin] }; @@ -50,7 +50,7 @@ test('uses babelConfig for babel options when babelConfig is an object', t => { t.false(options.ast); t.true('inputSourceMap' in options); t.false(options.babelrc); - t.strictDeepEqual(options.presets, ['stage-2', 'es2015']); + t.strictDeepEqual(options.presets, ['stage-2', 'es2015-node4']); t.strictDeepEqual(options.plugins, [customPlugin, setup.powerAssert, throwsHelper, setup.rewrite, transformRuntime]); t.end(); }); @@ -65,7 +65,7 @@ test('should reuse existing source maps', t => { }); const babelConfig = { - presets: ['stage-2', 'es2015'], + presets: ['stage-2', 'es2015-node4'], plugins: [customPlugin] }; @@ -79,7 +79,7 @@ test('should reuse existing source maps', t => { t.true(options.sourceMaps); t.false(options.ast); t.true('inputSourceMap' in options); - t.strictDeepEqual(options.presets, ['stage-2', 'es2015']); + t.strictDeepEqual(options.presets, ['stage-2', 'es2015-node4']); t.strictDeepEqual(options.plugins, [customPlugin, setup.powerAssert, throwsHelper, setup.rewrite, transformRuntime]); t.end(); }); @@ -94,7 +94,7 @@ test('should disable power-assert when powerAssert is false', t => { }); const babelConfig = { - presets: ['stage-2', 'es2015'], + presets: ['stage-2', 'es2015-node4'], plugins: [customPlugin] }; diff --git a/test/fixture/babelrc/.alt-babelrc b/test/fixture/babelrc/.alt-babelrc index 3b58de6e4..cc5c5f72f 100644 --- a/test/fixture/babelrc/.alt-babelrc +++ b/test/fixture/babelrc/.alt-babelrc @@ -1,4 +1,4 @@ { - "presets": ["es2015", "stage-2"], + "presets": ["es2015-node4", "stage-2"], "plugins": ["../babel-plugin-foo-to-bar"] } diff --git a/test/fixture/babelrc/.babelrc b/test/fixture/babelrc/.babelrc index 02ef3bce8..0e88723b6 100644 --- a/test/fixture/babelrc/.babelrc +++ b/test/fixture/babelrc/.babelrc @@ -1,4 +1,4 @@ { - "presets": ["es2015", "stage-2"], + "presets": ["es2015-node4", "stage-2"], "plugins": ["../babel-plugin-test-doubler"] } diff --git a/test/fixture/babelrc/test.js b/test/fixture/babelrc/test.js index c472597f0..f968e1068 100644 --- a/test/fixture/babelrc/test.js +++ b/test/fixture/babelrc/test.js @@ -1,3 +1,10 @@ -import test from '../../../' +import test from '../../../'; -test('foo', t => t.pass()); +const fixture = [1, 2]; + +test('foo', t => { + // using destructuring to ensure it transpiles on Node.js 4 + // since that is a Node.js 6 feature + const [one, two] = fixture; + t.pass(); +});