Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Over-aggressive pruning inside loops with try/catch #2894

Closed
jbt opened this issue Jun 5, 2019 · 4 comments · Fixed by #2898
Closed

Over-aggressive pruning inside loops with try/catch #2894

jbt opened this issue Jun 5, 2019 · 4 comments · Fixed by #2898

Comments

@jbt
Copy link

jbt commented Jun 5, 2019

  • Rollup Version: 1.14.0
  • Operating System (or Browser): Any
  • Node Version: 10.16.0

How Do We Reproduce?

Using the following code as input for rollup, no plugins and all the default options:

export default function mixin(Interface, Classes) {

    for (var _iterator2 = Object.getOwnPropertyNames(Interface)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
      var name = _step2.value;

      if (Class.hasOwnProperty(name)) continue;
      var desc = Object.getOwnPropertyDescriptor(Interface, name);
      Object.defineProperty(Class, name, desc);
    }

    try {
      for (var _iterator3 = Object.getOwnPropertyNames(Interface.prototype)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
        var _name = _step3.value;

        if (Class.prototype.hasOwnProperty(_name)) continue;
        var desc = Object.getOwnPropertyDescriptor(Interface.prototype, _name);
        Object.defineProperty(Class.prototype, _name, desc);
      }
    } catch (err) {
    }
}

(this is a reduced version of the mixin util from Slate.js after transpilation that can be found in lib/slate.es.js of slate on npm)

Expected Behavior

Output should be pretty much identical to input

Actual Behavior

The second loop gets reduced down to:

      for (; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
        var desc;
      }

_iterator3 is no longer defined and the loop body is also missing.

This seems to be about as minimal as I can make the test case - removing the try/catch or anything inside either of the loops causes this behaviour to go away.

REPL link

This seems to have been introduced in 1.14.0, since with 1.13.1 it's perfectly fine (repl)

@colinrobertbrooks
Copy link

I ran into this as well building this small repo.

@lukastaegert
Copy link
Member

Thanks, I already tracked it down, fix upcoming.

@lukastaegert
Copy link
Member

Fix at #2898

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants