@babel/plugin-transform-block-scoped-functions
信息
此插件包含在 @babel/preset-env
中
示例
输入
JavaScript
{
function name(n) {
return n;
}
}
name("Steve");
输出
JavaScript
{
let name = function(n) {
return n;
};
}
name("Steve");
安装
- npm
- Yarn
- pnpm
npm install --save-dev @babel/plugin-transform-block-scoped-functions
yarn add --dev @babel/plugin-transform-block-scoped-functions
pnpm add --save-dev @babel/plugin-transform-block-scoped-functions
用法
使用配置文件(推荐)
babel.config.json
{
"plugins": ["@babel/plugin-transform-block-scoped-functions"]
}
通过 CLI
Shell
babel --plugins @babel/plugin-transform-block-scoped-functions script.js
通过 Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-transform-block-scoped-functions"],
});