forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zloirock#492 Co-authored-by: Nicolò Ribaudo <[email protected]>
- Loading branch information
1 parent
2dd122f
commit 2934d8e
Showing
15 changed files
with
233 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require('../../modules/es.regexp.sticky'); | ||
|
||
module.exports = function (it) { | ||
return it.sticky; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
var fails = require('./fails'); | ||
var speciesConstructor = require('../internals/species-constructor'); | ||
|
||
// babel-minify transpiles RegExp('a', 'y') -> /a/y and it causes SyntaxError, | ||
// so we use an intermediate function. | ||
function RE(s, f) { | ||
return RegExp(s, f); | ||
} | ||
|
||
exports.UNSUPPORTED_Y = fails(function () { | ||
// babel-minify transpiles RegExp('a', 'y') -> /a/y and it causes SyntaxError | ||
var re = RE('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'); | ||
re.lastIndex = 2; | ||
return re.exec('str') != null; | ||
}); | ||
|
||
exports.createStickyRegExp = function (re, otherFlags) { | ||
var C = speciesConstructor(re, RegExp); | ||
|
||
if (C !== RegExp) return new C(re, otherFlags + 'y'); | ||
|
||
// y is either supported or polyfilled | ||
if (!exports.UNSUPPORTED_Y || RegExp.sham) { | ||
return new RegExp(re, otherFlags + 'y'); | ||
} | ||
|
||
// If y hasn't been polyfilled and it isn't supported, assigning | ||
// to .sticky won't throw. | ||
// This usually happens in engines where descriptors aren't supported. | ||
var fakeRe = new RegExp(re, otherFlags); | ||
fakeRe.sticky = true; | ||
return fakeRe; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
var DESCRIPTORS = require('../internals/descriptors'); | ||
var UNSUPPORTED_Y = require('../internals/regexp-sticky-helpers').UNSUPPORTED_Y; | ||
var defineProperty = require('../internals/object-define-property').f; | ||
var getInternalState = require('../internals/internal-state').get; | ||
var RegExpPrototype = RegExp.prototype; | ||
|
||
// `RegExp.prototype.sticky` getter | ||
if (DESCRIPTORS && UNSUPPORTED_Y) { | ||
defineProperty(RegExp.prototype, 'sticky', { | ||
configurable: true, | ||
get: function () { | ||
if (this === RegExpPrototype) return undefined; | ||
// We can't use InternalStateModule.getterFor because | ||
// we don't add metadata for regexps created by a literal. | ||
if (this instanceof RegExp) { | ||
return !!getInternalState(this).sticky; | ||
} | ||
throw TypeError('Incompatible receiver, RegExp required'); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.