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

Syntax Regular Expression Error in IE #479

Closed
babel-bot opened this issue Jan 22, 2019 · 10 comments
Closed

Syntax Regular Expression Error in IE #479

babel-bot opened this issue Jan 22, 2019 · 10 comments

Comments

@babel-bot
Copy link

Original issue submitted by @Chun-MingChen in babel/babel#9380

Bug Report

Current Behavior

core-js@2.6.x start support sticky flag y in modules/es6.regexp.split.js
Unfortunately, this feature IE didn't support (see http://kangax.github.io/compat-table/es6/#test-RegExp_y_and_u_flags).

SCRIPT5017: Syntax error in regular expression

ref: https://github.com/getify/You-Dont-Know-JS/blob/master/es6%20&%20beyond/ch2.md#sticky-flag

Possible Solution
Remove ^ in package.json.

Babel Configuration (.babelrc, package.json, cli command)

{
  "name": "@babel/polyfill",
  "dependencies": {
-   "core-js": "^2.5.7",
+   "core-js": "2.5.7",
    "regenerator-runtime": "^0.12.0"
  }
}

Environment

  • Babel version(s): 6.5.2
  • Node/npm version: 8.14.0
@zloirock
Copy link
Owner

zloirock commented Jan 22, 2019

@Chun-MingChen @waynelai614 could you add a code which causes a problem?

@waynelai614
Copy link

waynelai614 commented Jan 22, 2019

@zloirock
This line

var SUPPORTS_Y = !!(function () { try { return new RegExp('x', 'y'); } catch (e) {} })();

https://github.com/zloirock/core-js/blob/v2/modules/es6.regexp.split.js#L17

IE didn't support both new RegExp('x', 'y') and /x/y

I'll cause error start from core-js@2.6.0 (#411)

same issue from #372

@zloirock
Copy link
Owner

It's calling of RegExp constructor, not syntax construction, and try / catch block catch this error. core-js tested and works in IE. So, please, add a reproducible example.

@zloirock
Copy link
Owner

Maybe the problem in minified code and your minifier transpile new RegExp('x', 'y') -> /x/y?

@waynelai614
Copy link

waynelai614 commented Jan 22, 2019

@zloirock
yes, you're right.
The problem is our minified code compress it to /x/y 😢

REPL link

@zloirock
Copy link
Owner

Ok, I'll try to add a workaround for that.

@zloirock
Copy link
Owner

Also, it should be fixed on babel side because core-js is not the only place where used this feature detection.

@zloirock
Copy link
Owner

It's already filed babel/minify#928

@waynelai614
Copy link

@zloirock
Thanks for the quick fix, hope you find a good job soon 😃

@chunming-c
Copy link

It's already filed babel/minify#928

Nice work and great speed 🎉

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

4 participants