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

Fix Rollup treeshaking #2456

Closed
wants to merge 1 commit into from
Closed

Fix Rollup treeshaking #2456

wants to merge 1 commit into from

Conversation

drwpow
Copy link

@drwpow drwpow commented Feb 4, 2021

Problem

When running Rollup on this library with the default behavior, it produces invalid JS:

// original (valid)
var wiggle = function wiggle(freq, amp) {
  // …
}.bind(this);

// rollup (invalid)
function wiggle(freq, amp) {
  // …
}.bind(this);

This is because it sees var wiggle is unused, which it is. It also occupies the same namespace as function wiggle.

Changes

This makes a simple change to the code. This makes it easier for Rollup (and other bundlers) to handle, with an invisible change:

- var wiggle = function wiggle(freq, amp) {
+ function wiggle(freq, amp) {
  // …
- }.bind(this);
+ }
+ wiggle.bind(this);

This is much easier for bundlers to prepare.

@drwpow
Copy link
Author

drwpow commented Feb 4, 2021

Closing; this should be handled here: rollup/rollup#3950

@drwpow drwpow closed this Feb 4, 2021
@drwpow drwpow deleted the drwpow/treeshaking branch February 4, 2021 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant