Skip to content
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

debugger: fix behavior of { a: 1 } in the debugger repl #46924

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/internal/debugger/inspect_repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,16 @@ function createRepl(inspector) {
if (input === '\n') return lastCommand;
// Add parentheses: exec process.title => exec("process.title");
const match = RegExpPrototypeExec(/^\s*(?:exec|p)\s+([^\n]*)/, input);
input = match ? match[1] : input;

// Add parentheses to make sure input is parsed as expression
if (RegExpPrototypeExec(/^\s*{/, input) !== null &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also should append lib/internal/debugger/inspect_repl.js to this comment:

node/lib/repl.js

Lines 417 to 421 in 31156a7

// It's confusing for `{ a : 1 }` to be interpreted as a block
// statement rather than an object literal. So, we first try
// to wrap it in parentheses, so that it will be interpreted as
// an expression. Note that if the above condition changes,
// lib/internal/repl/utils.js needs to be changed to match.

RegExpPrototypeExec(/;\s*$/, input) === null) {
input = `(${StringPrototypeTrim(input)})\n`;
}

if (match) {
lastCommand = `exec(${JSONStringify(match[1])})`;
lastCommand = `exec(${JSONStringify(input)})`;
} else {
lastCommand = input;
}
Expand Down
Loading