closure-compiler icon indicating copy to clipboard operation
closure-compiler copied to clipboard

Add an @pure annotation

Open ChadKillingsworth opened this issue 8 years ago • 5 comments

I'd like to have an annotation to declare an intent that a function will not have side effects. In the presence of this annotation, I'd like the compiler to warn me if the function has side effects.

In a lot of code, you have simple helper methods that are intended to be side-effect free. It's very easy for a side effect to be accidentally introduced at a later time. I'd like to have a warning issued for this so the developer can correct it.

ChadKillingsworth avatar Mar 31 '17 21:03 ChadKillingsworth

What we discussed was that this annotation would indicate that a function was dead code if it's return value is not used.

The compiler should warn if the side effect detection disagreed with the annotation. The warning would be suppressible.

ChadKillingsworth avatar Apr 03 '17 23:04 ChadKillingsworth

Prior art exists with the UglifyJS --pure-funcs option.

ChadKillingsworth avatar Apr 03 '17 23:04 ChadKillingsworth

Was there any progress on this item?

roman01la avatar Oct 12 '22 09:10 roman01la

AFAIK, no action has ever been taken on this.

brad4d avatar Oct 13 '22 22:10 brad4d

I don't currently see us having time to implement this, but I think I could find time to review a pull request, if someone wanted to create one.

brad4d avatar Oct 13 '22 22:10 brad4d