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

"pureFunctions" are not actually pure, and are not safe to remove. #2540

ljharb opened this Issue Nov 1, 2018 · 0 comments


None yet
1 participant

ljharb commented Nov 1, 2018

tl;dr: the vast majority of the language builtins listed in can throw exceptions, which makes them not "pure", and decidedly unsafe to remove.

Specifically, the es6-shim - something that is widely deployed on a not-insignificant percentage of the internet - has many things like this line that rely on a thrown exception, or lack thereof, to indicate if a builtin implementation is broken and needs replacement. We pre-build our shims at @airbnb with rollup, and this resulted in our website being broken for, in particular, IE 11 users - because rollup transpiled this:

var objectKeysAcceptsPrimitives = !throwsError(function () { Object.keys('foo'); });

into this:

var objectKeysAcceptsPrimitives = !throwsError(function () {  });

Anything that can possibly throw an exception under any circumstances (Object.keys(null), for example) is not something that's necessarily safe to remove (depending on if the parameters are all inline literals that meet the appropriate criteria), and although I haven't exhaustively gone through the list of pureFunctions, at a glance, almost all of them have a path in the spec that can throw.

I've patched around this issue in v0.35.4 of es6-shim by adding return so that rollup is not fooled into thinking the statements are no-ops, but it'd be ideal to fix this in rollup itself - there may be other cases I've not yet discovered..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment