summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorVse Mozhet Byt <vsemozhetbyt@gmail.com>2017-06-16 20:14:58 +0300
committerVse Mozhet Byt <vsemozhetbyt@gmail.com>2017-06-19 18:07:52 +0300
commit878990498a246488dfe5393ddc89b2b15f395a4d (patch)
tree09518527781b28991d44039a40d0a221992b0756 /lib
parentb9457717cab131a0f6e58b12f4b65a7aae4ecc30 (diff)
downloadandroid-node-v8-878990498a246488dfe5393ddc89b2b15f395a4d.tar.gz
android-node-v8-878990498a246488dfe5393ddc89b2b15f395a4d.tar.bz2
android-node-v8-878990498a246488dfe5393ddc89b2b15f395a4d.zip
readline,repl,url,util: remove needless capturing
Use non-capturing grouping or remove capturing completely when: * capturing is useless per se, e.g. in test() check; * captured groups are not used afterwards at all; * some of the later captured groups are not used afterwards. PR-URL: https://github.com/nodejs/node/pull/13718 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/url.js2
-rw-r--r--lib/readline.js8
-rw-r--r--lib/repl.js6
-rw-r--r--lib/url.js2
-rw-r--r--lib/util.js6
5 files changed, 12 insertions, 12 deletions
diff --git a/lib/internal/url.js b/lib/internal/url.js
index 14c22e4ff4..7d7c79149a 100644
--- a/lib/internal/url.js
+++ b/lib/internal/url.js
@@ -51,7 +51,7 @@ const IteratorPrototype = Object.getPrototypeOf(
);
const unpairedSurrogateRe =
- /([^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])/;
+ /(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])/;
function toUSVString(val) {
const str = `${val}`;
// As of V8 5.5, `str.search()` (and `unpairedSurrogateRe[@@search]()`) are
diff --git a/lib/readline.js b/lib/readline.js
index adf2d5f067..51d1da5770 100644
--- a/lib/readline.js
+++ b/lib/readline.js
@@ -551,7 +551,7 @@ function commonPrefix(strings) {
Interface.prototype._wordLeft = function() {
if (this.cursor > 0) {
var leading = this.line.slice(0, this.cursor);
- var match = leading.match(/([^\w\s]+|\w+|)\s*$/);
+ var match = leading.match(/(?:[^\w\s]+|\w+|)\s*$/);
this._moveCursor(-match[0].length);
}
};
@@ -560,7 +560,7 @@ Interface.prototype._wordLeft = function() {
Interface.prototype._wordRight = function() {
if (this.cursor < this.line.length) {
var trailing = this.line.slice(this.cursor);
- var match = trailing.match(/^(\s+|\W+|\w+)\s*/);
+ var match = trailing.match(/^(?:\s+|\W+|\w+)\s*/);
this._moveCursor(match[0].length);
}
};
@@ -587,7 +587,7 @@ Interface.prototype._deleteRight = function() {
Interface.prototype._deleteWordLeft = function() {
if (this.cursor > 0) {
var leading = this.line.slice(0, this.cursor);
- var match = leading.match(/([^\w\s]+|\w+|)\s*$/);
+ var match = leading.match(/(?:[^\w\s]+|\w+|)\s*$/);
leading = leading.slice(0, leading.length - match[0].length);
this.line = leading + this.line.slice(this.cursor, this.line.length);
this.cursor = leading.length;
@@ -599,7 +599,7 @@ Interface.prototype._deleteWordLeft = function() {
Interface.prototype._deleteWordRight = function() {
if (this.cursor < this.line.length) {
var trailing = this.line.slice(this.cursor);
- var match = trailing.match(/^(\s+|\W+|\w+)\s*/);
+ var match = trailing.match(/^(?:\s+|\W+|\w+)\s*/);
this.line = this.line.slice(0, this.cursor) +
trailing.slice(match[0].length);
this._refreshLine();
diff --git a/lib/repl.js b/lib/repl.js
index fe6c1a5af4..6446c74787 100644
--- a/lib/repl.js
+++ b/lib/repl.js
@@ -680,9 +680,9 @@ ArrayStream.prototype.writable = true;
ArrayStream.prototype.resume = function() {};
ArrayStream.prototype.write = function() {};
-const requireRE = /\brequire\s*\(['"](([\w@./-]+\/)?([\w@./-]*))/;
+const requireRE = /\brequire\s*\(['"](([\w@./-]+\/)?(?:[\w@./-]*))/;
const simpleExpressionRE =
- /(([a-zA-Z_$](?:\w|\$)*)\.)*([a-zA-Z_$](?:\w|\$)*)\.?$/;
+ /(?:[a-zA-Z_$](?:\w|\$)*\.)*[a-zA-Z_$](?:\w|\$)*\.?$/;
function intFilter(item) {
// filters out anything not starting with A-Z, a-z, $ or _
@@ -753,7 +753,7 @@ function complete(line, callback) {
} else if (match = line.match(requireRE)) {
// require('...<Tab>')
const exts = Object.keys(this.context.require.extensions);
- var indexRe = new RegExp('^index(' + exts.map(regexpEscape).join('|') +
+ var indexRe = new RegExp('^index(?:' + exts.map(regexpEscape).join('|') +
')$');
var versionedFileNamesRe = /-\d+\.\d+/;
diff --git a/lib/url.js b/lib/url.js
index 8a76d1fc10..f3ebbec7b1 100644
--- a/lib/url.js
+++ b/lib/url.js
@@ -56,7 +56,7 @@ function Url() {
// define these here so at least they only have to be
// compiled once on the first module load.
-const protocolPattern = /^([a-z0-9.+-]+:)/i;
+const protocolPattern = /^[a-z0-9.+-]+:/i;
const portPattern = /:[0-9]*$/;
const hostPattern = /^\/\/[^@/]+@[^@/]+/;
diff --git a/lib/util.js b/lib/util.js
index 4f6d727eaa..c9140069e2 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -798,7 +798,7 @@ function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
if (array) {
str = str.replace(/\n/g, '\n ');
} else {
- str = str.replace(/(^|\n)/g, '\n ');
+ str = str.replace(/^|\n/g, '\n ');
}
}
} else {
@@ -810,13 +810,13 @@ function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
return str;
}
name = JSON.stringify('' + key);
- if (/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/.test(name)) {
+ if (/^"[a-zA-Z_][a-zA-Z_0-9]*"$/.test(name)) {
name = name.substr(1, name.length - 2);
name = ctx.stylize(name, 'name');
} else {
name = name.replace(/'/g, "\\'")
.replace(/\\"/g, '"')
- .replace(/(^"|"$)/g, "'")
+ .replace(/^"|"$/g, "'")
.replace(/\\\\/g, '\\');
name = ctx.stylize(name, 'string');
}