-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
fixes #471 #745
fixes #471 #745
Changes from 3 commits
7948175
3bfe93c
e0a3d42
c7429d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,14 @@ var REPLACE_KEEPS_$0 = (function () { | |
return 'a'.replace(/./, '$0') === '$0'; | ||
})(); | ||
|
||
// Safari <= 13.0.3(?) substitutes nth capture where n>m with an empty string | ||
var REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE = (function () { | ||
if (RegExp.prototype[wellKnownSymbol('replace')]) { | ||
return RegExp.prototype[wellKnownSymbol('replace')].call(/./, 'a', '$0') === ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
return false; | ||
})(); | ||
|
||
// Chrome 51 has a buggy "split" implementation when RegExp#exec !== nativeExec | ||
// Weex JS has frozen built-in prototypes, so use try / catch wrapper | ||
var SPLIT_WORKS_WITH_OVERWRITTEN_EXEC = !fails(function () { | ||
|
@@ -75,7 +83,9 @@ module.exports = function (KEY, length, exec, sham) { | |
if ( | ||
!DELEGATES_TO_SYMBOL || | ||
!DELEGATES_TO_EXEC || | ||
(KEY === 'replace' && !(REPLACE_SUPPORTS_NAMED_GROUPS && REPLACE_KEEPS_$0)) || | ||
(KEY === 'replace' && !(REPLACE_SUPPORTS_NAMED_GROUPS && ( | ||
REPLACE_KEEPS_$0 || REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A strange logic. Why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My thinking was that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not something related to specific engines, it's related to specific bugs and implementations of old spec versions. At this moment we have 3 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mattclough1 Note that the |
||
))) || | ||
(KEY === 'split' && !SPLIT_WORKS_WITH_OVERWRITTEN_EXEC) | ||
) { | ||
var nativeRegExpMethod = /./[SYMBOL]; | ||
|
@@ -90,7 +100,10 @@ module.exports = function (KEY, length, exec, sham) { | |
return { done: true, value: nativeMethod.call(str, regexp, arg2) }; | ||
} | ||
return { done: false }; | ||
}, { REPLACE_KEEPS_$0: REPLACE_KEEPS_$0 }); | ||
}, { | ||
REPLACE_KEEPS_$0: REPLACE_KEEPS_$0, | ||
REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE: REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE | ||
}); | ||
var stringMethod = methods[0]; | ||
var regexMethod = methods[1]; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to cache
wellKnownSymbol('replace')
as a constant, for example,REPLACE
.