-
Notifications
You must be signed in to change notification settings - Fork 2k
unless variable?
compiles to two different things.
#2455
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
Comments
coffee checks if the variable was already declared, so this to be a proper way to me. why the heck would someone assign var to itself? |
You wouldn’t, that is just by example. Doing When I use input number 1 CoffeeScript adds |
In the first example, the test is made before the assignment, but the compiler should know that the declaration was hoisted above the test. Marking as |
Related: #1500 |
Still broken here This code: if a?.b?.c
a.b.c Compiles to: var ref;
if (typeof a !== "undefined" && a !== null ? (ref = a.b) != null ? ref.c : void 0 : void 0) {
a.b.c;
} It's like it gives up after the first try... |
That's not broken. If you really think it's broken, submit a failing test that proves it. |
Why was this issue reopened, by the way? |
It looks like the comments on that commit are why — but I'm not sure if they're still relevant or not. |
Just curious if the purpose of the |
That's how |
@vendethiel In Coffeescript, you can't do |
We're talking about generated code here, not coffeescript code. |
I see, you're right @vendethiel. Thanks for the help! |
Setting any variable depending on its own existence (checked with the existential operator
?
) results in different JavaScript code depending on whether the variable has been assigned a value somewhere prior to the check. See code examples below.I would expect the JavaScript output to be the same in both cases. Because both cases add the
var
statement and therefor neither has to check viatypeof
.Input
Output
Input
Output
The text was updated successfully, but these errors were encountered: