!((
input,
processed = {
foo: 1,
...input
}
) => {
window.console.log(processed)
})({
bar: 2 // input configuration
})
gets minified to:
((t, e = {
foo: 1,
bar: 2
}) => {
window.console.log(e);
})();
I need that input
parameter for later configuration
Question: How to maintain the original pattern?
Terser output I need:
((t, e = {
foo: 1,
...t
}) => {
window.console.log(e);
})({bar: 2});
let input1 = { bar:2 }
!((
input,
processed = {
foo: 1,
...input
}
) => {
window.console.log(processed)
})( input1 )
outputs:
((t, e = {
foo: 1,
...t
}) => {
window.console.log(e);
})({
bar: 2
});
Terser will take care of the current version of your code. Right now, you are passing a constant parameter to a function, so terser can just inline it preventing the creation of intermediate objects.
If in the future you change this parameter inside (for primitive values) or outside the function (for objects) the function, terser should recognize that and not inline anymore.
Surprisingly the already declaring the parameter as a variable seems to give the proper hint to terser, as discovered by OP:
let input1 = { bar:2 }
!((
input,
processed = {
foo: 1,
...input
}
) => {
window.console.log(processed)
})( input1 )
will result in
((t, e = {
foo: 1,
...t
}) => {
window.console.log(e);
})({
bar: 2
});