Compiler not accurately tracking polyfill use of $jscomp.makeIterator
See original GitHub issueI’m using the Closure Compiler via the Java API in shadow-cljs. I’m using it to process npm
packages and polyfill when needed or configured to do so. Recently some code starting throwing at runtime with $jscomp.makeIterator is not a function
errors. It appears that some code gets rewritten to use that but the (expected) ensureLibraryInjected("es6/util/makeiterator")
never happens. This is also somewhat elusive to reproduce. As far as I can tell es6/util/makeiterator
is referenced only by other polyfills so it’ll sometimes be available if you happen to have other code that used those polyfills. If not however it’ll just fail at runtime.
This call seems to create the rewrite: https://github.com/google/closure-compiler/blob/c42989161269278a5c86683be70f4933f5f12333/src/com/google/javascript/jscomp/AstFactory.java#L1115
And it is used in two places https://github.com/google/closure-compiler/blob/023718e521b4f1cb508ff7d177b3d8e50c0ad8d8/src/com/google/javascript/jscomp/Es6ForOfConverter.java#L88 https://github.com/google/closure-compiler/blob/524f612385c836730a194502b30c601090cface6/src/com/google/javascript/jscomp/Es6RewriteDestructuring.java#L626
Neither ensure that the polyfill is actually injected prior to using that.
I’m not entirely sure they are supposed and I have no small reproduction with only the Closure Compiler available as of now but it does happen reliably with my tool as shown in this repro.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top GitHub Comments
I have a fix for this currently in review.
Thanks, that’s very helpful.
This seems to happen with --language_out=ECMASCRIPT_2015 but not --language_out=ECMASCRIPT5. I suspect it’s an issue with the combo of object spread (unsupported in ES 2015) and array destructuring (ok in ES 2015).