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

whitespace_only changes function names #2718

Open
nirbd opened this issue Nov 14, 2017 · 8 comments
Open

whitespace_only changes function names #2718

nirbd opened this issue Nov 14, 2017 · 8 comments

Comments

@nirbd
Copy link

nirbd commented Nov 14, 2017

Hi,

Using the closure-compiler.appspot.com API in WHITESPACE_ONLY mode
functions like function cbar_log_error(msg){
get renamed to: var cbar_log_error$7=function(msg){

Is this a bug? If not how to avoid?

10X

@MatrixFrog
Copy link
Contributor

Sounds like maybe the Normalize pass is running but the later pass which undoes that renaming is not.

@brad4d
Copy link
Contributor

brad4d commented Nov 14, 2017

@nirbd thanks for the repro, but we could use a bit more help.
Could you a) cut down the source to just a small subset that demonstrates the problem and
b) have the code in the "code" box instead of loading it from a separate URL?

Thanks.

@brad4d
Copy link
Contributor

brad4d commented Nov 15, 2017

Thanks @nirbd !
This makes the problem quite clear.
It seems the compiler is considering a function declared inside a try block to be local to the try block, when it isn't.

Before:

try {
  function cbar_log_console(msg){}
} catch (err){
  cbar_log_console('cbar error: '+err);
};

After:

try{
  var cbar_log_console$0 = function(msg){}
} catch(err) {
  cbar_log_console("cbar error: "+err)
};

@brad4d brad4d self-assigned this Nov 15, 2017
@nirbd
Copy link
Author

nirbd commented Nov 16, 2017

@brad4d Thanks for looking at this.

Isn't whitespace-only mode supposed to maintain function names even if they're local?
Is there a fix to it? If so do you guys upload fixes immediately or it takes time?

  • N

@brad4d
Copy link
Contributor

brad4d commented Feb 14, 2020

normalization always runs and always renames local variables to be uniquely named even in WHITESPACE_ONLY. I don't think we'll change that.

It is definitely wrong that the compiler is thinking that the cbar_log_console in the catch clause refers to a different variable than the one declared in the try clause.

Given how long this issue has lived without an update (my bad) it's clear that this isn't a use case we really deal with much. Code that declares something in the try then uses it in the catch, is just strange, and we should really disallow it entirely. (TypeScript reports an error for it, btw.)

Sorry, but it doesn't seem likely we'll find time to hunt down and kill this bug.

@brad4d brad4d removed their assignment Feb 14, 2020
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

3 participants