repl: add hint as to how to exit#20617
Conversation
|
I think it would be better to at least check that |
|
Also, can you remove the merge commit? |
|
@mscdex Ok, I will remove the commit. And this is my first commit, so sorry. |
|
This is the effect changed now. $ ./out/Release/node
> exit
(To exit, press ^D or type .exit)
> quit
(To exit, press ^D or type .exit)
> exit = 1
1
> exit
1
> quit = 2
2
> quit
2 |
|
When |
|
@nodejs/repl |
|
Also pinging @princejwesley (who should totally let us know if they want to be added to @nodejs/repl). |
|
Is this semver-major? Can there be cases when changed output is breaking? |
|
Its good to be generic for all defined commands. Its like const context = this.useGlobal ? global : this.context;
if (context[cmd] === undefined && this.commands[cmd] && this[kBufferedCommandSymbol] === '') {
// emit this.commands[cmd].hint
} |
lib/repl.js
Outdated
There was a problem hiding this comment.
Just a tiny style thing, but could you maybe turn trimCmd = code.trim() into its own line? Also, don’t be shy to use a verbose name like trimCommand/isExitCommand.
There was a problem hiding this comment.
Thank you soooo much about your advice! I will modify the code as soon.
lib/repl.js
Outdated
There was a problem hiding this comment.
I think you don’t really need to add the else { … } here since you return early in the if() {} block anyway.
|
@princejwesley The |
|
Hi, this is my first time offering pr to nodejs, so what should I do after commit the changes? Thank you so much~ |
|
@monkingxue ... the process is: a number of us will review the commits and offer feedback as necessary. Once we're relatively sure it's ready, someone with commit access to kick off a CI test run in jenkins at ci.nodejs.org, and if it looks good we'll get it landed. So far you've done everything you need to do :-) |
|
@jasnell Thank u sooo much~ It is an honor to pr for nodejs ! |
|
@monkingxue Internally commands are not prefixed with I don't think, its a good idea to check in the catch block after executing the code. because Its easy to define exit in such a way that it will throw error. e.g. $ node
> Object.defineProperty(global, 'exit', { get: function() { throw new Error('catch me') } });
Object [global] {
...
}
> exit
Error: catch me
at get (repl:1:65)
>I suggest to try something like this. const context = this.useGlobal ? global : this.context;
if (isExitCommand && !context.hasOwnProperty(trimCommand)) {
// emit hint
} @nodejs/repl what do you say? |
|
@princejwesley oh I see! You're right, i will fix the code, thank u suggestion! |
lib/repl.js
Outdated
There was a problem hiding this comment.
this can be done before executing the code, right?
There was a problem hiding this comment.
You mean define the context out of the catch block ?
There was a problem hiding this comment.
No. the whole test condition. check this before executing vm.runInContext
There was a problem hiding this comment.
ok I got it and I have modified the code, thank u~
BridgeAR
left a comment
There was a problem hiding this comment.
LGTM with my comments addressed.
lib/repl.js
Outdated
There was a problem hiding this comment.
Would you be so kind and rename the variable to trimmedCommand? Otherwise I would confuse it with a function :-)
lib/repl.js
Outdated
There was a problem hiding this comment.
Nit: this is a unrelated change and I think the comment is better the way it was before.
lib/repl.js
Outdated
There was a problem hiding this comment.
Please remove the extra brackets.
Imitate python repl, when the user enters 'exit' or 'quit', no longer prompt 'Reference Error', but prompts 'To exit, press ^D or type .exit'. If the user defines variables named 'exit' or 'quit' , only the value of the variables are output Fixes: nodejs#19021
Before output the hint, check if defined the command-named variable as an error
Imitate python repl, when the user enters 'exit' or 'quit', no longer prompt 'Reference Error', but prompts 'To exit, press ^D or type .exit'. If the user defines variables named 'exit' or 'quit' , only the value of the variables are output PR-URL: nodejs#20617 Fixes: nodejs#19021 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
|
Landed in 9aa4ec4 @monkingxue congratulations on your first commit to Node.js! 🎉 |
Imitate python repl, when the user enters 'exit' or 'quit', no longer prompt 'Reference Error', but prompts 'To exit, press ^D or type .exit'. If the user defines variables named 'exit' or 'quit' , only the value of the variables are output PR-URL: #20617 Fixes: #19021 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
add friendly tips about how to exit repl.
Fixes: #19021
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes