Bug: transform code to unsafe code
Closed this issue ยท 20 comments
This lib will transform this code typeof(a) !== 'undefined'
to (a)!==void 0
, when 'a' is not defined, will introduce JS error.
More case that kill me hard:
// Before mangle
function everywhere() {}
function cool() { const list = []; for (const item of list) { everywhere() } }
// After mangle
function a() {}
function b() { const a = []; for (const b of a) { a() } }
Super realitic evident photo:
Good bye my fucking whole day -_-
May I suggest to stop mangle top-level function name? Or just completely stop mangle every name? The mangleClassNames
is not enough.
You should be extremely careful with mangling code man. Please refer this case if you wish to improve it: https://code.visualstudio.com/blogs/2023/07/20/mangling-vscode
This lib will transform this code typeof(a) !== 'undefined' to (a)!==void 0, when 'a' is not defined, will introduce JS error.
Just fixed ๐. Please re-install Minify, is it works for you?
May I suggest to stop mangle top-level function name? Or just completely stop mangle every name? The mangleClassNames is not enough.
Just landed support of option mangle
, now you can disable all mangle ๐ . Please re-install Minify, is it works for you?
Is the new commit use the same version notation 10.5.2
? Should I clear cache and redownload it because I'm using Deno.
You need to have @putout/minify@2.4.0
installed.
Ok, so that means refresh Deno cache: deno run -r main.ts
It works nice, thanks.
I would like to reopen this issue as mangle
option fails to work today. (It was really good yesterday though)
At first I suspect something wrong with Deno cache, so I look into its cache dir. But Deno get the right dep. However, to be safe, I remove a whole cache dir and re install. Still the mangling still be excuted even though I set it false.
import { minify } from "npm:minify@10.5.2";
const js_main = await minify(`${dir.src}/main.js`, {
js: { mangle: false, mangleClassNames: false },
});
Here is the @putout/minify@2.4.0
file from deno cache: minify.min.js.txt
maybe you could check md5 of this file with the original?
Could you please try to use @putout/minify
directly?
import { minify as minifyjs } from "npm:@putout/minify@2.4.0";
error: Uncaught (in promise) SyntaxError: Invalid regular expression flag. (1:8)
at e (file:///home/dangtu/.cache/deno/npm/registry.npmjs.org/@putout/minify/2.4.0/bundle/minify.min.js:1:199630)
at Ql.raise (file:///home/dangtu/.cache/deno/npm/registry.npmjs.org/@putout/minify/2.4.0/bundle/minify.min.js:1:240060)
at Ql.readRegexp (file:///home/dangtu/.cache/deno/npm/registry.npmjs.org/@putout/minify/2.4.0/bundle/minify.min.js:1:235589)
at Ql.parseExprAtom (file:///home/dangtu/.cache/deno/npm/registry.npmjs.org/@putout/minify/2.4.0/bundle/minify.min.js:1:401006)
at Ql.parseExprAtom (file:///home/dangtu/.cache/deno/npm/registry.npmjs.org/@putout/minify/2.4.0/bundle/minify.min.js:1:287740)
at Ql.parseExprSubscripts (file:///home/dangtu/.cache/deno/npm/registry.npmjs.org/@putout/minify/2.4.0/bundle/minify.min.js:1:396113)
at Ql.parseUpdate (file:///home/dangtu/.cache/deno/npm/registry.npmjs.org/@putout/minify/2.4.0/bundle/minify.min.js:1:395736)
at Ql.parseMaybeUnary (file:///home/dangtu/.cache/deno/npm/registry.npmjs.org/@putout/minify/2.4.0/bundle/minify.min.js:1:395354)
at Ql.parseMaybeUnaryOrPrivate (file:///home/dangtu/.cache/deno/npm/registry.npmjs.org/@putout/minify/2.4.0/bundle/minify.min.js:1:392237)
at Ql.parseExprOps (file:///home/dangtu/.cache/deno/npm/registry.npmjs.org/@putout/minify/2.4.0/bundle/minify.min.js:1:392337)
I wonder if it because I upgrade deno :?
Could you please try node.js for this purpose :)?
I'll try it later
It doesn't work, and what make me curious the most now is why it worked before and then it wasn't.
import {minify} from 'minify';
// import {minify} from '@putout/minify'; // I tried to install it but it doesn't work, what did I do wrong?
console.log(minify);
const js_main = await minify(`main.js`, {
js: { mangle: false, mangleClassNames: false },
})
console.log(js_main);
Did my code break it?
Have you tried to run in with nodejs?
Here is correct code:
import {minify} from '@putout/minify';
const js_main = await minify(`const hello = 5; const fn = (a) => a + '!'; fn(hello);`, {
mangle: false,
mangleClassNames: false,
})
console.log(js_main)
Have you tried to run in with nodejs?
Why would I lie to you?
Does the minify use OS lib?
Update, here is what happen on my version:
package.json
{
"name": "test-minify",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@putout/minify": "^2.4.0",
"minify": "^10.5.2"
},
"type": "module"
}
Does it happen on your PC?
Here is commit with test:
Please provide me example of code you do not want to be mangled
I've send the file to your email, please confirm if you received it.
Just landed an update ๐, please re-install Minify, is it works for you?
Thanks, for now it looks good. But let me confirm again tomorrow just to make sure that the bug is killed for good :D
It works fine since yesterday. I think we can close this issue and may it never return.