From 92955488424e23c1546c6c96021a45c21ce84a98 Mon Sep 17 00:00:00 2001 From: Michael Bianco Date: Sat, 15 Jul 2023 05:52:34 -0600 Subject: [PATCH] feat: add pretty-print to debugger repl --- debugger/inspect_repl.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/debugger/inspect_repl.js b/debugger/inspect_repl.js index 9cb1e66..2a90048 100644 --- a/debugger/inspect_repl.js +++ b/debugger/inspect_repl.js @@ -578,17 +578,23 @@ function createRepl(inspector) { } } + // preprocess debugger repl input to allow parentheses-less `exec` and `p` function prepareControlCode(input) { if (input === '\n') return lastCommand; + // Add parentheses: exec process.title => exec("process.title"); // TODO all helper functions should auto-add parentheses - const match = RegExpPrototypeExec(/^\s*(?:exec|p)\s+([^\n]*)/, input); - if (match) { - lastCommand = `exec(${JSONStringify(match[1])})`; - } else { - lastCommand = input; + const execMatch = RegExpPrototypeExec(/^\s*(?:exec|p)\s+([^\n]*)/, input); + if (execMatch) { + return `exec(${JSONStringify(execMatch[1])})`; } - return lastCommand; + + const prettyPrintMatch = RegExpPrototypeExec(/^\s*(?:pretty-print|pp)\s+([^\n]*)/, input); + if(prettyPrintMatch) { + return `exec(${JSONStringify('console.dir(' + prettyPrintMatch[1] + ', {depth: null, colors: true, maxArrayLength: null, maxStringLength: null})')})`; + } + + return input; } async function evalInCurrentContext(code) {