facebookarchive / prepack

A JavaScript bundle optimizer.
http://prepack.io
Other
14.22k stars 424 forks source link

External Event Handlers #2625

Open s5bug opened 5 years ago

s5bug commented 5 years ago

I'm dealing with code.org's AppLab for one of my projects. I'm using Scala and compiling to Scala.JS.

This Scala registers event handlers to AppLab's onEvent function but prepack is recognizing it as dead code.

How do I properly handle/configure this case? (There are other functions that mutate external state as well, like button, setPosition, setText that I use in my code, but I handle these with the function described in #619)

NTillmann commented 5 years ago

This Scala registers event handlers to AppLab's onEvent function but prepack is recognizing it as dead code.

Do you have a small self-contained example that illustrates the issue?

s5bug commented 5 years ago

It seems the behavior has changed now (or prepack is unable to correctly infer behavior from the ScalaJS code).

__assumeDataProperty(global, "onEvent", __abstract("function", "onEvent"));

(function() {
  onEvent("onClick", "foo", function(e) {
    console.log("hi")
  })
}).call(this);

Error on line 4.

I just recently reset my computer to free up space so I don't have a ScalaJS file to test at the moment. I'll get one as soon as time allows.