google / closure-compiler

A JavaScript checker and optimizer.
https://developers.google.com/closure/compiler/
Apache License 2.0
7.31k stars 1.15k forks source link

A for loop compiles incorrectly in WHITESPACE_ONLY and SIMPLE_OPTIMIZATIONS #4130

Closed jplevene closed 7 months ago

jplevene commented 8 months ago

A for(const row of rows) returns $jscomp and loads of junk JavaScript code that won't run.

jplevene commented 8 months ago

Even does this in WHITESPACE_ONLY that is not supposed to alter the code

lauraharker commented 7 months ago

This is caused by transpilation. See https://github.com/google/closure-compiler/issues/3856 and https://github.com/google/closure-compiler/issues/2007.

Compiler versions past https://github.com/google/closure-compiler/commit/ac3e3303617e23aed24eb7574e1d140565aa079a will default to not transpiling. If you're using an older version you can set --language_out=ECMASCRIPT_NEXT. If you're using a newer version, are you setting --language_out explicitly? You'd need to remove that.

jplevene commented 5 months ago

I spotted this bug in the Google online compiler https://closure-compiler.appspot.com/ which is managed by Google so I reported this, and thanks. By default, clicking "Whitespace only" in the online compiler should include the line // @language_out ECMASCRIPT_NEXT which is causing the issue. Again, thanks for this and I have reported the bug there