| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5080734 commit 1ecd407
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -136,6 +136,8 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | |||
| 136 | 136 | let previewCompletionCounter = 0; | |
| 137 | 137 | let completionPreview = null; | |
| 138 | 138 | ||
| 139 | + let wrapped = false; | ||
| 140 | + | ||
| 139 | 141 | function getPreviewPos() { | |
| 140 | 142 | const displayPos = repl._getDisplayPos(`${repl._prompt}${repl.line}`); | |
| 141 | 143 | const cursorPos = repl.line.length !== repl.cursor ? | |
@@ -244,8 +246,9 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | |||
| 244 | 246 | function getInputPreview(input, callback) { | |
| 245 | 247 | // For similar reasons as `defaultEval`, wrap expressions starting with a | |
| 246 | 248 | // curly brace with parenthesis. | |
| 247 | - if (input.startsWith('{') && !input.endsWith(';')) { | ||
| 249 | + if (input.startsWith('{') && !input.endsWith(';') && !wrapped) { | ||
| 248 | 250 | input = `(${input})`; | |
| 251 | + wrapped = true; | ||
| 249 | 252 | } | |
| 250 | 253 | sendInspectorCommand((session) => { | |
| 251 | 254 | session.post('Runtime.evaluate', { | |
@@ -329,13 +332,19 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | |||
| 329 | 332 | return; | |
| 330 | 333 | } | |
| 331 | 334 | ||
| 332 | - getInputPreview(line, (error, inspected) => { | ||
| 335 | + const inputPreviewCallback = (error, inspected) => { | ||
| 336 | + if (inspected === null) { | ||
| 337 | + return; | ||
| 338 | + } | ||
| 339 | + | ||
| 340 | + wrapped = false; | ||
| 341 | + | ||
| 333 | 342 | // Ignore the output if the value is identical to the current line and the | |
| 334 | 343 | // former preview is not identical to this preview. | |
| 335 | - if ((line === inspected && lastInputPreview !== inspected) || | ||
| 336 | - inspected === null) { | ||
| 344 | + if (line === inspected && lastInputPreview !== inspected) { | ||
| 337 | 345 | return; | |
| 338 | 346 | } | |
| 347 | + | ||
| 339 | 348 | if (error) { | |
| 340 | 349 | debug('Error while generating preview', error); | |
| 341 | 350 | return; | |
@@ -386,7 +395,13 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | |||
| 386 | 395 | repl.output.write(`\n${result}`); | |
| 387 | 396 | cursorTo(repl.output, cursorPos.cols); | |
| 388 | 397 | moveCursor(repl.output, 0, -rows - 1); | |
| 389 | - }); | ||
| 398 | + }; | ||
| 399 | + | ||
| 400 | + getInputPreview(line, inputPreviewCallback); | ||
| 401 | + if (wrapped) { | ||
| 402 | + getInputPreview(line, inputPreviewCallback); | ||
| 403 | + } | ||
| 404 | + wrapped = false; | ||
| 390 | 405 | }; | |
| 391 | 406 | ||
| 392 | 407 | // -------------------------------------------------------------------------// | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -125,7 +125,13 @@ async function tests(options) { | |||
| 125 | 125 | '\x1B[90m{ a: true }\x1B[39m\x1B[20G\x1B[1A\x1B[1B\x1B[2K\x1B[1A;', | |
| 126 | 126 | '\x1B[90mtrue\x1B[39m\x1B[21G\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r', | |
| 127 | 127 | '\x1B[33mtrue\x1B[39m', | |
| 128 | - '\x1B[1G\x1B[0Jrepl > \x1B[8G'] | ||
| 128 | + '\x1B[1G\x1B[0Jrepl > \x1B[8G'], | ||
| 129 | + ['{};1', [2, 4], '\x1B[33m1\x1B[39m', | ||
| 130 | + '{};1', | ||
| 131 | + '\x1B[90m1\x1B[39m\x1B[12G\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r', | ||
| 132 | + '\x1B[33m1\x1B[39m', | ||
| 133 | + '\x1B[1G\x1B[0Jrepl > \x1B[8G' | ||
| 134 | + ] | ||
| 129 | 135 | ]; | |
| 130 | 136 | ||
| 131 | 137 | const hasPreview = repl.terminal && | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -457,6 +457,28 @@ const errorTests = [ | |||
| 457 | 457 | /'thefourtheye'/ | |
| 458 | 458 | ] | |
| 459 | 459 | }, | |
| 460 | + // Check for wrapped objects. | ||
| 461 | + { | ||
| 462 | + send: '{ a: 1 }.a', // ({ a: 1 }.a); | ||
| 463 | + expect: '1' | ||
| 464 | + }, | ||
| 465 | + { | ||
| 466 | + send: '{ a: 1 }.a;', // { a: 1 }.a; | ||
| 467 | + expect: [ | ||
| 468 | + kSource, | ||
| 469 | + kArrow, | ||
| 470 | + '', | ||
| 471 | + /^Uncaught SyntaxError: / | ||
| 472 | + ] | ||
| 473 | + }, | ||
| 474 | + { | ||
| 475 | + send: '{ a: 1 }["a"] === 1', // ({ a: 1 }['a'] === 1); | ||
| 476 | + expect: 'true' | ||
| 477 | + }, | ||
| 478 | + { | ||
| 479 | + send: '{ a: 1 }["a"] === 1;', // { a: 1 }; ['a'] === 1; | ||
| 480 | + expect: 'false' | ||
| 481 | + }, | ||
| 460 | 482 | // Empty lines in the REPL should be allowed | |
| 461 | 483 | { | |
| 462 | 484 | send: '\n\r\n\r\n', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments