mleibman / SlickGrid

A lightning fast JavaScript grid/spreadsheet
http://wiki.github.com/mleibman/SlickGrid
MIT License
6.81k stars 1.98k forks source link

failed to compile filter functions after minifier (at slick.dataview.js) #301

Open SQReder opened 12 years ago

SQReder commented 12 years ago

Simple filter function

    var filter = function(item, args){
        if (item.status != args.status) return false;
        return true;
    };

Minified

if(f.status!=e.status){return false}return true

and after replacing return statements at compileFilter() and compileFilterWithCaching() functions

if(f.status!=e.status){{ continue _coreloop; }return true

Voila! We've get invalid js code.

Fast fix for me - remove [;}] from regexp at

      var filterBody = filterInfo.body
          .replace(/return false[;}]/gi, "{ continue _coreloop; }")
          .replace(/return true[;}]/gi, "{ _retval[_idx++] = $item$; continue _coreloop; }")
          .replace(/return ([^;}]+?);/gi,
          "{ if ($1) { _retval[_idx++] = $item$; }; continue _coreloop; }");
dencey commented 12 years ago

another circumstance: a minified filter function like this

if(some condtions)return!1;return!0

will get a wrong 'compiledFilter', and no items will be displayed

mleibman commented 12 years ago

Right, the inliner parsing logic is rather simplistic right now, which is why it's optional and off by default. I'll tweak it a bit, but it probably still won't handle all the cases.

ericjohannsen commented 11 years ago

I have come across another case where the compiler is failing with minified code: http://stackoverflow.com/q/15031876/141172