rspivak / slimit

SlimIt - a JavaScript minifier/parser in Python
MIT License
551 stars 94 forks source link

division with "this" fails #6

Closed wkornewald closed 13 years ago

wkornewald commented 13 years ago

I'm trying to minify code generated by pyjs/pyjamas. Slimit fails on this snippet:

Number.prototype.rfloordiv = function (y) { if (!y.number || isNaN(y = y.valueOf())) return @{{NotImplemented}}; if (this == 0) throw @{{ZeroDivisionError}}('float divmod'); return Math.floor(y / this); };

Traceback (most recent call last): ... File "...\slimit\minifier.py", line 38, in minify tree = parser.parse(text) File "...\slimit\parser.py", line 64, in parse return self.parser.parse(text, lexer=self.lexer, debug=debug) File "C:\Python26\lib\site-packages\ply\yacc.py", line 265, in parse return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc) File "C:\Python26\lib\site-packages\ply\yacc.py", line 1047, in parseopt_notrack tok = self.errorfunc(errtoken) File "...\slimit\parser.py", line 84, in p_error self.lexer.prev_token, self.lexer.token()) SyntaxError: Unexpected token (REGEX, "/ y);\n};\n\nNumber.prototype.rfloordiv = function (y) {\n if (!y.number || isNaN(y = y.valueOf())) return $p['NotImplemented'];\n if (this == 0) throw $m['ZeroDivisionError']('float divmod');\n return Math.floor(y /") at 1:601787 between LexToken(THIS,'this',1,601782) and LexToken(THIS,'this',1,602015)

I tried browsing the code, but it would take me much too long to understand the parser (I've only worked with OMeta/PyMeta2). Could you please help?

rspivak commented 13 years ago

Hey Waldemar,

Thanks for reporting the issue, I'll take a look at it today.

rspivak commented 13 years ago

Could you provide a block of code that is located just above

Number.prototype.rfloordiv = function (y) {
if (!y.number || isNaN(y = y.valueOf())) return @{{NotImplemented}};
if (this == 0) throw @{{ZeroDivisionError}}('float divmod');
return Math.floor(y / this);
};
wkornewald commented 13 years ago

Sure. I've uploaded the whole JS file here: http://dl.dropbox.com/u/20937738/pyjslib.js

Thank you!

rspivak commented 13 years ago

I've made a fix and released a new version 0.5.4

Enjoy it :)

P.S.: I've also added your name to CREDIT file

wkornewald commented 13 years ago

Thanks a lot. Next issue is coming... :)