-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Invalid JS: return if not x?
creates empty if
block
#2298
Comments
Interestingly:
|
CoffeeScript reads |
Why not just make "if not" specifically synonymous with "unless"? Are there cases where they should not be equivalent? |
See #1393. |
return if not x?
creates empty if
block
Even more minimal case: -> return if yes (function() {
if (true) {
}
}); |
This seems like some kind of optimisation. If there's anything after the ->
return if yes
'hello' (function() {
if (true) {
return;
}
return 'hello';
}); |
The optimization is in |
return if not x?
creates empty if
blockreturn if not x?
creates empty if
block
The phrasing on this one is a bit strange and can lead to confusion. Heres an example:
So this is saying to return an error message of "Please enter a number" when the two specified conditions have been met. The first one being that there is no data in consumer.number?. The second condition checks for valid data, so it doesn't take any strings with a length less than 9. |
I can’t seem to write a test for this. Returning (function() {
if (true) {
}
})(); is the same, really, as (function() {
if (true) {
return;
}
})(); And as @connec wrote, as soon as you put a value anywhere ( So I guess this is just an optimization that works. It’s a bit confusing to read, but As for the question about the readability of So I don’t see anything here that needs fixing. Please comment if I’m wrong, and I’ll reopen. |
We have some code like:
And this generates:
As I understand it, this should output:
Or am I missing something unusual about JS? :)
The text was updated successfully, but these errors were encountered: