| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a90b96f commit 1330cfc
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1066,7 +1066,7 @@ REPLServer.prototype.turnOffEditorMode = deprecate( | |||
| 1066 | 1066 | const requireRE = /\brequire\s*\(\s*['"`](([\w@./-]+\/)?(?:[\w@./-]*))(?![^'"`])$/; | |
| 1067 | 1067 | const fsAutoCompleteRE = /fs(?:\.promises)?\.\s*[a-z][a-zA-Z]+\(\s*["'](.*)/; | |
| 1068 | 1068 | const simpleExpressionRE = | |
| 1069 | - /(?:[a-zA-Z_$](?:\w|\$)*\.)*[a-zA-Z_$](?:\w|\$)*\.?$/; | ||
| 1069 | + /(?:[a-zA-Z_$](?:\w|\$)*\??\.)*[a-zA-Z_$](?:\w|\$)*\??\.?$/; | ||
| 1070 | 1070 | ||
| 1071 | 1071 | function isIdentifier(str) { | |
| 1072 | 1072 | if (str === '') { | |
@@ -1138,7 +1138,7 @@ function complete(line, callback) { | |||
| 1138 | 1138 | line = line.trimLeft(); | |
| 1139 | 1139 | ||
| 1140 | 1140 | // REPL commands (e.g. ".break"). | |
| 1141 | - let filter; | ||
| 1141 | + let filter = ''; | ||
| 1142 | 1142 | if (/^\s*\.(\w*)$/.test(line)) { | |
| 1143 | 1143 | completionGroups.push(ObjectKeys(this.commands)); | |
| 1144 | 1144 | completeOn = line.match(/^\s*\.(\w*)$/)[1]; | |
@@ -1253,10 +1253,8 @@ function complete(line, callback) { | |||
| 1253 | 1253 | let expr; | |
| 1254 | 1254 | completeOn = (match ? match[0] : ''); | |
| 1255 | 1255 | if (line.length === 0) { | |
| 1256 | - filter = ''; | ||
| 1257 | 1256 | expr = ''; | |
| 1258 | 1257 | } else if (line[line.length - 1] === '.') { | |
| 1259 | - filter = ''; | ||
| 1260 | 1258 | expr = match[0].slice(0, match[0].length - 1); | |
| 1261 | 1259 | } else { | |
| 1262 | 1260 | const bits = match[0].split('.'); | |
@@ -1285,6 +1283,12 @@ function complete(line, callback) { | |||
| 1285 | 1283 | return; | |
| 1286 | 1284 | } | |
| 1287 | 1285 | ||
| 1286 | + let chaining = '.'; | ||
| 1287 | + if (expr[expr.length - 1] === '?') { | ||
| 1288 | + expr = expr.slice(0, -1); | ||
| 1289 | + chaining = '?.'; | ||
| 1290 | + } | ||
| 1291 | + | ||
| 1288 | 1292 | const evalExpr = `try { ${expr} } catch {}`; | |
| 1289 | 1293 | this.eval(evalExpr, this.context, 'repl', (e, obj) => { | |
| 1290 | 1294 | if (obj != null) { | |
@@ -1316,12 +1320,12 @@ function complete(line, callback) { | |||
| 1316 | 1320 | } | |
| 1317 | 1321 | ||
| 1318 | 1322 | if (memberGroups.length) { | |
| 1319 | - for (let i = 0; i < memberGroups.length; i++) { | ||
| 1320 | - completionGroups.push( | ||
| 1321 | - memberGroups[i].map((member) => `${expr}.${member}`)); | ||
| 1323 | + expr += chaining; | ||
| 1324 | + for (const group of memberGroups) { | ||
| 1325 | + completionGroups.push(group.map((member) => `${expr}${member}`)); | ||
| 1322 | 1326 | } | |
| 1323 | 1327 | if (filter) { | |
| 1324 | - filter = `${expr}.${filter}`; | ||
| 1328 | + filter = `${expr}${filter}`; | ||
| 1325 | 1329 | } | |
| 1326 | 1330 | } | |
| 1327 | 1331 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,6 +68,19 @@ testMe.complete('console.lo', common.mustCall(function(error, data) { | |||
| 68 | 68 | assert.deepStrictEqual(data, [['console.log'], 'console.lo']); | |
| 69 | 69 | })); | |
| 70 | 70 | ||
| 71 | + testMe.complete('console?.lo', common.mustCall((error, data) => { | ||
| 72 | + assert.deepStrictEqual(data, [['console?.log'], 'console?.lo']); | ||
| 73 | + })); | ||
| 74 | + | ||
| 75 | + testMe.complete('console?.zzz', common.mustCall((error, data) => { | ||
| 76 | + assert.deepStrictEqual(data, [[], 'console?.zzz']); | ||
| 77 | + })); | ||
| 78 | + | ||
| 79 | + testMe.complete('console?.', common.mustCall((error, data) => { | ||
| 80 | + assert(data[0].includes('console?.log')); | ||
| 81 | + assert.strictEqual(data[1], 'console?.'); | ||
| 82 | + })); | ||
| 83 | + | ||
| 71 | 84 | // Tab Complete will return globally scoped variables | |
| 72 | 85 | putIn.run(['};']); | |
| 73 | 86 | testMe.complete('inner.o', common.mustCall(function(error, data) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments