Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Destructuring empty array with invalid Symbol.iterator #15154

Closed
1 task
p51lee opened this issue Nov 7, 2022 · 2 comments 路 Fixed by #15183
Closed
1 task

[Bug]: Destructuring empty array with invalid Symbol.iterator #15154

p51lee opened this issue Nov 7, 2022 · 2 comments 路 Fixed by #15183
Labels
i: enhancement outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@p51lee
Copy link

p51lee commented Nov 7, 2022

馃捇

  • Would you like to work on a fix?

How are you using Babel?

Other (Next.js, Gatsby, vue-cli, ...)

Input code

var [ ] = { [ Symbol . iterator ] : ( ) => [ ] } ;

Configuration file name

No response

Configuration

No response

Current and expected behavior

In input.js, Symbol.iterator is lazily evaluated so input.js is terminated without error.
On the other hand, Array.from(iter) in output.js eagerly throws TypeError:

$ node input.js # no error

$ node output.js
output.js:48
    return Array.from(iter);
                 ^

TypeError: undefined is not a function
    at Function.from (<anonymous>)
    at _iterableToArray (output.js:48:18)
    at _toArray (output.js:17:5)
    at Object.<anonymous> (output.js:56:23)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.11.0

Environment

Reproduction on Babel's own REPL

Possible solution

No response

Additional context

No response

@babel-bot
Copy link
Collaborator

Hey @p51lee! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@SuperSodaSea
Copy link
Contributor

I believe #15183 also fixes this problem. Empty array destructuring should only check the result of [Symbol.iterator]() is an object, and not calling its next() (but will call its return() if exist).

SuperSodaSea added a commit to SuperSodaSea/babel that referenced this issue Nov 11, 2022
nicolo-ribaudo pushed a commit that referenced this issue Nov 25, 2022
Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>
Fixes #15154
Fixes #15168
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Feb 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: enhancement outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants