-
Notifications
You must be signed in to change notification settings - Fork 30k
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
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
var wrappedCmd = false; | ||
var awaitPromise = false; | ||
var input = code; | ||
|
||
if ((trimCmd = code.trim()) && (trimCmd === 'exit' || trimCmd === 'quit')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you soooo much about your advice! I will modify the code as soon.
lib/repl.js
Outdated
if (isExitCmd) { | ||
self.outputStream.write('(To exit, press ^D or type .exit)\n'); | ||
return self.displayPrompt(); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -338,7 +338,8 @@ function REPLServer(prompt, | |||
} | |||
} | |||
} catch (e) { | |||
if (isExitCommand) { | |||
const context = this.useGlobal ? global : this.context; | |||
if (isExitCommand && !context.hasOwnProperty(trimCommand)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be done before executing the code, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean define the context
out of the catch
block ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. the whole test condition. check this before executing vm.runInContext
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok I got it and I have modified the code, thank u~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with my comments addressed.
lib/repl.js
Outdated
var wrappedCmd = false; | ||
var awaitPromise = false; | ||
var input = code; | ||
var trimCommand = code.trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be so kind and rename the variable to trimmedCommand
? Otherwise I would confuse it with a function :-)
if (err && err.code === 'ERR_SCRIPT_EXECUTION_INTERRUPTED') { | ||
// The stack trace for this case is not very useful anyway. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this is a unrelated change and I think the comment is better the way it was before.
lib/repl.js
Outdated
var wrappedCmd = false; | ||
var awaitPromise = false; | ||
var input = code; | ||
var trimCommand = code.trim(); | ||
|
||
if ((trimCommand === 'exit' || trimCommand === 'quit')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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