You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running Vite's build process to create a legacy build using plugin-legacy, using the spread operator on a Set inside an Array literal produces different behavior than expected.
For example, [...new Set([1, 1, 2, 3])] will evaluate to [1, 2, 3] in modern browsers. However, the transformed code is [].concat(new Set([1, 1, 2, 3])), which will evaluate to [Set(3)] instead.
In troubleshooting it I narrowed it down to the loose option of babel-preset-env: https://github.com/vitejs/vite/blob/main/packages/plugin-legacy/index.js#L251. Setting it to false results in the code being transformed how I'd expect, but it affects all plugins which probably isn't ideal. I'd be happy to submit a PR, just not entirely sure what the best fix is yet - maybe turning loose off for only proposal-object-rest-spread, if possible?
The code compiles as expected after that, but the recordAndRemovePolyfillBabelPlugin plugin doesn't catch the import statements from it. A plugin like https://github.com/uiwjs/babel-plugin-transform-remove-imports does though, so updating how recordAndRemovePolyfillBabelPlugin works to use CallExpression and/or ImportDeclaration might be the way to go.
Describe the bug
When running Vite's build process to create a legacy build using plugin-legacy, using the spread operator on a Set inside an Array literal produces different behavior than expected.
For example,
[...new Set([1, 1, 2, 3])]
will evaluate to[1, 2, 3]
in modern browsers. However, the transformed code is[].concat(new Set([1, 1, 2, 3]))
, which will evaluate to[Set(3)]
instead.In troubleshooting it I narrowed it down to the
loose
option of babel-preset-env: https://github.com/vitejs/vite/blob/main/packages/plugin-legacy/index.js#L251. Setting it to false results in the code being transformed how I'd expect, but it affects all plugins which probably isn't ideal. I'd be happy to submit a PR, just not entirely sure what the best fix is yet - maybe turning loose off for onlyproposal-object-rest-spread
, if possible?Reproduction
https://github.com/mwojtul/vite-plugin-legacy-spread-operator-on-set
System Info
vite
version: 2.1.5The text was updated successfully, but these errors were encountered: