Skip to content

Instantly share code, notes, and snippets.

@mishoo
Created October 30, 2013 11:15
Show Gist options
  • Save mishoo/7230949 to your computer and use it in GitHub Desktop.
Save mishoo/7230949 to your computer and use it in GitHub Desktop.
//// Safari parser bug
//// derived from: https://github.com/mishoo/UglifyJS2/issues/313
// fails with SyntaxError: Expected token ')'
( function(){ return this || eval('this'); }().x = "y" );
// fails with SyntaxError: Unexpected token '='
1, function(){ return this || eval('this'); }().x = "y";
//// weird that we get different error messages
//// The following all work.
// place the function call inside parens
( (function(){ return this || eval('this'); }()).x = "y" );
1, (function(){ return this || eval('this'); }()).x = "y";
// simplify the return expression, keep `then`
( function(){ return this; }().x = "y" );
1, function(){ return this; }().x = "y";
// keep `eval`
( function(){ return eval('this'); }().x = "y" );
1, function(){ return eval('this'); }().x = "y";
// place the return expression inside parens (!!)
( function(){ return ( this || eval('this') ); }().x = "y" );
1, function(){ return ( this || eval('this') ); }().x = "y";
//// I have the strange feeling that the *parser* in JSC tries to
//// inline the return value and parse the result instead, like some
//// sort of macro-expansion. Huh?! */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment