Open koljada opened 2 months ago
This is a new one.
Its because it doesn't think theyre used as it doesn't properly understand the object destructuring with the spread operator, i.e. the preceeding arguments/destructured variables change what gets ...
spread into copy
.
The change needs to be in one of the Analysers, can't recall off the top of my head, pull requests welcome
I found an issue with destructuring objects with default values, haven’t had a chance to enter it yet, but if anyone can give ideas of where to look, I’ll try to take a pass at all if them. I’ve set aside tomorrow (5/9) to try and fix them.
That would be great, thanks
Without going deep into it i cant tell you exactly where, but from memory its to do with how it parses object literals. I cant remember exactly what the problem was, but the parser gets confused between two different notations/types of objects and it needed more than a quick bugfix to deal with it, that part of the parser needed reconsidering/rewriting
Probably in ParseObjectLiteralProperty
This one is a bit more than I have time for this week, I'll try to come back to it when I have another free day.
Hello @failwyn and @trullock Is the bug mentioned by @koljada fixed now? If yes from which version on?
I haven't fixed it. PRs welcome
Version 1.21.4
Describe the bug I'm using object desctructuring to remove object properties. For example:
const { avatar, timeline, backup, ...copy } = { ...user };
After this linecopy
object does not haveavatar
,timeline
andbackup
properties. But after minification not used variablesavatar
,timeline
andbackup
are removed. And as a result mycopy
object is identical to originaluser
object. Which is a big problem in my scenario. I tried to setRemoveUnneededCode
settings tofalse
but it didn't work.To Reproduce
Minified output or stack trace
const func=()=>{const n={avatar:Date(),timeline:Date(),backup:Date(),id:123,name:"Roman"},{...copy}=n;return copy};console.log(func())
Excepted output code
const func=()=>{const n={avatar:Date(),timeline:Date(),backup:Date(),id:123,name:"Roman"},{avatar, timeline, backup,...copy}=n;return copy};console.log(func())