babel / minify

:scissors: An ES6+ aware minifier based on the Babel toolchain (beta)
https://babeljs.io/repl
MIT License
4.4k stars 225 forks source link

simplify expands a return value of Object.entries() to void 0 #962

Open knu opened 5 years ago

knu commented 5 years ago

To Reproduce

Minimal code to reproduce the bug

function unLoad() {
  const { events } = this.props;
  const { editor } = this.state;
  if (!editor) return;

  const { change, ...eventsSansChange } = events;
  for (const [event, handler] of Object.entries(eventsSansChange)) {
    editor.on(event, handler);
  }
}

Actual Output

// bootstrap and polyfill snipped
function unLoad() {
  var a = this.props.events,
    b = this.state.editor;
  if (b)
    for (
      var c = a.change,
        d = _objectWithoutProperties(a, ["change"]),
        e = 0,
        f = Object.entries(d);
      e < (void 0).length;
      e++
    ) {
      var g = _slicedToArray((void 0)[e], 2),
        h = g[0],
        i = g[1];
      b.on(h, i);
    }
}

Expected Output

f should not expand to void 0.

Configuration

How are you using babel-minify?

{
  plugins: [],
  presets: [
    ["@babel/preset-env", { modules: false }],
    ["minify", { builtIns: false }]
  ]
}

Possible solution

Additional context