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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classes with iterators are not tree-shaken #3561

Closed
devongovett opened this issue Dec 23, 2023 · 1 comment
Closed

Classes with iterators are not tree-shaken #3561

devongovett opened this issue Dec 23, 2023 · 1 comment

Comments

@devongovett
Copy link

When a class includes an iterator method using Symbol.iterator, it is no longer tree-shaken when unused.

(() => {
  class Test {
    *[Symbol.iterator]() {
      // do nothing
    }
  }
})()

Example

If you change this to *foo (still a generator function), or a non-generator with a static identifier as a name, it is tree-shaken. I believe this should be safe to tree shake with Symbol.iterator as well. SWC's minifier does so.

@evanw
Copy link
Owner

evanw commented Dec 23, 2023

Thanks for pointing this out. That’s obviously not great, and should be safe to do.

@evanw evanw closed this as completed in f8ae3af Dec 29, 2023
omar-azmi added a commit to omar-azmi/kitchensink_ts that referenced this issue Jan 8, 2025
…ide of the `Deque` class with the `[Symbol.iterator]()` method, since esbuild can now treeshake well known symbolic methods.

  github issue related to this optimization: evanw/esbuild#3561
omar-azmi added a commit to omar-azmi/kitchensink_ts that referenced this issue Jan 8, 2025
…ide of the `Deque` class with the `[Symbol.iterator]()` method, since esbuild can now treeshake well known symbolic methods.

  github issue related to this optimization: evanw/esbuild#3561
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants