sindresorhus/deep-assign

Set not being overwritten

Closed this issue · 3 comments

const assign = require('deep-assign')

const foo = {
  keys: new Set(['123456'])
}

const bar = assign({}, {keys: new Set()}, foo)

console.log('foo.keys.size = ', foo.keys.size)
console.log('bar.keys.size = ', bar.keys.size)

console.log('foo.keys.has(123456) = ', foo.keys.has('123456'))
console.log('bar.keys.has(123456) = ', bar.keys.has('123456'))

Yields:

foo.keys.size =  1
bar.keys.size =  0
foo.keys.has(123456) =  true
bar.keys.has(123456) =  false

On the first iteration https://github.com/sindresorhus/deep-assign/blob/master/index.js#L29 is being hit and works as expected. When the second object is iterated, the to object now has a keys property that causes https://github.com/sindresorhus/deep-assign/blob/master/index.js#L31 to be hit instead. The code in this path then attempt to turn theSet into a vanilla Object and iterate the keys on it. Since Set doesn't work as expected in this code path, the second iteration never assigns anything.

kevva commented

This module is deprecated.

I see this project is deprecated. Closing.