Skip to content

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

@Grundik

Description

@Grundik

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions