babel: [Bug]: Destructured symbol fails on IE 10+

💻

  • Would you like to work on a fix?

How are you using Babel?

@rollup/plugin-babel

Input code

const symbol = Symbol('desc')

export default ({
  [symbol]: alias = {},
  ...rest
}) => {
  return {
    ...rest,
    symbol: alias
  }
}

Configuration file name

babel.config.json

Configuration

{
  "presets": [
    "@babel/env"
  ],
  "exclude": [
    "node_modules/**"
  ],
  "targets": ["since 2000"]
}

Current and expected behavior

Actually, it throws “@@toPrimitive must return a primitive value.” which doesn’t seems to be catchable.

But the objects passed are pretty fine, since if I extract the parts separately, it works.

const symbol = Symbol('desc')

export default ({
  ...properties
}) => {
  return {
    ...properties,
    [symbol]: properties[symbol]
  }
}

Environment

  • Babel version: 7.16.7
  • Node: 16.3.0
  • npm: 7.18.1
  • OS: Windows 10
  • Monorepo: no

Possible solution

No response

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (8 by maintainers)

Most upvoted comments

Ok, I try to make a minimal repo to share it with you (I just can’t share the real one actually, it’s a project of my client and it isn’t intended to be open source right now)