From 8a9ff172f0b5ae20bf17882bc6e675d4d8bb5251 Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Tue, 22 Jan 2019 18:34:33 +0700 Subject: [PATCH] add a workaround for `babel-minify` bug, fix #479 --- modules/es6.regexp.split.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/es6.regexp.split.js b/modules/es6.regexp.split.js index 8952ee04e4b8..45f81ce4d2b1 100644 --- a/modules/es6.regexp.split.js +++ b/modules/es6.regexp.split.js @@ -7,14 +7,16 @@ var advanceStringIndex = require('./_advance-string-index'); var toLength = require('./_to-length'); var callRegExpExec = require('./_regexp-exec-abstract'); var regexpExec = require('./_regexp-exec'); +var fails = require('./_fails'); var $min = Math.min; var $push = [].push; var $SPLIT = 'split'; var LENGTH = 'length'; var LAST_INDEX = 'lastIndex'; +var MAX_UINT32 = 0xffffffff; -// eslint-disable-next-line no-empty -var SUPPORTS_Y = !!(function () { try { return new RegExp('x', 'y'); } catch (e) {} })(); +// babel-minify transpiles RegExp('x', 'y') -> /x/y and it causes SyntaxError +var SUPPORTS_Y = !fails(function () { RegExp(MAX_UINT32, 'y'); }); // @@split logic require('./_fix-re-wks')('split', 2, function (defined, SPLIT, $split, maybeCallNative) { @@ -39,7 +41,7 @@ require('./_fix-re-wks')('split', 2, function (defined, SPLIT, $split, maybeCall (separator.unicode ? 'u' : '') + (separator.sticky ? 'y' : ''); var lastLastIndex = 0; - var splitLimit = limit === undefined ? 4294967295 : limit >>> 0; + var splitLimit = limit === undefined ? MAX_UINT32 : limit >>> 0; // Make `global` and avoid `lastIndex` issues by working with a copy var separatorCopy = new RegExp(separator.source, flags + 'g'); var match, lastIndex, lastLength; @@ -93,14 +95,14 @@ require('./_fix-re-wks')('split', 2, function (defined, SPLIT, $split, maybeCall var unicodeMatching = rx.unicode; var flags = (rx.ignoreCase ? 'i' : '') + - (rx.multiline ? 'm' : '') + - (rx.unicode ? 'u' : '') + - (SUPPORTS_Y ? 'y' : 'g'); + (rx.multiline ? 'm' : '') + + (rx.unicode ? 'u' : '') + + (SUPPORTS_Y ? 'y' : 'g'); // ^(? + rx + ) is needed, in combination with some S slicing, to // simulate the 'y' flag. var splitter = new C(SUPPORTS_Y ? rx : '^(?:' + rx.source + ')', flags); - var lim = limit === undefined ? 0xffffffff : limit >>> 0; + var lim = limit === undefined ? MAX_UINT32 : limit >>> 0; if (lim === 0) return []; if (S.length === 0) return callRegExpExec(splitter, S) === null ? [S] : []; var p = 0;