跳至主要内容

@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 install --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"],
});