putoutjs / minify

Minify with help of 🐊Putout
MIT License
12 stars 3 forks source link

Add to minification-benchmarks #28

Open sirenkovladd opened 1 day ago

sirenkovladd commented 1 day ago

Try running minification for these libraries and add yourself to the list

https://github.com/privatenumber/minification-benchmarks

coderaiser commented 1 day ago

I don’t mind if you do it, and share link here.

sirenkovladd commented 1 day ago

error with the first lib https://replit.com/@sirenkovladd/putoutminify#result.log

coderaiser commented 1 day ago

Could you please provide minimal example of code, about 10 lines that errored?

coderaiser commented 1 day ago

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Strict_non_simple_params

sirenkovladd commented 1 day ago
import {minify} from '@putout/minify';

async function main() {
  const body = `(function() {
    'use strict';
    function createElement() {
      for (let i in arguments) {
        childArray[i] = arguments[i + 2];
      }
    }
  })();`;
  eval(body)
  const result = minify(body);
  console.log(result);
  eval(result)
}

main();
(function(...args){'use strict';function a(){for(let i in args)childArray[i]=args[i+2]}})();
undefined:1
(function(...args){'use strict';function a(){for(let i in args)childArray[i]=args[i+2]}})();
                   ^^^^^^^^^^^^

SyntaxError: Illegal 'use strict' directive in function with non-simple parameter list
    at main (file:///private/var/folders/36/nhtbdyy51gg2n2snnk7c7gnr0000gn/T/tmp.09BhuIycnU/index.mjs:15:8)
    at file:///private/var/folders/36/nhtbdyy51gg2n2snnk7c7gnr0000gn/T/tmp.09BhuIycnU/index.mjs:18:1
    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:475:24)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:109:5)

Node.js v22.2.0

additional error:

sirenkovladd commented 1 day ago

I would like to note regarding your previous comment that the code runs successfully before minification

coderaiser commented 1 day ago

what do you mean by incorrectly replaced arguments?

coderaiser commented 23 hours ago

Just fixed 🎉. Is it works for you?

sirenkovladd commented 18 hours ago
import {minify} from '@putout/minify';

async function main() {
  // lodash
  const body = `;(function() {}.call(this));`
  eval(body)
  const result = minify(body);
  console.log(result);
  eval(result)
}

main();
❯ node lodash.cjs
;function(){}.call(this);
undefined:1
;function(){}.call(this);
 ^^^^^^^^

SyntaxError: Function statements require a function name
    at main (/private/var/folders/36/nhtbdyy51gg2n2snnk7c7gnr0000gn/T/tmp.09BhuIycnU/lodash.cjs:22:8)

Node.js v22.2.0
sirenkovladd commented 10 hours ago

I can't minimize d3, I waited more than 6 minutes but still didn't get the result

npm i d3

https://unpkg.com/browse/d3@7.9.0/dist/d3.js

import {minify} from '@putout/minify';
import { readFile } from 'node:fs/promises'

async function main() {
  const body = await readFile('./node_modules/d3/dist/d3.js', 'utf8');
  eval(body)
  const start = new Date();
  console.log(start);
  const result = minify(body);
  console.log(new Date());
  console.log(new Date() - start);
  eval(result)
}

main();
❯ node d3.mjs
2024-09-28T00:11:33.023Z
^C