@babel/plugin-transform-parameters
This plugin transforms ES2015 parameters to ES5, this includes:
- Destructuring parameters
- Default parameters
- Rest parameters
In
function test() {
var x =
var _ref = arguments[1];
var a = _ref.a,
b = _ref.b;
for (
var _len = arguments.length,
args = Array(_len > 2 ? _len - 2 : 0),
_key = 2;
_key++
) {
args[_key - 2] = arguments[_key];
}
}
Default parameters desugar into let
declarations to retain proper semantics. If this is not supported in your environment then you’ll need the @babel/plugin-transform-block-scoping plugin.
{
"plugins": ["@babel/plugin-transform-parameters"]
}
require("@babel/core").transformSync("code", {
});
boolean
, defaults to false
.
Under the ignoreFunctionLength
assumption, Babel will generate a more performant solution as JavaScript engines will fully optimize a function that doesn’t reference arguments
. Please do your own benchmarking and determine if this option is the right fit for your application.
// Spec behavior
function bar1(arg1 = 1) {}
bar1.length; // 0
// ignoreFunctionLength: true
function bar1(arg1 = 1) {}