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

Threat throw same as function. #3347

Closed
al6x opened this issue Feb 2, 2014 · 6 comments
Closed

Threat throw same as function. #3347

al6x opened this issue Feb 2, 2014 · 6 comments
Labels

Comments

@al6x
Copy link

al6x commented Feb 2, 2014

Throw in CS threat somehow similar to function, but this

(@onError|throw) new Error(msg)

doesn't compile, while

(@onError|@somethingOther) new Error(msg)

does.

@vendethiel
Copy link
Collaborator

because throw is a statement, not an expression (like return)

@michaelficarra
Copy link
Collaborator

To elaborate, throw, return, continue, and break are the only statements that CoffeeScript refuses to treat as expressions because they affect control flow.

@epidemian
Copy link
Contributor

There seems to be a difference between throw and the others though. throw <expr> can be used as an expression while return|continue|break <expr> can't:

# Both lines compile.
foo throw bar, 42
baz or throw qux

# Neither of these lines compile.
foo return bar, 42
baz or return qux

Given that that difference exists, couldn't we compile:

(@onError or throw) new Error msg

to:

(this.onError || function(e) {
  throw e;
})(new Error(msg));

?

And, would it make sense to do so?

@vendethiel
Copy link
Collaborator

Then people will ask us to support (monoid or (+)).
We could compile it to a throwing function, knowing we're gonna add a line in the stack trace (and checking we're correctly carrying arguments)

@michaelficarra
Copy link
Collaborator

@epidemian: I actually didn't know about that. I'm going to have to add that to CoffeeScriptRedux.

@al6x
Copy link
Author

al6x commented Feb 4, 2014

Yes, right now throw is like a half expression, would be nice to make it as a plain expression.

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

4 participants