babel-preset-njs
Advanced tools
Comparing version 0.1.2 to 0.2.0
25
index.js
@@ -28,5 +28,24 @@ const { declare } = require('@babel/helper-plugin-utils') | ||
const asyncHelpersValues = ['external', 'local', 'inline'] | ||
const bundlers = [ | ||
'@rollup/plugin-babel', | ||
'babel-loader', // webpack | ||
] | ||
module.exports = declare((api, opts) => { | ||
api.assertVersion(7) | ||
const callerName = api.caller(c => c.name) | ||
const asyncHelpers = v.validateStringOption( | ||
'asyncHelpers', | ||
opts.asyncHelpers, | ||
bundlers.includes(callerName) ? 'external' : 'local', | ||
) | ||
if (!asyncHelpersValues.includes(asyncHelpers)) { | ||
const allowedValues = asyncHelpersValues.map(x => `'${x}'`).join(', ') | ||
throw Error(`'asyncHelpers' option must be one of: ${allowedValues}, but given: '${asyncHelpers}'`) | ||
} | ||
const assumeArrayIterables = v.validateBooleanOption( | ||
@@ -130,5 +149,9 @@ 'assumeArrayIterables', | ||
// calls with use of minimal helper functions. | ||
[transformAsyncToPromises], | ||
[transformAsyncToPromises, { | ||
target: 'es6', | ||
externalHelpers: asyncHelpers === 'external', | ||
inlineHelpers: asyncHelpers === 'inline', | ||
}], | ||
], | ||
} | ||
}) |
{ | ||
"name": "babel-preset-njs", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "A Babel preset for njs - NGINX JavaScript.", | ||
@@ -5,0 +5,0 @@ "author": "Jakub Jirutka <jakub@jirutka.cz>", |
@@ -56,3 +56,3 @@ A [Babel](https://babeljs.io) | ||
Assume that all iterables used in `for…of` loops, [array spread | ||
Assume that all iterables used in `for...of` loops, [array spread | ||
syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#Spread_in_array_literals) | ||
@@ -79,2 +79,26 @@ and [array | ||
### `asyncHelpers` | ||
`'external'`, `'local'`, `'inline'` | ||
Toggles how | ||
[async-to-promises](https://github.com/rpetrich/babel-plugin-transform-async-to-promises) | ||
injects its helpers: | ||
- `'external'` — injects import from | ||
`babel-plugin-transform-async-to-promises/helpers` into each file | ||
with async/await | ||
- `'local'` — injects the needed helper functions into each file with | ||
async/await | ||
- `'inline'` — inlines the needed helper code in place of each | ||
occurrence of async/await | ||
Defaults to `'external'` if Rollup or webpack is detected, otherwise | ||
`'local'`. | ||
- [async-to-promises](https://github.com/rpetrich/babel-plugin-transform-async-to-promises): | ||
`externalHelpers`, `inlineHelpers` | ||
### `looseClasses` | ||
@@ -133,3 +157,3 @@ | ||
The list of included Babel plugins is available | ||
[here](https://github.com/jirutka/babel-preset-njs/blob/v0.1.2/README.adoc#plugins). | ||
[here](https://github.com/jirutka/babel-preset-njs/blob/v0.2.0/README.adoc#plugins). | ||
@@ -136,0 +160,0 @@ ## References |
Sorry, the diff of this file is not supported yet
25416
142
166