Skip to content

Commit 69001a4

Browse files
tobiaslinsjaredpalmer
authored andcommitted
exclude async transfrom if already supported (#87)
1 parent 5fa5008 commit 69001a4

File tree

1 file changed

+45
-25
lines changed

1 file changed

+45
-25
lines changed

packages/babel-preset-backpack/index.js

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ const path = require('path')
22

33
const preset = {
44
presets: [
5-
[require('babel-preset-env').default, {
6-
target: {
7-
node: 'current'
8-
},
9-
// Webpack takes care of modules, so we don't have to.
10-
modules: false
11-
}]
5+
[
6+
require('babel-preset-env').default,
7+
{
8+
target: {
9+
node: 'current'
10+
},
11+
// Webpack takes care of modules, so we don't have to.
12+
modules: false
13+
}
14+
]
1215
],
1316
plugins: [
1417
// class { handleThing = () => { } }
@@ -17,40 +20,57 @@ const preset = {
1720
// The following two plugins use Object.assign directly, instead of Babel's
1821
// extends helper. Note that this assumes `Object.assign` is available.
1922
// { ...todo, completed: true }
20-
[require.resolve('babel-plugin-transform-object-rest-spread'), {
21-
useBuiltIns: true
22-
}],
23-
24-
[require.resolve('babel-plugin-transform-regenerator'), {
25-
// Async functions are converted to generators by babel-preset-env (which
26-
// is based on babel-preset-latest)
27-
async: false
28-
}],
23+
[
24+
require.resolve('babel-plugin-transform-object-rest-spread'),
25+
{
26+
useBuiltIns: true
27+
}
28+
],
2929

30+
[
31+
require.resolve('babel-plugin-transform-regenerator'),
32+
{
33+
// Async functions are converted to generators by babel-preset-env (which
34+
// is based on babel-preset-latest)
35+
async: false
36+
}
37+
],
3038

3139
// This is so we don't need to add `babel-polyfill` to our webpack `entry`.
3240
// Unlike `babel-polyfill`, `babel-runtime` + the transform do not pollute
3341
// the global namespace. Yay.
3442
// @see https://medium.com/@jcse/clearing-up-the-babel-6-ecosystem-c7678a314bf3#.7j10g8yn0
35-
[require.resolve('babel-plugin-transform-runtime'), {
36-
helpers: false,
37-
polyfill: false,
38-
regenerator: true,
39-
// Resolve the Babel runtime relative to the config.
40-
moduleName: path.dirname(require.resolve('babel-runtime/package'))
41-
}]
43+
[
44+
require.resolve('babel-plugin-transform-runtime'),
45+
{
46+
helpers: false,
47+
polyfill: false,
48+
regenerator: true,
49+
// Resolve the Babel runtime relative to the config.
50+
moduleName: path.dirname(require.resolve('babel-runtime/package'))
51+
}
52+
]
4253
]
4354
}
4455

56+
const v = process.versions.node.split('.')
57+
if ((v[0] >= 7 && v[1] >= 6) || v[0] >= 8) {
58+
preset.presets[0].exclude = [
59+
'babel-plugin-transform-regenerator',
60+
'transform-async-to-generator'
61+
]
62+
}
4563
if (process.env.NODE_ENV === 'test' || process.env.BABEL_ENV === 'test') {
4664
preset.plugins.push.apply(preset.plugins, [
4765
// We always include this plugin regardless of environment
4866
// because of a Babel bug that breaks object rest/spread without it:
4967
// https://github.com/babel/babel/issues/4851
5068
require.resolve('babel-plugin-transform-es2015-parameters'),
51-
5269
// Jest needs this to work properly with import/export syntax
53-
[require.resolve('babel-plugin-transform-es2015-modules-commonjs'), {loose: true}]
70+
[
71+
require.resolve('babel-plugin-transform-es2015-modules-commonjs'),
72+
{ loose: true }
73+
]
5474
])
5575
}
5676

0 commit comments

Comments
 (0)