CoffeeScriptRedux icon indicating copy to clipboard operation
CoffeeScriptRedux copied to clipboard

`throw` is no longer an expression.

Open jnicklas opened this issue 12 years ago • 4 comments

In jashkenas/CoffeeScript, the following is valid:

foo or throw "bar"

It compiles to this:

foo || (function() {
  throw "bar";
})();

The same code does not compile on redux.

Maybe this was intentionally left out, in which case, I'm perfectly fine with that, it's not exactly an essential feature, but it is quite handy and I couldn't see it mentioned anywhere. Feel free to close this if you don't think it's relevant.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/825331-throw-is-no-longer-an-expression?utm_campaign=plugin&utm_content=tracker%2F33145&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F33145&utm_medium=issues&utm_source=github).

jnicklas avatar Feb 10 '13 21:02 jnicklas

Interesting. I didn't know throw could be used as an expression (i assumed throw and return were the only not valid expressions). I'd always prefer doing:

throw "bar" unless foo

Buuuut, it seems like a bug on Redux, as this does compile:

foo or (throw "bar")

epidemian avatar Feb 10 '13 22:02 epidemian

It's a bug. They're both bugs, since throw is a statement in JS. Also, @epidemian: you forgot break and continue.

michaelficarra avatar Feb 10 '13 23:02 michaelficarra

jashkenas/coffee-script explicitly claims support for throw as an expression, both in the changelog for 1.2.0 ("The throw statement can now be used as part of an expression.") and in the tests.

kevinmehall avatar Feb 11 '13 01:02 kevinmehall

@kevinmehall: Yep, I believe I was the one that added that support.

edit: Never mind, it was Jeremy.

michaelficarra avatar Feb 11 '13 01:02 michaelficarra