putoutjs / minify

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

Incorrect order of initialization variables #18

Closed sirenkovladd closed 5 months ago

sirenkovladd commented 5 months ago

Incorrect order of initialization variables

import { minify } from "@putout/minify";

const source = `
const c = (e) => e.w;
const w = (c) => c;
function f(e) {
  const { n } = e;
  e.w = n;
  const q = c(e);
  return q && w(q)
}
console.log(f({n:1}))`;

eval(source);
const result = minify(source);
console.log(result);
eval(result);
❯ node test.js
1
var c=e=>e.w,w=c=>c;function f(e){var{n}=e,q=c(e);e.w=n;return q&&w(q)}console.log(f({n:1}));
undefined
coderaiser commented 5 months ago

Fixed in #17 🎉. Is it works for you?

sirenkovladd commented 5 months ago

No, same result

"dependencies": {
    "@putout/minify": "^3.16.0"
  }
coderaiser commented 5 months ago

Try to re-install @putout/minify.

sirenkovladd commented 5 months ago
❯ node index.js
1
var c=e=>e.w,w=c=>c;function f(e){const{n}=e,q=c(e);e.w=n;return q&&w(q)}console.log(f({n:1}));
undefined

❯ cat node_modules/@putout/minify/package.json | jq '.version'
"3.17.1"
coderaiser commented 5 months ago

Added ability to disable mergeVariables.

sirenkovladd commented 5 months ago

But it's a useful feature I'd like to use the problem is that it may not work correctly in such scenarios

coderaiser commented 5 months ago

Here is the code, you can play with it, if you get any ideas how to make this work, I’ll merge.

coderaiser commented 5 months ago

Fixed in latest version of @putout/minify 🎉