Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Constructors incorrectly forming conditionals when a throw exists in execution #2561

Open
trueadm opened this issue Sep 21, 2018 · 3 comments

Comments

@trueadm
Copy link
Contributor

trueadm commented Sep 21, 2018

Here's a strange issue that I've been running into with the React Native bundle. Our module system initializes and when doing so, can run into cases where there's an abstract conditional that might throw. The throw seems to break the execution flow for function constructors, something that shouldn't happen.

Here's a repro:

function module() {
  var x = global.__abstract ? __abstract("boolean", "(true)") : true;

  // if the throw is remove, the string below gets inlined correctly
  if (!x) {
    throw new Error("An error");
  }

  var Component = function () {
    function Component() {
      this.someMethod = function() {
        return "This should be inlined!";
      };
    }
  
    return Component;
  }();
  
  function fn(x) {
    var instance = new Component();
    return instance.someMethod();
  }
  
  global.__optimize && __optimize(fn);

  return fn;
}

global.result = module();

When we get to var instance = new Component();. Prepack wrongly thinks that Component is a conditional abstract value of undefined | Constructor, because of the above throw. This results in bailing out and the code never inlining – something that break the React reconciler when dealing with React class components (we don't support conditional constructors).

@hermanventer
Copy link
Contributor

This seems to be some kind of interaction between optimizing nested functions and joining the state of the local variables of module.

@cblappert
Copy link
Contributor

Passes on master.

@cblappert cblappert reopened this Oct 22, 2018
@matthargett
Copy link

if it passes on master, is there a missing test that should be added? or is the internal test difficult to reduce?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants