zoffixznet / JavaScript-Minifier

JavaScript::Minifier perl module
9 stars 6 forks source link

Handle the case when js code returns a regexp from a function #11

Closed faf closed 3 years ago

faf commented 3 years ago

In short, it fixes #10 .

That particular problem was caused by lack of handling the special case when a function contained return statement followed by a regular expression. The code treated initial slash of regexp as division operator, so the quote inside the regexp was treated as the beginning of a string, and so on, and so forth.

For example, an attempt to minify the code below caused unterminated single quoted string literal error.

var b=function(a){return /(\")/.test(a)}; console.log(b('"'));

Now it works. And it seems like minification of CKEditor mentioned in znuny/Znuny#6 goes well too (though, that should be double checked).

faf commented 3 years ago

BTW, seems like it also fixes #2 . At least, the code mentioned in that issue now could be minified without errors (though, IDK whether it's working after minification).

zoffixznet commented 3 years ago

Thank you very much. Version 1.15 with this fix pushed to CPAN.