babel / babel/minify

Unneeded mangle on destructed function parameters used as shorthands in the function body

Open
#175 0 comments 0 reactions 0 assignees View on GitHub
enhancement
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.