Missing semicolon on final statement
sachya opened this issue · 10 comments
Hi tholu,
Thanks for continuing the legacy of js packer.
Can you fix the missing semicolon problem in the library?
@sachya I read about that somewhere, do you have a link to the exact problem description? At best, include it here with an example. Thanks!
I have the same issues. It seems to obfuscate everything precisely except that it is missing the semicolon at the end of commands and such. For example, when Obfuscating and DeObfuscating the following:
Var count = 1;
MyFunction();
It seems that the way it is translating it is like so:
var count = 1
MyFunction()
But they are missing the semi-colon in there. Can you help?
Just as a guide, if I am not mistaken, a semi-colon should literally be translated into a semi-colon when being obfuscated.. At least I think...
@jdiperla Do you have actual code that leads to a syntax error? Because semicolons should be optional in JavaScript.
$js = 'function addEvent(element, eventName, func) {
if (element.addEventListener) {
return element.addEventListener(eventName, func, false);
} else if (element.attachEvent) {
return element.attachEvent("on" + eventName, func);
}
};';
Above code will be translated in
eval(function(p,a,c,k,e,d){while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+c+'\\b','g'),k[c])}}return p}('7 8(0,2,1){4(0.3){5 0.3(2,1,9)}10 4(0.6){5 0.6("11"+2,1)}};',10,12,'element|func|eventName|addEventListener|if|return|attachEvent|function|addEvent|false|else|on'.split('|')))
Actually a white space is added after last character and not semi-colon. And semicolons are not optional in some scenarios. In my brackets editor large amount of white space is shown (about 20-30 blank
spaces).
@jdiperla The way packer works, you don't have to worry about semi-colons inside the program. It is smart enough to handle them. Only the one last semi-colon should be added after clearing the whitespaces.
@tholu Actually when you will add any other js over the packer code will crash entire site. I use 8-9 consistent js files and some js files generated on the fly, so cannot use packer if doesn't come with semicolon ending.
I have released 0.2.0 which includes the optional argument $removeSemicolons.