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

Tree-shaking of D3 broken since 0.50. #1707

Closed
mbostock opened this issue Nov 8, 2017 · 5 comments
Closed

Tree-shaking of D3 broken since 0.50. #1707

mbostock opened this issue Nov 8, 2017 · 5 comments

Comments

@mbostock
Copy link
Contributor

mbostock commented Nov 8, 2017

Reproduction here:

https://bl.ocks.org/mbostock/40e26f283013422491ca475e2513b08c

The crash occurs on this line in transition.style:

https://github.com/d3/d3-transition/blob/d894452ffd3ff69effe1eb1fdfcb5fd9236ba8f3/src/transition/style.js#L12

It’s trying to reference d3.style imported from d3-selection, but for some reason the import is ignored. Maybe it’s because d3-selection is also imported by the entry index.js, but d3.style is only used internally by d3-transition? I’ll try to reduce this to a smaller test case.

@mbostock
Copy link
Contributor Author

mbostock commented Nov 8, 2017

Looking a little closer at the generated code, it appears to have something to do with the use of the comma operator:

var value0 = styleValue(this, name),
    value1 = value(this);
if (value1 == null) value1 = (this.style.removeProperty(name), style(this, name));

Notice that the first reference to style is properly renamed to styleValue (the name Rollup chose for the d3.style import from d3.selection), but the second style is not.

@lukastaegert
Copy link
Member

Thanks for providing a repo and digging into this, this is very helpful!
I'll try to address this during the next days.

Just a question: Is this happening for 0.50.0 as well as 0.50.1 or just for the latter? There have been some changes to sequence (i.e. comma) expression handling in 0.50.1.

@mbostock
Copy link
Contributor Author

mbostock commented Nov 8, 2017

In my testing it appeared broken in 0.50.0, 0.50.1 and 0.51.0. I will investigate further today as I have time. Thanks for looking into this and the prompt response! (Also, very excited that you are working on tree-shaking improvements. Thank you!)

@nathancahill
Copy link
Contributor

nathancahill commented Nov 8, 2017

I think this is the same issue I found in #1709. Bisecting lead me to 0.50.1, and I believe it has to do with variable names not being tracked correctly in SequenceExpressions. I have a minimal Rollup repl that shows this problem in that issue.

@nathancahill
Copy link
Contributor

nathancahill commented Nov 8, 2017

Here's another example of the issue when including Redux-Immutable:

var _utilities = require('./utilities');

(0, _utilities.validateNextState)(nextDomainState, reducerName, action);

_utilities gets shaken as an unused import. I suspect this issue affects a lot of code generated by Babel, since Babel uses (0, required.func)() to avoid passing required as the this context to func. Again, fine in 0.50.0, but breaking in 0.50.1.

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

No branches or pull requests

3 participants