persvr / rql

Resource Query Language
http://www.persvr.org/
267 stars 49 forks source link

possible fix for losing function names in eval when minifying #36

Closed wshager closed 11 years ago

wshager commented 11 years ago

possible fix for minifying with closure compiler

wshager commented 11 years ago

Alas, this doesn't work for the condition by closure in filter...

neonstalwart commented 11 years ago

does this approach work?

return "(function(){return " + op.name + "('" + value.name + "').call(this" +
  // ...
wshager commented 11 years ago

No, since the operators are wrapped in an object. You'd just be calling "and", so that doesn't make sense. Also, referencing "exports" won't work, so the only thing I can think of is providing a function representation and replacing whatever I can grasp.

neonstalwart commented 11 years ago

i'm not following why op.name won't work. as i understand it, the goal is to bridge the gap between minified JS and the strings that get passed to eval. so let's say that the op function is minified to function e() { ... } then the reference to op.name should also be minified to e.name which would be "e" and so the string passed to eval effectively becomes "(function(){return e('" + value.name + "').call(this" and should work.

i ran my idea through http://closure-compiler.appspot.com/home and got

    function e(a) {
      return h[a] || f.i(a);
    }
    function g(a) {
      // ...
        return a instanceof Date ? a.valueOf() : "(function(){return " + e.name + "('" + a.name + "').call(this" + (a && a.b && 0 < a.b.length ? ", " + a.b.map(g).join(",") : "") + ")})";
      }
      return "string" === typeof a ? q(a) : a;
    }

am i missing something?

wshager commented 11 years ago

You're right. I tested this before, but probably with an anonymous function. I'll open a new pull request.