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

Lexer: Within inline if block, a throw that takes implicit object will split the object into multiple objects #3199

Closed
KarlPurk opened this issue Oct 10, 2013 · 3 comments
Labels

Comments

@KarlPurk
Copy link

I apologise if this has already been reported, I did search the issues but there are lots related to "throw". Also, this may not be an issue, but I wanted to double check anyway.

When throwing exceptions the following syntax does not compile correctly:

if 1 then throw
    type: 'a'
    msg: 'b'

The above coffeescript compiles to the following:

if (1) {
  throw {
    type: 'a'
  };
}

({
  msg: 'b'
});

In order for this to compile we must use one of the following variations:

if 1 then throw type: 'a', msg: 'b'

or

if 1 then throw {
    type: 'a'
    msg: 'b'
}

or

if 1 
    throw
        type: 'a',
        msg: 'b'

Is this intended? Or are we missing out on a nicer syntax for throwing exceptions?

Thanks!

@GeoffreyBooth
Copy link
Collaborator

Duplicate of #1263. The issue is the object without braces as part of a statement. That would be nice to fix, if someone feels like submitting a PR; but the workaround is to just add braces, or define the object into a variable before throw or returning it.

@GeoffreyBooth
Copy link
Collaborator

Actually it’s not a duplicate of #1263. Possibly a duplicate of #4150.

@GeoffreyBooth
Copy link
Collaborator

One more try: maybe a duplicate of #2998.

@GeoffreyBooth GeoffreyBooth changed the title Throw exception syntax Lexer: Within inline if block, a throw that takes implicit object will split the object into multiple objects May 6, 2017
helixbass added a commit to helixbass/copheescript that referenced this issue Jul 3, 2017
helixbass added a commit to helixbass/copheescript that referenced this issue Jul 5, 2017
GeoffreyBooth pushed a commit that referenced this issue Jul 9, 2017
* throw multiline implicit object [Fixes #3199]

* restrict to Object

* test error on non-object

* test error on call indented non-object
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

2 participants