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

Invalid JS: Nested throw expressions #3789

Closed
no-longer-on-githu-b opened this issue Jan 12, 2015 · 3 comments
Closed

Invalid JS: Nested throw expressions #3789

no-longer-on-githu-b opened this issue Jan 12, 2015 · 3 comments
Labels

Comments

@no-longer-on-githu-b
Copy link

no-longer-on-githu-b commented Jan 12, 2015

The following CoffeeScript code:

throw throw throw a

compiles to the following JavaScript code:

throw throw throw a;;;

which is invalid syntax in JavaScript.

Instead it should either compile to the following JavaScript code:

throw (function() {
    throw (function() {
        throw a;
    })();
})();

or be rejected by the CoffeeScript compiler.

Now this code is of course incredibly silly, but the CoffeeScript compiler should under no circumstance both accept the input and generate code with invalid syntax.

@jashkenas jashkenas added the bug label Jan 29, 2015
@jashkenas
Copy link
Owner

I don't think it should compile. That should be a syntax error.

@GeoffreyBooth GeoffreyBooth changed the title CoffeeScript generates invalid syntax for nested throw expressions. Invalid JS: Nested throw expressions May 6, 2017
@GeoffreyBooth
Copy link
Collaborator

See also #3709.

GeoffreyBooth added a commit to GeoffreyBooth/coffeescript that referenced this issue Aug 25, 2017
GeoffreyBooth added a commit that referenced this issue Aug 25, 2017
)

* Fix #3709: throwing an if, for, switch or while should throw the returned value of the statement/loop

* Fix #3789: don’t throw a throw (unless it’s in a closure)

* LEVEL_LIST works better than a list of node types
@GeoffreyBooth
Copy link
Collaborator

Fixed by #4664.

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

3 participants