google / closure-compiler

A JavaScript checker and optimizer.
https://developers.google.com/closure/compiler/
Apache License 2.0
7.38k stars 1.15k forks source link

Allow @nocompile on a per function basis #2013

Closed arciisine closed 8 years ago

arciisine commented 8 years ago

I have a scenario in which I want the closure compiler to ignore certain regions of code. Right now,


/*@nocompile*/

seems to work on a per file level, but I need to be able to do it a function level. Ultimately this could be at any block level, but function is the safest bet with var and function declarations.

dimvar commented 8 years ago

We don't plan to support @nocompile on a more fine-grained level than we do now.

What is it that you're trying to do, and need nocompile per function?

arciisine commented 8 years ago

The gist of the issue, is that I have nested functions that are being optimized by closure, but I need access to the original code as I have other transformations I need to do as well. Essentially closure is making good decisions with what it knows at the moment, but those decisions are breaking the assumptions my other transformations are making.

arciisine commented 8 years ago

As a follow up, I can rewrite my code to ensure my assumptions are valid, but this will occur every time closure optimizes in a way that breaks my assumptions. Ultimately I was hoping to be able to ignore certain regions of code as to ensure my transformations will always be valid.

dimvar commented 8 years ago

Are you transforming the code after compilation? What kind of transformation are you doing?

arciisine commented 8 years ago

My transformation is being applied at runtime, and after I transform the code, I run it through the closure compiler to optimize my transformation. This process can recurse infinitely through nested functions, and that is where I'm running into problems. I want to optimize everything but the nested function as that input needs to be in the original form to be fed into my transformation.

dimvar commented 8 years ago

I see. We use nocompile to drop files that don't follow the compiler assumptions from the compilation. We don't plan to provide such fine-grained control of the optimizer.

arciisine commented 8 years ago

Thanks for the response. I will need to find other ways to handle this.