跳至主要內容

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