You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wrong error report message for expression {}) #46877
// 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.
if(RegExpPrototypeExec(/^\s*{/,code)!==null&&
RegExpPrototypeExec(/;\s*$/,code)===null){
code=`(${StringPrototypeTrim(code)})\n`;
wrappedCmd=true;
}
I think it makes sense for Node.js to show the string it tried to parse rather than the input string – and I think adding those parentheses is useful as well. So if you ask me, I'd say this is not a bug, this is a feature.
Activity
aduh95 commentedon Feb 28, 2023
Any input that starts with a
{and doesn't end with a;will be wrapped in parentheses:node/lib/repl.js
Lines 417 to 426 in e4e8421
I think it makes sense for Node.js to show the string it tried to parse rather than the input string – and I think adding those parentheses is useful as well. So if you ask me, I'd say this is not a bug, this is a feature.
cola119 commentedon Mar 1, 2023
Potentially related issue: #46196
jenthone commentedon Mar 1, 2023
Try to wrap input in parentheses cause another issue:
BridgeAR commentedon Sep 11, 2025
This got fixed by #59607