-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
libs: fix some RegExp nits #13536
libs: fix some RegExp nits #13536
Changes from all commits
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 |
---|---|---|
|
@@ -754,6 +754,7 @@ function complete(line, callback) { | |
const exts = Object.keys(this.context.require.extensions); | ||
var indexRe = new RegExp('^index(' + exts.map(regexpEscape).join('|') + | ||
')$'); | ||
var versionedFileNamesRe = /-\d+\.\d+/; | ||
|
||
completeOn = match[1]; | ||
var subdir = match[2] || ''; | ||
|
@@ -772,7 +773,7 @@ function complete(line, callback) { | |
name = files[f]; | ||
ext = path.extname(name); | ||
base = name.slice(0, -ext.length); | ||
if (base.match(/-\d+\.\d+(\.\d+)?/) || name === '.npm') { | ||
if (versionedFileNamesRe.test(base) || name === '.npm') { | ||
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. same here, but I really don’t know what this code is supposed to do. :/ 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. Ditto about clarity/performance ) 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. I looked into this a bit further and this all about the npm cache itself. It is meant to prevent listing all the version folders found in the cache folder (e.g. 1.0.0 in |
||
// Exclude versioned names that 'npm' installs. | ||
continue; | ||
} | ||
|
@@ -816,7 +817,7 @@ function complete(line, callback) { | |
// spam.eggs.<|> # completions for 'spam.eggs' with filter '' | ||
// foo<|> # all scope vars with filter 'foo' | ||
// foo.<|> # completions for 'foo' with filter '' | ||
} else if (line.length === 0 || line[line.length - 1].match(/\w|\.|\$/)) { | ||
} else if (line.length === 0 || /\w|\.|\$/.test(line[line.length - 1])) { | ||
match = simpleExpressionRE.exec(line); | ||
if (line.length === 0 || match) { | ||
var expr; | ||
|
@@ -1067,7 +1068,7 @@ REPLServer.prototype.memory = function memory(cmd) { | |
self.lines.level.push({ | ||
line: self.lines.length - 1, | ||
depth: depth, | ||
isFunction: /\s*function\s*/.test(cmd) | ||
isFunction: /\bfunction\b/.test(cmd) | ||
}); | ||
} else if (depth < 0) { | ||
// going... up. | ||
|
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 wonder if this was meant to be anchored, i.e.
^…$
, otherwise the addition doesn’t make much sense? Anyway, your change seems correct.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.
Maybe this was for some more clarity, to show the wider pattern. But this may impact performance a bit.