facebookarchive / prepack

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

Emit warning when a module writes global state #690

Open hershi opened 7 years ago

hershi commented 7 years ago

When initializing dependencies, we evaluate each module in isolation, and if the module evaluation fails, we roll back its changes and continue with the next module in line. This can cause a change of behavior when running the prepacked code compared to the standard code, in case of badly behaved modules that have implicit dependency via global state:

To help detect such cases, we should emit a warning when a module fails to be prepacked because it writes to global state. Note that this won't guarantee that we catch all cases where a module initialization may affect global state (and hence can theoretically affect downstream modules), bit it should cover at least some of these cases.

NTillmann commented 7 years ago

I assume this is meant to address https://github.com/facebook/prepack/blob/master/src/serializer/modules.js#L90-L100?

NTillmann commented 7 years ago

Look out for #690 in the code to find the place where this needs to get addressed. #798 might be the key to make this safe, which is what should ultimately happen --- not just issuing a warning.