@babel/plugin-proposal-throw-expressions
示例
JavaScript
function test(param = throw new Error("required!")) {
const test = param === true || throw new Error("Falsy!");
}
安装
- 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
用法
使用配置文件(推荐)
babel.config.json
{
"plugins": ["@babel/plugin-proposal-throw-expressions"]
}
通过 CLI
Shell
babel --plugins @babel/plugin-proposal-throw-expressions script.js
通过 Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-proposal-throw-expressions"],
});