Skip to content
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

Compiler doesn't output synthetic code in WHITESPACE_ONLY #2007

Closed
jart opened this issue Sep 12, 2016 · 8 comments
Closed

Compiler doesn't output synthetic code in WHITESPACE_ONLY #2007

jart opened this issue Sep 12, 2016 · 8 comments
Labels

Comments

@jart
Copy link
Contributor

jart commented Sep 12, 2016

cat lol.js
let a = [0, 1];
for (var x of a) {
}
java -jar ~/code/compiler.jar \
   --compilation_level=WHITESPACE_ONLY \
   --js_output_file=/dev/stdout \
   --language_in=ECMASCRIPT6_STRICT \
   --language_out=ECMASCRIPT5_STRICT \
   --formatting=PRETTY_PRINT \
   --js lol.js
'use strict';var a = [0, 1];
for (var $jscomp$iter$0 = $jscomp.makeIterator(a), $jscomp$key$x = $jscomp$iter$0.next();!$jscomp$key$x.done;$jscomp$key$x = $jscomp$iter$0.next()) {
  var x = $jscomp$key$x.value
}
;
@jart
Copy link
Contributor Author

jart commented Sep 12, 2016

It would also be pretty cool if --use_types_for_optimization --new_type_inf caused the code above to not need the polyfill.

@jart
Copy link
Contributor Author

jart commented Sep 12, 2016

It would also be cool if the compiler was like, hey, this for loop doesn't have side effects. I'm just going to remove it. And a isn't referenced by anything. So the output becomes empty. I checked and all this stuff still gets output, even in ADVANCED mode.

@MatrixFrog MatrixFrog added the ES6 label Sep 12, 2016
@zeroinformatique
Copy link

Same issue here. The "for of" loops are converted to polyfill, but the polyfill is not provided to the JS which just plain crashes. I expected Whitespace_only to not try any code modification, but it's not working at all because of this.

Is there a fix planned?

@MatrixFrog
Copy link
Contributor

"WHITESPACE_ONLY" is used internally for systems where we are transpiling a single file at a time, and thus don't want to include the ES6 runtime library because it's going to be included once when all the files are brought together. It's a misnomer because we're not just stripping whitespace, we're also transpiling. If you don't need transpilation, you can use --language_out=ES_2017.

@brad4d brad4d added the P3 label Sep 28, 2017
@brad4d
Copy link
Contributor

brad4d commented Sep 28, 2017

@OzoneGrif, will setting the --language_out=ES_2017 option to avoid transpilation be sufficient for your needs? Or maybe just use SIMPLE optimization mode?

This is a low priority issue.

@lauraharker
Copy link
Contributor

Another internal team recently encountered this, so updating the issue.

At some point we want to separate WHITESPACE_ONLY from what we need for "transpiling a single file at a time without including the runtime libraries", and still output the synthetic $jscomp.* code. I'll make sure that the documentation for WHITESPACE_ONLY mentions it still transpiles code.

@concavelenz
Copy link
Contributor

See also this:
#2950

If it isn't going to include the jscomp.* code, it shouldn't include the polyfills either as it, it is duplicating polyfill code and is still is non-functional. The compiler should produce a functional bundle at least that would be something useful.

@sbc100
Copy link
Contributor

sbc100 commented Aug 24, 2023

I'm having trouble seeing how ac3e330 fixes this issue. The commit doesn't seem to relate to the WHITESPACE_ONLY option at all.

We use WHITESPACE_ONLY in emscripten to mean "transpile only and don't do any expensive optimizations" . Sadly because WHITESPACE_ONLY doesn't include any polyfills we can't use certain features. See emscripten-core/emscripten#11984.

We are considering using a seperate tool for trasnpilation but closure compiler is already fully integrated and I capable to doing the transpilation we need. Is there some way we could fix this issue, or create a new TRANSPILE_ONLY ompilation_level?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants