Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Unable to Parse valid statement... #22

hasanyasin opened this Issue Feb 4, 2012 · 5 comments


None yet
2 participants

In Short: Like it perfectly parses a=function(){}(); slimit should be able to parse a||function(){}(); too.

In Detail:
slimit parses

(function() { return "slimit!"; } )();


a=function () { return "slimit!" ; }();


It throws an exception for
function() { return "slimit!"; } ();

SyntaxError: Unexpected token (LPAREN, '(') at 1:8 between LexToken(FUNCTION,'function',1,0) and LexToken(RPAREN,')',1,9)

which is again perfect since function declaration needs a name here.

It throws the similar (unexpected token is FUNCTION this time, instead of LPAREN) exception here:

window.done_already || function () { return "slimit!" ; }();

which is syntactically correct like the second example above.

@ghost ghost assigned rspivak Feb 4, 2012


rspivak commented Feb 4, 2012

Again, thanks for this bug report. You are fast ;)


rspivak commented Feb 4, 2012

Looks like I'll need to dig deeper to handle this one right for different scenarios. There is a whole article devoted just to function declarations and function expressions demystification : http://kangax.github.com/nfe/


rspivak commented Feb 4, 2012

OK, the issue turned out to be pretty simple to fix and I had to change only one production rule in the parser.
Here is the fix: c250efc
All slimit tests passed, which is a good thing :)

I have checked your update in the code. From the one-line addition, I see that this was it!

Thank you again, for the great library. :)

@hasanyasin hasanyasin closed this Feb 4, 2012


rspivak commented Feb 4, 2012

Thank you for taking your time to report in detail all those issues.

acatton added a commit to acatton/slimit that referenced this issue Jan 26, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment