Unneeded mangle on destructed function parameters used as shorthands in the function body
- Dominant language
- JavaScript
- Stars
- 4.4k
- Forks
- 217
- PR merge metrics
- No merged PRs in 30d
Description
Manglifier adds shorter names from destructing parameters (and it's good in most cases), however, it produces bigger code if these destruction parameters are used for shorthand object creation inside function body.
It's easier to show on example
Original source:
``` javascript
link.onload = ({ target: { dataset: { style = 'normal', weight = 400, name = 'Roboto' }, href } }) => {
const font = new FontFace(name, `url(${href}) format("woff2")`, { style, weight });
doc.fonts.add(font);
font.load();
font.loaded.then(() =>
doc.documentElement.classList.add(['wf', ...name.toLowerCase().split(' '), 'active'].join('-'))
);
};
```
minifies into:
``` javascript
b.onload=({target:{dataset:{style:d='normal',weight:g=400,name:h='Roboto'},href:c}})=>{const i=new FontFace(h,`url(${c}) format("woff2")`,{style:d,weight:g});a.fonts.add(i),i.load(),i.loaded.then(()=>a.documentElement.classList.add(['wf',...h.toLowerCase().split(' '),'active'].join('-')))}
```
As you may see `style` and `width` from parameters destructions are used only as shorthand properties inside function, so, adding renaming parameters `d` and `g` only added 6 bytes to resulted code without any benefits.
Contributor guide
Assessment
This issue has not been assessed yet.