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

Inconsistency with the existential operator #2182

Closed
michaelowens opened this issue Mar 7, 2012 · 2 comments
Closed

Inconsistency with the existential operator #2182

michaelowens opened this issue Mar 7, 2012 · 2 comments
Labels

Comments

@michaelowens
Copy link

Quicky shown in one code:

if varname? then
varname2 = "hi"
if varname2? then
delete varname2
if varname2? then

Compiles to

var varname2;

if (typeof varname !== "undefined" && varname !== null) {}

varname2 = "hi";

if (varname2 != null) {}

delete varname2;

if (varname2 != null) {}

The last one doesn't check for undefined, even though the variable was deleted. I think it's bad for CoffeeScript to decide to not check for undefined based on how the script was during compiling.

@yuchi
Copy link

yuchi commented Mar 7, 2012

Luckily enough it's not a problem in JS where you _cannot delete vars_!

Have a look at @kangax's http://perfectionkills.com/understanding-delete/ awesome article.

tl;dr: 'cause in JS vars are not deleted checking for varA != null is valid even after a delete varA; (which is not successful).

@michaelficarra
Copy link
Collaborator

Thanks to #2021, that syntax won't even be allowed anyway. But yeah, as @yuchi says, delete won't remove anything from scope that was added in a variable declaration, as all variables (known to the scope check) in coffeescript are. Not a bug. Feel free to re-open if you can find a way for an existentially-guarded reference to produce a ReferenceError.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants