Skip to content

TRANSPILE_ONLY mode #4231

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

Open
brad4d opened this issue Apr 9, 2025 · 5 comments
Open

TRANSPILE_ONLY mode #4231

brad4d opened this issue Apr 9, 2025 · 5 comments
Assignees

Comments

@brad4d
Copy link
Contributor

brad4d commented Apr 9, 2025

Summary

Add a TRANSPILE_ONLY mode that does the following:

  • Error checking as usual
  • Code changes necessary to generate running code, including:
    • handling goog.define()
    • handling goog.module()
    • transpiling down to the requested --language_out level, including the addition of polyfills
  • Otherwise leave the code unchanged. No optimizations. No renaming.

Background

WHITESPACE_ONLY mode is borderline useless, because what it means is very badly defined. In many cases it results in output code that will not run. Several examples can be seen in this issue search.

https://github.com/google/closure-compiler/issues?q=is%3Aissue%20state%3Aopen%20WHITESPACE_ONLY

On the other hand SIMPLE_OPTIMIZATIONS does much more than developers often want when they're "just" trying to get an executable version of their project as fast as possible for testing and debugging.

@brad4d brad4d assigned brad4d and rahul-kamat and unassigned brad4d Apr 9, 2025
@brad4d
Copy link
Contributor Author

brad4d commented Apr 9, 2025

Rahul's agreed to look into how hard this will be to accomplish as part of investigating a related polyfill problem.

@niloc132
Copy link
Contributor

niloc132 commented Apr 9, 2025

Might be a typo, or I'm reading docs from the wrong place, but what is goog.declare()? In the context of goog.module I would assume it might have been meant to be goog.define() or goog.provide() (or if the context was goog.module.get, maybe goog.require() or goog.forwardDeclare()?) Or, possibly goog.declareModuleId() (or less likely, goog.module.declareLegacyNamespace())?

Aside, would it be possible to get an equivalent of https://google.github.io/closure-library/api/goog.html for this repo, and possibly forward the old page to this (or at least put up a note that it is archived/deprecated)? I'm looking at https://github.com/google/closure-compiler/blob/master/lib/base.js as the "modern" version of that file.


Would it be fair to say that TRANSPILE_ONLY is in some ways a "lighter" version of BUNDLE, and in other ways a "heavier" version of BUNDLE? That is:

  • BUNDLE will chase goog.require() and goog.module.get(), loading other files recursively as needed, but TRANSPILE_ONLY will not (as neither is in your bullet list. Do users then need to include a complete list of JS files desired to be baked in when calling this, in the correct order?
  • TRANSPILE_ONLY will fully parse the JS files it is running, making it somewhat slower than BUNDLE (which will only apply the regex required to discover dependencies), so that it can find syntax that needs to be transpiled down and discover required polyfills.

@brad4d
Copy link
Contributor Author

brad4d commented Apr 10, 2025

@niloc132 s/goog.declare/goog.define/

edit done

@hills
Copy link

hills commented Apr 11, 2025

Perhaps this is the appropriate place to mention that --define= could be considered, as it does nothing in WHITESPACE_ONLY and this seems unhelpful.

@brad4d
Copy link
Contributor Author

brad4d commented May 16, 2025

That is a good point. I think what we would want from this compilation mode is roughly:

  1. Make all changes necessary to make the output code functional. This includes handling --define, goog.module(), and transpiling and polyfill injection appropriate for --language_out=ES_20XX
  2. Skip all optimizations, the only "optimizing" that happens is that comments and whitespace are not output from the code printer.

Given this, perhaps it would be easier to think of this and implement it by starting with SIMPLE mode and removing optimizations.

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

No branches or pull requests

4 participants