slimit icon indicating copy to clipboard operation
slimit copied to clipboard

Breaks on object attributes that use certain special characters

Open liftoff opened this issue 11 years ago • 4 comments

I just ran slimit -m jquery-1.9.1.js > jquery.min.js and this resulted in errors in the browser:

Uncaught SyntaxError: Unexpected identifier 

...so I did some digging and it turns out this is the line that caused the problem:

jQuery.expr[":"] = jQuery.expr.pseudos;

The problem is that slimit converted that expr[":"] into expr.: which is not valid JavaScript. It seems there's a number of special and "illegal" characters where slimit has this problem.

I've put together a simple test case to demonstrate the problem:

var testObj = {};
testObj[":"] = undefined; // Breaks
testObj["::"] = undefined; // Breaks
testObj["a:"] = undefined; // Breaks
testObj["."] = undefined; // OK
testObj["{"] = undefined; // OK
testObj["}"] = undefined; // OK
testObj["["] = undefined; // Breaks
testObj["]"] = undefined; // Breaks
testObj["("] = undefined; // OK
testObj[")"] = undefined; // OK
testObj["="] = undefined; // Breaks
testObj["-"] = undefined; // OK
testObj["+"] = undefined; // OK
testObj["*"] = undefined; // OK
testObj["/"] = undefined; // OK
testObj["\\"] = undefined; // Breaks
testObj["%"] = undefined; // OK
testObj["<"] = undefined; // Breaks
testObj[">"] = undefined; // Breaks
testObj["!"] = undefined; // OK
testObj["?"] = undefined; // Breaks
testObj[","] = undefined; // OK
testObj["@"] = undefined; // Breaks
testObj["#"] = undefined; // OK
testObj["&"] = undefined; // OK
testObj["|"] = undefined; // OK
testObj["~"] = undefined; // OK
testObj["`"] = undefined; // Breaks
testObj["."] = undefined; // OK

This is the result (newlines added by me):

var testObj={};
testObj.:=undefined;
testObj.::=undefined;
testObj.a:=undefined;
testObj["."]=undefined;
testObj["{"]=undefined;
testObj["}"]=undefined;
testObj.[=undefined;
testObj.]=undefined;
testObj["("]=undefined;
testObj[")"]=undefined;
testObj.==undefined;
testObj["-"]=undefined;
testObj["+"]=undefined;
testObj["*"]=undefined;
testObj["/"]=undefined;
testObj.\\=undefined;
testObj["%"]=undefined;
testObj.<=undefined;
testObj.>=undefined;
testObj["!"]=undefined;
testObj.?=undefined;
testObj[","]=undefined;
testObj.@=undefined;
testObj["#"]=undefined;
testObj["&"]=undefined;
testObj["|"]=undefined;
testObj["~"]=undefined;
testObj.`=undefined;
testObj["."]=undefined;

Please take a look when you get a chance. I hope it is as simple as adding a few more characters to a list of specials somewhere :arrow_forward:

liftoff avatar Apr 24 '13 01:04 liftoff

Hi Dan,

What version of slimit did you test against?

rspivak avatar Apr 25 '13 22:04 rspivak

I was using the latest Github code.

liftoff avatar Apr 25 '13 23:04 liftoff

Let me make a clarification: I was using the latest github code with Python 3. PLY has some known issues with Python 3. If you're not seeing the same behavior in Python 2 perhaps that could be the underlying problem?

liftoff avatar Apr 25 '13 23:04 liftoff

I've added test cases that you provided (thanks a lot) and everything works as expected under Python 2.7 Looks like some sort of Python 3 related issue. I'll have to dig deeper.

rspivak avatar Apr 26 '13 02:04 rspivak