Skip to content

Commit

Permalink
Convert function expressions to arrow functions
Browse files Browse the repository at this point in the history
As mentioned in slevithan/xregexp#108 (comment)

This was done with the help of [lebab], using `lebeb --replace src --transform arrow`.

[lebab]: https://github.com/lebab/lebab

I did have to add an `/* eslint disable no-confusing-arrow */` comment
to suppress an error. Once eslint/eslint#8439 is
merged and released, we can upgrade eslint and remove the comment.
  • Loading branch information
speecyy committed Apr 30, 2017
1 parent 2354d51 commit 67723a0
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 95 deletions.
18 changes: 8 additions & 10 deletions src/addons/build.js
Expand Up @@ -4,7 +4,7 @@
* Steven Levithan (c) 2012-2017 MIT License
*/

module.exports = function(XRegExp) {
module.exports = (XRegExp) => {
const REGEX_DATA = 'xregexp';
const subParts = /(\()(?!\?)|\\([1-9]\d*)|\\[\s\S]|\[(?:[^\\\]]|\\[\s\S])*\]/g;
const parts = XRegExp.union([/\({{([\w$]+)}}\)|{{([\w$]+)}}/, subParts], 'g', {
Expand Down Expand Up @@ -96,12 +96,10 @@ module.exports = function(XRegExp) {
* time.test('10:59'); // -> true
* XRegExp.exec('10:59', time).minutes; // -> '59'
*/
XRegExp.tag = function(flags) {
return function(literals, ...substitutions) {
const subpatterns = substitutions.map(interpolate).reduce(reduceToSubpatternsObject, {});
const pattern = literals.raw.map(embedSubpatternAfter).join('');
return XRegExp.build(pattern, subpatterns, flags);
};
XRegExp.tag = (flags) => (literals, ...substitutions) => {
const subpatterns = substitutions.map(interpolate).reduce(reduceToSubpatternsObject, {});
const pattern = literals.raw.map(embedSubpatternAfter).join('');
return XRegExp.build(pattern, subpatterns, flags);
};

/**
Expand Down Expand Up @@ -129,7 +127,7 @@ module.exports = function(XRegExp) {
* time.test('10:59'); // -> true
* XRegExp.exec('10:59', time).minutes; // -> '59'
*/
XRegExp.build = function(pattern, subs, flags) {
XRegExp.build = (pattern, subs, flags) => {
flags = flags || '';
// Used with `asXRegExp` calls for `pattern` and subpatterns in `subs`, to work around how
// some browsers convert `RegExp('\n')` to a regex that contains the literal characters `\`
Expand Down Expand Up @@ -168,7 +166,7 @@ module.exports = function(XRegExp) {
let numOuterCaps = 0;
const outerCapsMap = [0];
const outerCapNames = patternAsRegex[REGEX_DATA].captureNames || [];
const output = patternAsRegex.source.replace(parts, function($0, $1, $2, $3, $4) {
const output = patternAsRegex.source.replace(parts, ($0, $1, $2, $3, $4) => {
const subName = $1 || $2;
let capName;
let intro;
Expand All @@ -189,7 +187,7 @@ module.exports = function(XRegExp) {
intro = '(?:';
}
numPriorCaps = numCaps;
return intro + data[subName].pattern.replace(subParts, function(match, paren, backref) {
return intro + data[subName].pattern.replace(subParts, (match, paren, backref) => {
// Capturing group
if (paren) {
capName = data[subName].names[numCaps - numPriorCaps];
Expand Down
4 changes: 2 additions & 2 deletions src/addons/matchrecursive.js
Expand Up @@ -4,7 +4,7 @@
* Steven Levithan (c) 2009-2017 MIT License
*/

module.exports = function(XRegExp) {
module.exports = (XRegExp) => {

/**
* Returns a match detail object composed of the provided values.
Expand Down Expand Up @@ -70,7 +70,7 @@ module.exports = function(XRegExp) {
* XRegExp.matchRecursive(str, '<', '>', 'gy');
* // -> ['1', '<<2>>', '3']
*/
XRegExp.matchRecursive = function(str, left, right, flags, options) {
XRegExp.matchRecursive = (str, left, right, flags, options) => {
flags = flags || '';
options = options || {};
const global = flags.indexOf('g') > -1;
Expand Down
10 changes: 5 additions & 5 deletions src/addons/unicode-base.js
Expand Up @@ -4,7 +4,7 @@
* Steven Levithan (c) 2008-2017 MIT License
*/

module.exports = function(XRegExp) {
module.exports = (XRegExp) => {

/**
* Adds base support for Unicode matching:
Expand Down Expand Up @@ -53,7 +53,7 @@ module.exports = function(XRegExp) {
XRegExp.forEach(
range,
/(\\x..|\\u....|\\?[\s\S])(?:-(\\x..|\\u....|\\?[\s\S]))?/,
function(m) {
(m) => {
const start = charCode(m[1]);
if (start > (lastEnd + 1)) {
output += '\\u' + pad4(hex(lastEnd + 1));
Expand Down Expand Up @@ -124,7 +124,7 @@ module.exports = function(XRegExp) {
XRegExp.addToken(
// Use `*` instead of `+` to avoid capturing `^` as the token name in `\p{^}`
/\\([pP])(?:{(\^?)([^}]*)}|([A-Za-z]))/,
function(match, scope, flags) {
(match, scope, flags) => {
const ERR_DOUBLE_NEG = 'Invalid double negation ';
const ERR_UNKNOWN_NAME = 'Unknown Unicode token ';
const ERR_UNKNOWN_REF = 'Unicode token missing data ';
Expand Down Expand Up @@ -206,7 +206,7 @@ module.exports = function(XRegExp) {
* }]);
* XRegExp('\\p{XDigit}:\\p{Hexadecimal}+').test('0:3D'); // -> true
*/
XRegExp.addUnicodeData = function(data) {
XRegExp.addUnicodeData = (data) => {
const ERR_NO_NAME = 'Unicode token requires name';
const ERR_NO_DATA = 'Unicode token has no character data ';
let item;
Expand Down Expand Up @@ -251,7 +251,7 @@ module.exports = function(XRegExp) {
* the future. It is meant for userland code that wishes to reuse the (large) internal Unicode
* structures set up by XRegExp.
*/
XRegExp._getUnicodeProperty = function(name) {
XRegExp._getUnicodeProperty = (name) => {
const slug = normalize(name);
return unicode[slug];
};
Expand Down
2 changes: 1 addition & 1 deletion src/addons/unicode-blocks.js
Expand Up @@ -5,7 +5,7 @@
* Unicode data by Mathias Bynens <mathiasbynens.be>
*/

module.exports = function(XRegExp) {
module.exports = (XRegExp) => {

/**
* Adds support for all Unicode blocks. Block names use the prefix 'In'. E.g.,
Expand Down
2 changes: 1 addition & 1 deletion src/addons/unicode-categories.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/addons/unicode-properties.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/addons/unicode-scripts.js
Expand Up @@ -5,7 +5,7 @@
* Unicode data by Mathias Bynens <mathiasbynens.be>
*/

module.exports = function(XRegExp) {
module.exports = (XRegExp) => {

/**
* Adds support for all Unicode scripts. E.g., `\p{Latin}`. Token names are case insensitive,
Expand Down

0 comments on commit 67723a0

Please sign in to comment.