WHITESPACE_ONLY mode does non-whitespace-only optimizations
See original GitHub issueClosure compiler v20200614
in.js:
{
function foo(p) { self["external1"](p) }
console.log(foo());
console.log(foo());
}
Command: java -jar ./closure-compiler.jar --js in.js --js_output_file out.js --compilation_level WHITESPACE_ONLY --formatting PRETTY_PRINT
out.js:
{
var foo = function(p) {
self["external1"](p);
};
console.log(foo());
console.log(foo());
}
;
Note that function foo(p)
was rewritten as var foo = function(p)
. This is not a whitespace-only change. It also causes a bug (#3623). Therefore even using the lowest tier of WHITESPACE_ONLY optimizations, we cannot escape this bug. I think it is reasonable to expect WHITESPACE_ONLY to only do what it says and not make other adjustments which alter the way scripts work.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Whitespace-Only Text Nodes
Whitespace -Only Text Nodes ; FALSE, XML processing with XQuery streaming optimization, Content of element is removed, and it becomes an empty element...
Read more >How to get whitespace-mode enabled only for certain modes
I'm trying to get emacs whitespace-mode enabled automatically only in certain modes. According to the documentation, ...
Read more >How do I move vertically until reaching a non-whitespace ...
vim for that. I map it to gK and gJ . It will jump over many lines with the same character in the...
Read more >white-space - CSS: Cascading Style Sheets - MDN Web Docs
The white-space CSS property sets how white space inside an element is handled.
Read more >Whitespace - Tailwind CSS
Use whitespace-pre-line to preserve newlines but not spaces within an element. Text will be wrapped normally. Hey everyone! It's almost 2022 and we...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any language_out above ECMASCRIPT_2015 should avoid this issue. “STABLE” as language_out is ECMASCRIPT5 currently (but for no good reason at this point).
I think that I would like to take WHITESPACE_ONLY back to its original intent: simply parse and print. That however, would mean that this would be restricted to a single “module” file input, or any number of scripts (which can be concatenated) but not both.
@AshleyScirra There isn’t supposed to be one - same input/output language should also imply no transpilation. It doesn’t end up being 100% coverage, but it does work usually:
$ google-closure-compiler -O WHITESPACE_ONLY --formatting PRETTY_PRINT --language_in ES_NEXT --language_out ES_NEXT
Also works for
ECMASCRIPT5
and a few others I tested. I think what the issue is here is that bothlanguage_in
andlanguage_out
are set toSTABLE
by default, butSTABLE
is actually different for input and output (ends up beingSTABLE_IN
andSTABLE_OUT
internally).google-closure-compiler -O WHITESPACE_ONLY --formatting PRETTY_PRINT --language_in STABLE --language_out STABLE
Using
STABLE
as input language still, but tryingNO_TRANSPILE
output target to prevent any unexpected behavior:google-closure-compiler -O WHITESPACE_ONLY --formatting PRETTY_PRINT --language_in STABLE --language_out NO_TRANSPILE
It’s definitely a bug, but
--NO_TRANSPILE
output mode is a good trick to have to work around it.