ndparker / rjsmin

Fast javascript minifier for Python
http://opensource.perlig.de/rjsmin/
Apache License 2.0
60 stars 15 forks source link

rjsmin deletes some code after a regex #13

Closed darrint closed 5 years ago

darrint commented 6 years ago

The following code is handled incorrectly by rjsmin:

// https://github.com/zloirock/core-js/issues/280
$export($export.P + $export.F * /Version\/10\.\d+(\.\d+)? Safari\//.test(userAgent), 'String', {
  padEnd: function padEnd(maxLength /* , fillString = ' ' */) {
    return $pad(this, maxLength, arguments.length > 1 ? arguments[1] : undefined, false);
  }
});

The result I get is:

$export($export.P+$export.F*/Version\/10\.\d+(\.\d+)?Safari\padEnd:function padEnd(maxLength){return $pad(this,maxLength,arguments.length>1?arguments[1]:undefined,false);}});

Notice that a significant amount of code between "Safari" and "padEnd" is deleted.

ndparker commented 6 years ago

Ew!

The * in front is not recognized as a valid 'pre-regex' character., which leads to the regex not being recognized at all. Which in turn removes everything after // in this line, because it's seen as a comment. Parentheses around the regex.test() would help here.

Sorry to say: this is just bad-styled code ;-) I'll add +, - and * as valid pre-chars. Let's hope it won't break anything else.

Thanks for the report.

kottenator commented 6 years ago

I have the same issue, even the same piece of code is broken :) It's part of babel-polyfill which is auto-generated and I can't easily modify it.

ndparker commented 5 years ago

This has finally been fixed in Release 1.1.0.