0
!((
    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});

Update after comment:

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
});
Danny '365CSI' Engelman
  • 16,526
  • 2
  • 32
  • 49
  • 1
    Shoudnt terser take care of whatever you do, when you do it? From the current code, there is just a constant passed as parameter and terser is inlining that. If in the future you change this parameter inside the function, terser should recognize that and not inline anymore. (Remember that the spread operator does a shallow copy, anyways. So changes would need to happen in nested objects to be reflected in both `input` and `processed` parameters.) – Sirko Mar 12 '20 at 09:42
  • Tnx, that was the pointer to an answer; I was on a wrong and long hunt in all terser configuration options. Copy paste my addition to an answer, and I can marked it answered. – Danny '365CSI' Engelman Mar 12 '20 at 09:49

1 Answers1

0

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
});
Sirko
  • 72,589
  • 19
  • 149
  • 183