question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WHITESPACE_ONLY mode does non-whitespace-only optimizations

See original GitHub issue

Closure 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:open
  • Created 3 years ago
  • Reactions:3
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
concavelenzcommented, Jul 24, 2020

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.

0reactions
ctjlewiscommented, Jul 27, 2020

@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

'use strict';
{
  function foo(p) {
    self["external1"](p);
  }
  console.log(foo());
  console.log(foo());
}
;

Also works for ECMASCRIPT5 and a few others I tested. I think what the issue is here is that both language_in and language_out are set to STABLE by default, but STABLE is actually different for input and output (ends up being STABLE_IN and STABLE_OUT internally).

google-closure-compiler -O WHITESPACE_ONLY --formatting PRETTY_PRINT --language_in STABLE --language_out STABLE

 {
  var foo = function(p) {
    self["external1"](p);
  };
  console.log(foo());
  console.log(foo());
}
;

Using STABLE as input language still, but trying NO_TRANSPILE output target to prevent any unexpected behavior:

google-closure-compiler -O WHITESPACE_ONLY --formatting PRETTY_PRINT --language_in STABLE --language_out NO_TRANSPILE

'use strict';
{
  function foo(p) {
    self["external1"](p);
  }
  console.log(foo());
  console.log(foo());
}
;

It’s definitely a bug, but --NO_TRANSPILE output mode is a good trick to have to work around it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found