-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
repl: add hint as to how to exit #20617
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
Changes from 1 commit
7b88a82
17e1272
51282ef
93c1647
de3385a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
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: #19021
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -214,11 +214,16 @@ function REPLServer(prompt, | |
| } | ||
|
|
||
| function defaultEval(code, context, file, cb) { | ||
| var err, result, script, wrappedErr; | ||
| var err, result, script, wrappedErr, trimCmd; | ||
| var isExitCmd = false; | ||
| var wrappedCmd = false; | ||
| var awaitPromise = false; | ||
| var input = code; | ||
|
|
||
| if ((trimCmd = code.trim()) && (trimCmd === 'exit' || trimCmd === 'quit')) { | ||
| isExitCmd = true; | ||
| } | ||
|
|
||
| if (/^\s*\{/.test(code) && /\}\s*$/.test(code)) { | ||
| // It's confusing for `{ a : 1 }` to be interpreted as a block | ||
| // statement rather than an object literal. So, we first try | ||
|
|
@@ -331,18 +336,21 @@ function REPLServer(prompt, | |
| } | ||
| } | ||
| } catch (e) { | ||
| err = e; | ||
|
|
||
| if (err && err.code === 'ERR_SCRIPT_EXECUTION_INTERRUPTED') { | ||
| if (isExitCmd) { | ||
| self.outputStream.write('(To exit, press ^D or type .exit)\n'); | ||
| return self.displayPrompt(); | ||
| } else { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you don’t really need to add the |
||
| err = e; | ||
| if (err && err.code === 'ERR_SCRIPT_EXECUTION_INTERRUPTED') { | ||
| // The stack trace for this case is not very useful anyway. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| Object.defineProperty(err, 'stack', { value: '' }); | ||
| } | ||
|
|
||
| if (process.domain) { | ||
| debug('not recoverable, send to domain'); | ||
| process.domain.emit('error', err); | ||
| process.domain.exit(); | ||
| return; | ||
| Object.defineProperty(err, 'stack', { value: '' }); | ||
| } | ||
| if (process.domain) { | ||
| debug('not recoverable, send to domain'); | ||
| process.domain.emit('error', err); | ||
| process.domain.exit(); | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
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 liketrimCommand/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.