-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #516 from zloirock/string-match-all-stage-4
Move `String#matchAll` to stable ES, expose `Symbol.matchAll`
- Loading branch information
Showing
36 changed files
with
200 additions
and
138 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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
'use strict'; | ||
module.exports = { | ||
// '3.1': ['esnext.builtin.feature'], | ||
3.1: [ | ||
'es.string.match-all', | ||
'es.symbol.match-all', | ||
], | ||
}; |
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,8 @@ | ||
var matchAll = require('../string/virtual/match-all'); | ||
var StringPrototype = String.prototype; | ||
|
||
module.exports = function (it) { | ||
var own = it.matchAll; | ||
return typeof it === 'string' || it === StringPrototype | ||
|| (it instanceof String && own === StringPrototype.matchAll) ? matchAll : own; | ||
}; |
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,3 @@ | ||
require('../../modules/es.string.match-all'); | ||
|
||
module.exports = require('../../internals/entry-unbind')('String', 'matchAll'); |
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,3 @@ | ||
require('../../../modules/es.string.match-all'); | ||
|
||
module.exports = require('../../../internals/entry-virtual')('String').matchAll; |
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,4 @@ | ||
require('../../modules/es.symbol.match-all'); | ||
require('../../modules/es.string.match-all'); | ||
|
||
module.exports = require('../../internals/wrapped-well-known-symbol').f('matchAll'); |
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 |
---|---|---|
@@ -1,8 +1 @@ | ||
var matchAll = require('../string/virtual/match-all'); | ||
var StringPrototype = String.prototype; | ||
|
||
module.exports = function (it) { | ||
var own = it.matchAll; | ||
return typeof it === 'string' || it === StringPrototype | ||
|| (it instanceof String && own === StringPrototype.matchAll) ? matchAll : own; | ||
}; | ||
module.exports = require('../../es/instance/match-all'); |
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
module.exports = require('../../es/string'); | ||
|
||
require('../../modules/esnext.string.at'); | ||
require('../../modules/esnext.string.match-all'); | ||
require('../../modules/esnext.string.replace-all'); |
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 |
---|---|---|
@@ -1,3 +1 @@ | ||
require('../../modules/esnext.string.match-all'); | ||
|
||
module.exports = require('../../internals/entry-unbind')('String', 'matchAll'); | ||
module.exports = require('../../es/string/match-all'); |
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
module.exports = require('../../../es/string/virtual'); | ||
|
||
require('../../../modules/esnext.string.at'); | ||
require('../../../modules/esnext.string.match-all'); | ||
require('../../../modules/esnext.string.replace-all'); |
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 |
---|---|---|
@@ -1,3 +1 @@ | ||
require('../../../modules/esnext.string.match-all'); | ||
|
||
module.exports = require('../../../internals/entry-virtual')('String').matchAll; | ||
module.exports = require('../../../es/string/virtual/match-all'); |
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 @@ | ||
module.exports = require('../../es/symbol/match-all'); |
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,91 @@ | ||
'use strict'; | ||
var createIteratorConstructor = require('../internals/create-iterator-constructor'); | ||
var requireObjectCoercible = require('../internals/require-object-coercible'); | ||
var toLength = require('../internals/to-length'); | ||
var aFunction = require('../internals/a-function'); | ||
var anObject = require('../internals/an-object'); | ||
var classof = require('../internals/classof'); | ||
var getFlags = require('../internals/regexp-flags'); | ||
var hide = require('../internals/hide'); | ||
var speciesConstructor = require('../internals/species-constructor'); | ||
var advanceStringIndex = require('../internals/advance-string-index'); | ||
var MATCH_ALL = require('../internals/well-known-symbol')('matchAll'); | ||
var IS_PURE = require('../internals/is-pure'); | ||
var REGEXP_STRING = 'RegExp String'; | ||
var REGEXP_STRING_ITERATOR = REGEXP_STRING + ' Iterator'; | ||
var InternalStateModule = require('../internals/internal-state'); | ||
var setInternalState = InternalStateModule.set; | ||
var getInternalState = InternalStateModule.getterFor(REGEXP_STRING_ITERATOR); | ||
var RegExpPrototype = RegExp.prototype; | ||
var regExpBuiltinExec = RegExpPrototype.exec; | ||
|
||
var regExpExec = function (R, S) { | ||
var exec = R.exec; | ||
var result; | ||
if (typeof exec == 'function') { | ||
result = exec.call(R, S); | ||
if (typeof result != 'object') throw TypeError('Incorrect exec result'); | ||
return result; | ||
} return regExpBuiltinExec.call(R, S); | ||
}; | ||
|
||
// eslint-disable-next-line max-len | ||
var $RegExpStringIterator = createIteratorConstructor(function RegExpStringIterator(regexp, string, global, fullUnicode) { | ||
setInternalState(this, { | ||
type: REGEXP_STRING_ITERATOR, | ||
regexp: regexp, | ||
string: string, | ||
global: global, | ||
unicode: fullUnicode, | ||
done: false | ||
}); | ||
}, REGEXP_STRING, function next() { | ||
var state = getInternalState(this); | ||
if (state.done) return { value: undefined, done: true }; | ||
var R = state.regexp; | ||
var S = state.string; | ||
var match = regExpExec(R, S); | ||
if (match === null) return { value: undefined, done: state.done = true }; | ||
if (state.global) { | ||
if (String(match[0]) == '') R.lastIndex = advanceStringIndex(S, toLength(R.lastIndex), state.unicode); | ||
return { value: match, done: false }; | ||
} | ||
state.done = true; | ||
return { value: match, done: false }; | ||
}); | ||
|
||
var $matchAll = function (string) { | ||
var R = anObject(this); | ||
var S = String(string); | ||
var C, flagsValue, flags, matcher, global, fullUnicode; | ||
C = speciesConstructor(R, RegExp); | ||
flagsValue = R.flags; | ||
if (flagsValue === undefined && R instanceof RegExp && !('flags' in RegExpPrototype)) { | ||
flagsValue = getFlags.call(R); | ||
} | ||
flags = flagsValue === undefined ? '' : String(flagsValue); | ||
matcher = new C(C === RegExp ? R.source : R, flags); | ||
global = !!~flags.indexOf('g'); | ||
fullUnicode = !!~flags.indexOf('u'); | ||
matcher.lastIndex = toLength(R.lastIndex); | ||
return new $RegExpStringIterator(matcher, S, global, fullUnicode); | ||
}; | ||
|
||
// `String.prototype.matchAll` method | ||
// https://github.com/tc39/proposal-string-matchall | ||
require('../internals/export')({ target: 'String', proto: true }, { | ||
matchAll: function matchAll(regexp) { | ||
var O = requireObjectCoercible(this); | ||
var S, matcher, rx; | ||
if (regexp != null) { | ||
matcher = regexp[MATCH_ALL]; | ||
if (matcher === undefined && IS_PURE && classof(regexp) == 'RegExp') matcher = $matchAll; | ||
if (matcher != null) return aFunction(matcher).call(regexp, O); | ||
} | ||
S = String(O); | ||
rx = new RegExp(regexp, 'g'); | ||
return IS_PURE ? $matchAll.call(rx, S) : rx[MATCH_ALL](S); | ||
} | ||
}); | ||
|
||
IS_PURE || MATCH_ALL in RegExpPrototype || hide(RegExpPrototype, MATCH_ALL, $matchAll); |
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,2 @@ | ||
// `Symbol.matchAll` well-known symbol | ||
require('../internals/define-well-known-symbol')('matchAll'); |
Oops, something went wrong.