babel-plugin-syntax-throw-expressions
Allow parsing of Throw Expressions:
function test(param = throw new Error('required!')) {
const test = param === true || throw new Error('Falsey!');
}
Installation
npm install --save-dev @babel/plugin-syntax-throw-expressions
Usage
Via .babelrc (Recommended)
.babelrc
{
"plugins": ["syntax-throw-expressions"]
}
Via CLI
babel --plugins syntax-throw-expressions script.js
Via Node API
require("@babel/core").transform("code", {
plugins: ["syntax-throw-expressions"]
});