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

Cannot supply flags when constructing one RegExp from another. #311

Closed
mbrevda opened this issue Jul 18, 2017 · 12 comments
Closed

Cannot supply flags when constructing one RegExp from another. #311

mbrevda opened this issue Jul 18, 2017 · 12 comments

Comments

@mbrevda
Copy link

mbrevda commented Jul 18, 2017

When duplicating regexes on some older browsers, flags cannot be added (testing Safari 6 atm, due to embedded device constraints). My particular error is being thrown on

new RegExp(expandsOnNFD, 'g')

in which case expandsOnNFD is already a regex, which is being duplicated.

Here is a test case: http://jsbin.com/nidevotuqi
Im currently including the code from here

@brettz9
Copy link
Collaborator

brettz9 commented Jul 18, 2017

Could you try replacing

new RegExp(expandsOnNFD, 'g')

with

new RegExp(expandsOnNFD.source, 'g')

?

I guess the copying of regex objects is an ES6 feature that Babel is not yet polyfilling.

If the fix above works, it'd be helpful to know whether there are any other issues in such older browsers (ideally tested against our various browser tests) as it'd be nicer to keep with the more succinct syntax if it's not going to be possible to support older browsers anyways (though of course, if we can support, that would be ideal).

@mbrevda
Copy link
Author

mbrevda commented Jul 19, 2017

I can confirm that on this Safari 6 esqueue browser, adding .source prevents the error.

@brettz9
Copy link
Collaborator

brettz9 commented Jul 26, 2017

Sorry been busy--this should be addressed by babel/babel#5978 for which I hope to get to a PR, though probably not at least for a week or so.

@mbrevda
Copy link
Author

mbrevda commented Jul 26, 2017 via email

@brettz9
Copy link
Collaborator

brettz9 commented Aug 3, 2017

Sorry but when you were testing it, do you recall whether you were including the babel polyfill file or only the indexeddbshim file?

@mbrevda
Copy link
Author

mbrevda commented Aug 4, 2017 via email

@brettz9
Copy link
Collaborator

brettz9 commented Sep 14, 2017

Going to close this unless someone else can confirm the babel polyfill doesn't solve it...

@brettz9 brettz9 closed this as completed Sep 14, 2017
@StabbarN
Copy link

StabbarN commented Apr 5, 2018

Babel polyfill using Babel 7 with babel-preset-env useBuiltIns set to 'entry' doesn't work. It results in "Cannot supply flags when constructing one RegExp from another"

Docs about useBuiltIns: https://new.babeljs.io/docs/en/babel-preset-env.html#usebuiltins

I made an example here https://github.com/StabbarN/indexeddbshim-regexp

It seems like Babel's preset-env strips some regexp polyfill.

@brettz9 brettz9 reopened this Apr 5, 2018
@brettz9
Copy link
Collaborator

brettz9 commented Apr 5, 2018

It'd be great if you could take a look at babel/babel#5978 or at least report your test case there... I'm pretty limited atm to investigate more closely...

@brettz9
Copy link
Collaborator

brettz9 commented Apr 5, 2018

Thank you very much for building that test case and reporting this to Babel, @StabbarN (and @mbrevda for the original issue). Glad we can use more elegant code as well as solve things at the root, but if it takes too long, let me know and we can just add the longer way...

brettz9 added a commit to brettz9/IndexedDBShim that referenced this issue Apr 9, 2018
…porarily

    circumvent current limitations in Babel until
    <babel/babel#5978> addressed; (see also
    <indexeddbshim#311 (comment)>);
    fixes indexeddbshim#311
- Linting: Expand ESLint file coverage and apply minor linting fix to test file
- npm: Update `eventtargeter` to avoid automatic `Object.setPrototypeOf`
    calls (make conditional on `CFG.fullIDLSupport`); fixes indexeddbshim#313
- npm: Bump to 3.6.0
brettz9 added a commit to brettz9/IndexedDBShim that referenced this issue Apr 9, 2018
…porarily

    circumvent current limitations in Babel until
    <babel/babel#5978> addressed; (see also
    <indexeddbshim#311 (comment)>);
    fixes indexeddbshim#311
- Linting: Expand ESLint file coverage and apply minor linting fix to test file
- Testing: Update web-platform-tests and our tests accordingly
- npm: Update `eventtargeter` to avoid automatic `Object.setPrototypeOf`
    calls (make conditional on `CFG.fullIDLSupport`); fixes indexeddbshim#313
- npm: Bump to 3.6.0
@brettz9 brettz9 closed this as completed in fc1c0f3 Apr 9, 2018
@brettz9
Copy link
Collaborator

brettz9 commented Apr 9, 2018

In publishing 3.6.0 just now, I went ahead and stomached the 7 extra characters to make it work for everybody. :-) I made a note to revert once Babel may apply a fix.

@StabbarN
Copy link

No release yet but this PR seems to fix it babel/babel#7809

brettz9 added a commit that referenced this issue Mar 5, 2021
- Linting (ESLint): As per latest ash-nazg
- Build: Set `preventAssignment: true` in `@rollup/plugin-replace`
- Refactoring: Switch to native `padStart` given minimum Node version
- Refactoring: Switch to copy RegExp constructor now that Babel should have
    fixed (see #311)
- npm: Update `unicode-10.0.0` to `@unicode/unicode-13.0.0`
- npm: Change from deprecated `request`/`request-promise-native` to `got`
- npm: Update `typeson`, `typeson-registry` deps.
- npm: Remove `regenerator-runtime` dep.
- npm: Remove `remark`
- npm: Update devDeps.
- npm: Bump to 7.1.0
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