Skip to content

Commit

Permalink
add a workaround of a Closure Compiler unsafe optimization, close #972
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Aug 17, 2021
1 parent 1e01d63 commit 1f79e84
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 5 additions & 6 deletions packages/core-js/internals/regexp-sticky-helpers.js
Original file line number Diff line number Diff line change
@@ -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;
});
7 changes: 5 additions & 2 deletions packages/core-js/internals/regexp-unsupported-dot-all.js
Original file line number Diff line number Diff line change
@@ -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');
});
7 changes: 5 additions & 2 deletions packages/core-js/internals/regexp-unsupported-ncg.js
Original file line number Diff line number Diff line change
@@ -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('(?<a>b)', (typeof '').charAt(5));
var re = $RegExp('(?<a>b)', 'g');
return re.exec('b').groups.a !== 'b' ||
'b'.replace(re, '$<a>c') !== 'bc';
});

0 comments on commit 1f79e84

Please sign in to comment.