(line, callback)
| 198 | // logic is skipped when getters or proxies are involved in the expression. |
| 199 | // (see: https://github.com/nodejs/node/issues/57829). |
| 200 | function complete(line, callback) { |
| 201 | // List of completion lists, one for each inheritance "level" |
| 202 | let completionGroups = []; |
| 203 | let completeOn, group; |
| 204 | |
| 205 | // Ignore right whitespace. It could change the outcome. |
| 206 | line = StringPrototypeTrimStart(line); |
| 207 | |
| 208 | let filter = ''; |
| 209 | |
| 210 | let match; |
| 211 | // REPL commands (e.g. ".break"). |
| 212 | if ((match = RegExpPrototypeExec(/^\s*\.(\w*)$/, line)) !== null) { |
| 213 | ArrayPrototypePush(completionGroups, ObjectKeys(this.commands)); |
| 214 | completeOn = match[1]; |
| 215 | if (completeOn.length) { |
| 216 | filter = completeOn; |
| 217 | } |
| 218 | } else if ((match = RegExpPrototypeExec(requireRE, line)) !== null) { |
| 219 | // require('...<Tab>') |
| 220 | completeOn = match[1]; |
| 221 | filter = completeOn; |
| 222 | if (this.allowBlockingCompletions) { |
| 223 | const subdir = match[2] || ''; |
| 224 | const extensions = ObjectKeys(CJSModule._extensions); |
| 225 | const indexes = ArrayPrototypeMap(extensions, |
| 226 | (extension) => `index${extension}`); |
| 227 | ArrayPrototypePush(indexes, 'package.json', 'index'); |
| 228 | |
| 229 | group = []; |
| 230 | let paths = []; |
| 231 | |
| 232 | if (completeOn === '.') { |
| 233 | group = ['./', '../']; |
| 234 | } else if (completeOn === '..') { |
| 235 | group = ['../']; |
| 236 | } else if (RegExpPrototypeExec(/^\.\.?\//, completeOn) !== null) { |
| 237 | paths = [process.cwd()]; |
| 238 | } else { |
| 239 | paths = []; |
| 240 | ArrayPrototypePushApply(paths, module.paths); |
| 241 | ArrayPrototypePushApply(paths, CJSModule.globalPaths); |
| 242 | } |
| 243 | |
| 244 | ArrayPrototypeForEach(paths, (dir) => { |
| 245 | dir = path.resolve(dir, subdir); |
| 246 | const dirents = gracefulReaddir(dir, { withFileTypes: true }) || []; |
| 247 | ArrayPrototypeForEach(dirents, (dirent) => { |
| 248 | if (RegExpPrototypeExec(versionedFileNamesRe, dirent.name) !== null || |
| 249 | dirent.name === '.npm') { |
| 250 | // Exclude versioned names that 'npm' installs. |
| 251 | return; |
| 252 | } |
| 253 | const extension = path.extname(dirent.name); |
| 254 | const base = StringPrototypeSlice(dirent.name, 0, -extension.length); |
| 255 | if (!dirent.isDirectory()) { |
| 256 | if (StringPrototypeIncludes(extensions, extension) && |
| 257 | (!subdir || base !== 'index')) { |
no test coverage detected
searching dependent graphs…