Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing semicolon on final statement #2

Closed
sachya opened this issue Nov 27, 2015 · 10 comments
Closed

Missing semicolon on final statement #2

sachya opened this issue Nov 27, 2015 · 10 comments

Comments

@sachya
Copy link

sachya commented Nov 27, 2015

Hi tholu,
Thanks for continuing the legacy of js packer.
Can you fix the missing semicolon problem in the library?

@tholu
Copy link
Owner

tholu commented Nov 27, 2015

@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!

@jdiperla
Copy link

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?

@jdiperla
Copy link

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...

@tholu
Copy link
Owner

tholu commented Dec 15, 2015

@jdiperla Do you have actual code that leads to a syntax error? Because semicolons should be optional in JavaScript.

@sachya
Copy link
Author

sachya commented Dec 16, 2015

$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).

@sachya
Copy link
Author

sachya commented Dec 16, 2015

@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
Copy link
Owner

tholu commented Dec 16, 2015

@sachya But this code will run fine packed as well? Just tested on jsfiddle.

@sachya
Copy link
Author

sachya commented Dec 18, 2015

@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.

@tholu
Copy link
Owner

tholu commented Mar 21, 2016

I just added an optional argument, whether to remove semicolons from the code.
@jdiperla @sachya Can you tell me if this fixes this problem for you? Then I can tag a release for that change.

@tholu
Copy link
Owner

tholu commented Apr 19, 2016

I have released 0.2.0 which includes the optional argument $removeSemicolons.

@tholu tholu closed this as completed Apr 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants