-
Notifications
You must be signed in to change notification settings - Fork 139
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
optimize bundle size #66
base: master
Are you sure you want to change the base?
Conversation
Tests still pass: npm run test
> [email protected] test /Users/andy/work/js/json-logic-js
> gulp test
[21:33:26] Using gulpfile ~/work/js/json-logic-js/gulpfile.js
[21:33:26] Starting 'test'...
Using cached applies() tests
Using cached rule_like() tests
Including 39 rule_like() tests
Including 275 applies() tests
Summary:
┌────────────────────────────────────────────┬────────┬────────┬───────┬─────────┐
│ File │ Failed │ Passed │ Total │ Runtime │
├────────────────────────────────────────────┼────────┼────────┼───────┼─────────┤
│ /Users/andy/work/js/json-logic-js/logic.js │ 0 │ 345 │ 345 │ 114 │
└────────────────────────────────────────────┴────────┴────────┴───────┴─────────┘
[21:33:27] Finished 'test' after 1.33 s |
* @return {Function} Operator function as specified by param | ||
*/ | ||
function generateBinaryOperation(operations, operator) { | ||
operations[operator] = new Function("a", "b", "return a" + operator + "b;"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this equivalent of eval
the code. I do understand the difference between eval
& new Function
(closure in new Function), but the concern that many users like me would have for avoiding eval
& new Function
would be around Content Security Policy
Read https://developer.chrome.com/extensions/contentSecurityPolicy#JSEval for more info
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your feedback @computnik
Well, eval
has access to current scope and local variables, in contrast to the new Function
constructor - which has not!
This difference is very often miss-understood and has plenty of discussions on the web already.
Regarding CSP, your are right, it could make problems, especially in chrome.
https://stackoverflow.com/questions/4599857/are-eval-and-new-function-the-same-thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway meanwhile we have forked and completely rewrote this project and I added JSON-Schemas for all operators.
https://github.com/axa-ch/json-logic-js
Really great tool.
I'm just keen if the bundle size could be reduzed by:
Before:
https://bundlephobia.com/[email protected]
Now:
4033
bytes/3.94kB
Minified - https://skalman.github.io/UglifyJS-online/1534
bytes/1.498kB
Minified + Gzipped (level 6) - https://dafrok.github.io/gzip-size-online/