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

rollup treeshaking breaks es.string.split.js #494

Closed
AndrewLeedham opened this issue Mar 12, 2019 · 2 comments
Closed

rollup treeshaking breaks es.string.split.js #494

AndrewLeedham opened this issue Mar 12, 2019 · 2 comments

Comments

@AndrewLeedham
Copy link

Issue

When using rollup with babel to inject core-js polyfills, the SUPPORTS_Y check gets truncated from

var SUPPORTS_Y = !fails(function () { RegExp(MAX_UINT32, 'y'); });

to

var SUPPORTS_Y = !fails(function () {  });

rollup seems to see this as having no side-effects and tree-shakes it. Whereas in reality the side-effect is an error being thrown.

Repro

I created a minimal repro to showcase that toggling treeshaking through rollup is causing the issue: https://codesandbox.io/s/r0vj2k7znn. See line 22 on the dest/output-*.js files.

Possible Solution

Perhaps this is an issue for rollup. But a quick fix would be to just return the RegExp call:

var SUPPORTS_Y = !fails(function () { return RegExp(MAX_UINT32, 'y'); });
// or
var SUPPORTS_Y = !fails(function () { return new RegExp(MAX_UINT32, 'y'); });
@zloirock
Copy link
Owner

Seems it an issue for rollup. However, I can add a fallback on core-js side.

@AndrewLeedham
Copy link
Author

Thanks for adding the workaround @zloirock. Much appreciated. Is there any plan to release a beta version with this in?

nicketson added a commit to turbobridge/core-js that referenced this issue Apr 26, 2019
rollup treeshaking is removing the Object.getOwnPropertyNames
FAILS_ON_PRIMITIVES feature test.

This is related to these rollup issue
rollup/rollup#1771
rollup/rollup#2790

Related issues
zloirock#494
zloirock#513
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