@babel/plugin-proposal-throw-expressions
Example
JavaScript
function test(param = throw new Error("required!")) {
const test = param === true || throw new Error("Falsy!");
}
Installation
- npm
- Yarn
- pnpm
npm install --save-dev @babel/plugin-proposal-throw-expressions
yarn add --dev @babel/plugin-proposal-throw-expressions
pnpm add --save-dev @babel/plugin-proposal-throw-expressions
Usage
With a configuration file (Recommended)
babel.config.json
{
"plugins": ["@babel/plugin-proposal-throw-expressions"]
}
Via CLI
Shell
babel --plugins @babel/plugin-proposal-throw-expressions script.js
Via Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-proposal-throw-expressions"],
});