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

RegExp.toString gives incorrect result without RegExp.flags #536

Closed
bz2 opened this issue Apr 26, 2019 · 1 comment · Fixed by #537
Closed

RegExp.toString gives incorrect result without RegExp.flags #536

bz2 opened this issue Apr 26, 2019 · 1 comment · Fixed by #537
Labels

Comments

@bz2
Copy link
Contributor

bz2 commented Apr 26, 2019

The RegExp.toString polyfill creates invalid patterns in the form /a/undefined unless the browser either supports RegExp.flags natively or that is also polyfilled. This is an issue when trying to use targetted imports as created by the @babel/preset-env setting useBuiltIns: 'usage'.

From the compat data, this is a problem for browsers like IE 11 and Edge, as Chrome/Firefox and so on have had native support for a while:
https://github.com/zloirock/core-js/blob/v3.0.1/packages/core-js-compat/src/data.js#L786

Tracking this down took a while, so I created minimal-ish project that reproduces the problem for demonstration:
https://github.com/zegami/test_core_regexp

bz2 added a commit to bz2/core-js that referenced this issue Apr 26, 2019
When the flags property is not available on RegExp, the internals
regexp-flags implementation should be used regardless of DESCRIPTORS.

Fixes: zloirock#536
@bz2
Copy link
Contributor Author

bz2 commented Apr 26, 2019

As a workaround, if a file depend on toString() for RegExp can manually include the core-js import for regexp/flags too:

// TODO: Remove when zloirock/core-js#536 is fixed upstream.
import 'core-js/es/regexp/flags';

This works even if the regexp/to-string polyfill is autocreated by @babel/preset-env.

@zloirock zloirock added the bug label Apr 27, 2019
bz2 added a commit to bz2/core-js that referenced this issue Apr 29, 2019
When the flags property is not available on RegExp, the internals
regexp-flags implementation should be used regardless of DESCRIPTORS.

Fixes: zloirock#536
bz2 added a commit to bz2/core-js that referenced this issue Apr 29, 2019
When the flags property is not available on RegExp, the internals
regexp-flags implementation should be used regardless of DESCRIPTORS.

Fixes: zloirock#536
bz2 added a commit to bz2/core-js that referenced this issue May 3, 2019
When the flags property is not available on RegExp, the internals
regexp-flags implementation should be used regardless of DESCRIPTORS.

Fixes: zloirock#536
zloirock pushed a commit that referenced this issue May 10, 2019
When the flags property is not available on RegExp, the internals
regexp-flags implementation should be used regardless of DESCRIPTORS.

Fixes: #536
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants