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
Property access should not be treated as dead code. #312
Comments
Duplicate of #76. |
The trouble is it means that you can't interact cleanly with JS code that relies on that feature. |
You can with |
Not terribly efficient I guess but would this be an acceptable workaround? Last I checked CSR didn't support back ticks, so... use = ->
use a.b |
That's what I meant by "not cleanly". Furthermore, a future, smarter compiler may also eliminate |
It'd be kind of difficult to eliminate that call since the compiler can't be sure that the value of |
Since CoffeeScript is lexically scoped, the compiler has all the information needed to determine if a variable is rebound later on. In that case, if the evaluation of the arguments dont have any effect, removing the call is a valid optimization. Relying on the lack of a correct optimization to prevent an invalid one is probably not a good idea... That being said, I agree that relying on the side effects of property access is a bad programming Well, it could have its use in a well documented DSL, but it's a corner case. The backticks allow it if needed, so it isn't that problematic if the language doesn't support it anyway. As far as I knew, backticks had been removed from CS 2.0. I'm glad that they're back in. In this case it makes it explicit that the property access does something special, so if someone encounters |
Backticks weren't removed, they just aren't able to introduce invalid syntax, such as |
As a workaround, you can simply assign the result to a variable (no need to pass it to an |
Side-effecting getters. |
Currently, the compiler will drop a property access whose return value is not used.
The thing is, because of ES5 accessors (and moreover ES6 proxies), property access may have side effects. They should not be eliminated.
The text was updated successfully, but these errors were encountered: