diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8d3079031abc..e6c86c3347b2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,6 @@
## Changelog
##### Unreleased
+- Added a workaround of a Closure Compiler unsafe optimization, [#972](https://github.com/zloirock/core-js/issues/972)
- One more fix crashing of `Object.create(null)` on WSH, [#970](https://github.com/zloirock/core-js/issues/970)
##### 3.16.1 - 2021.08.09
diff --git a/packages/core-js/internals/regexp-sticky-helpers.js b/packages/core-js/internals/regexp-sticky-helpers.js
index 6fecac12cd62..289634764772 100644
--- a/packages/core-js/internals/regexp-sticky-helpers.js
+++ b/packages/core-js/internals/regexp-sticky-helpers.js
@@ -1,19 +1,18 @@
var fails = require('../internals/fails');
+var global = require('../internals/global');
-// babel-minify transpiles RegExp('a', 'y') -> /a/y and it causes SyntaxError,
-var RE = function (s, f) {
- return RegExp(s, f);
-};
+// babel-minify and Closure Compiler transpiles RegExp('a', 'y') -> /a/y and it causes SyntaxError
+var $RegExp = global.RegExp;
exports.UNSUPPORTED_Y = fails(function () {
- var re = RE('a', 'y');
+ var re = $RegExp('a', 'y');
re.lastIndex = 2;
return re.exec('abcd') != null;
});
exports.BROKEN_CARET = fails(function () {
// https://bugzilla.mozilla.org/show_bug.cgi?id=773687
- var re = RE('^r', 'gy');
+ var re = $RegExp('^r', 'gy');
re.lastIndex = 2;
return re.exec('str') != null;
});
diff --git a/packages/core-js/internals/regexp-unsupported-dot-all.js b/packages/core-js/internals/regexp-unsupported-dot-all.js
index a48532f832e7..3398349db048 100644
--- a/packages/core-js/internals/regexp-unsupported-dot-all.js
+++ b/packages/core-js/internals/regexp-unsupported-dot-all.js
@@ -1,7 +1,10 @@
var fails = require('./fails');
+var global = require('../internals/global');
+
+// babel-minify and Closure Compiler transpiles RegExp('.', 's') -> /./s and it causes SyntaxError
+var $RegExp = global.RegExp;
module.exports = fails(function () {
- // babel-minify transpiles RegExp('.', 's') -> /./s and it causes SyntaxError
- var re = RegExp('.', (typeof '').charAt(0));
+ var re = $RegExp('.', 's');
return !(re.dotAll && re.exec('\n') && re.flags === 's');
});
diff --git a/packages/core-js/internals/regexp-unsupported-ncg.js b/packages/core-js/internals/regexp-unsupported-ncg.js
index 064c9e51a6dd..94ebefbdbb50 100644
--- a/packages/core-js/internals/regexp-unsupported-ncg.js
+++ b/packages/core-js/internals/regexp-unsupported-ncg.js
@@ -1,8 +1,11 @@
var fails = require('./fails');
+var global = require('../internals/global');
+
+// babel-minify and Closure Compiler transpiles RegExp('.', 'g') -> /./g and it causes SyntaxError
+var $RegExp = global.RegExp;
module.exports = fails(function () {
- // babel-minify transpiles RegExp('.', 'g') -> /./g and it causes SyntaxError
- var re = RegExp('(?b)', (typeof '').charAt(5));
+ var re = $RegExp('(?b)', 'g');
return re.exec('b').groups.a !== 'b' ||
'b'.replace(re, '$c') !== 'bc';
});