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 syntax error in IE when using Google Closure Compiler #972

Closed
Grundik opened this issue Aug 17, 2021 · 4 comments
Closed

RegExp syntax error in IE when using Google Closure Compiler #972

Grundik opened this issue Aug 17, 2021 · 4 comments

Comments

@Grundik
Copy link

Grundik commented Aug 17, 2021

There are several places in code, where are workarounds for IE misunderstanding of some regexp flags:

  • internals/regexp-sticky-helpers.js for flag 'y';
  • internals/regexp-unsupported-dot-all.js for flag 's';
  • internals/regexp-unsupported-ncg.js for flag 'g'.

Workarounds are like:

// babel-minify transpiles RegExp('a', 'y') -> /a/y and it causes SyntaxError,
var RE = function (s, f) {
  return RegExp(s, f);
};

exports.UNSUPPORTED_Y = fails(function () {
  var re = RE('a', 'y');
  re.lastIndex = 2;
  return re.exec('abcd') != null;
});

and

module.exports = fails(function () {
  // babel-minify transpiles RegExp('.', 's') -> /./s and it causes SyntaxError
  var re = RegExp('.', (typeof '').charAt(0));
  return !(re.dotAll && re.exec('\n') && re.flags === 's');
});

That could work fine with Babel, but Google Closure Compiler cannot be fooled like that. It understands such tricks, and still compiles code into failing regexps.

That could be prevented by using "@noinline" flag, like this:

// babel-minify transpiles RegExp('a', 'y') -> /a/y and it causes SyntaxError,
/** @noinline */
var RE = function (s, f) {
  return RegExp(s, f);
};

in all 3 places.

@zloirock
Copy link
Owner

Thanks for the issue. However, such directives-comments will not work if you will pass already minified core-js with removed comments to Closure Compiler - that confuses me.

@Grundik
Copy link
Author

Grundik commented Aug 17, 2021

Yes, thats a small problem. But if one uses google closure compiler, there are no point to compile minified files. Its better to use source files, to get useful source maps.

@zloirock
Copy link
Owner

Could you try to add

var RegExp = require('../internals/global').RegExp;

at the top of those files?

@Grundik
Copy link
Author

Grundik commented Aug 17, 2021

Yes, that works too, compiles into

var d=a(17).RegExp;b.UNSUPPORTED_Y=c(function(){var e=d("a","y"); .... }

with SIMPLE compilation level.

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