-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: Proposal for better repl (implementation) #9601
Conversation
@princejwesley +1 on this... it's going to take some time to review properly tho. Will hopefully have some comments soon |
@princejwesley Would it make sense to rebase this? |
@fhinkel sure, I'll do |
* Welcome message with version and help guide * `displayWelcomeMessage` flag is used to turn on/off * Differentiate execute & continue actions * ^M or enter key to execute the command * ^J to continue building multiline expression. * `executeOnTimeout` value is used to determine the end of expression when `terminal` is false. * Pretty stack trace. * REPL specific stack frames are removed before emitting to output stream. * Recoverable errors. * No more recoverable errors & no false positives. * Defined commands(like .exit, .load) are meaningful only at the top level. * Remove `.break` command. Welcome message template ------------------------ ```js $ node Welcome to Node.js <<version>> (<<vm name>> VM, <<vm version>>) Type ^M or enter to execute, ^J to continue, ^C to exit Or try ``` Pretty stack trace ------------------ ```js $ node -i > throw new Error('tiny stack') Error: tiny stack at repl:1:7 > var x y; var x y; ^ SyntaxError: Unexpected identifier > ```
429e046
to
48414f0
Compare
lib/repl.js
Outdated
self.displayPrompt(); | ||
} | ||
inherits(REPLServer, Interface); | ||
exports.REPLServer = REPLServer; | ||
|
||
exports.REPL_MODE_SLOPPY = Symbol('repl-sloppy'); | ||
exports.REPL_MODE_STRICT = Symbol('repl-strict'); | ||
exports.REPL_MODE_MAGIC = exports.REPL_MODE_SLOPPY; | ||
exports.REPL_MODE_MAGIC = Symbol('repl-strict'); |
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.
Was this change intended?
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.
Nope!
lib/repl.js
Outdated
const docURL = `https://nodejs.org/dist/${version}/docs/api/repl.html`; | ||
|
||
const welcome = `Welcome to Node.js ${version} (${jsEngine} VM,` + | ||
` ${jsEngineVersion})\nType ^M or enter to execute,` + |
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 Node.js ${version} (${jsEngine} ${jsEngineVersion})
should suffice; the "VM" seems a bit extraneous.
lib/repl.js
Outdated
magic.context = magic.createContext(); | ||
flat.run(tmp); // eval the flattened code | ||
flat.run(tmp, magic); // eval the flattened code |
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.
The comment indentation is now out of date.
lib/repl.js
Outdated
@@ -1224,6 +1253,32 @@ function regexpEscape(s) { | |||
} | |||
|
|||
|
|||
function indexOfInternalFrame(frames) { | |||
return frames.indexOf('vm.js') !== -1 || | |||
frames.indexOf('REPLServer.') !== -1; |
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.
Can this interfere with userland script files named vm.js
?
lib/repl.js
Outdated
} | ||
inherits(Recoverable, SyntaxError); | ||
exports.Recoverable = Recoverable; | ||
}, 'replServer.convertToContext() is deprecated'); |
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.
The DEP0024
code was removed accidentally.
doc/api/repl.md
Outdated
displayed. Defaults to `false`. | ||
```js | ||
> node | ||
Welcome to Node.js <<version>> (<<vm name>> VM, <<vm version>>) |
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.
The VM
should be gone now.
doc/api/repl.md
Outdated
@@ -440,11 +420,15 @@ without passing any arguments (or by passing the `-i` argument): | |||
|
|||
```js | |||
$ node | |||
> const a = [1, 2, 3]; | |||
Welcome to Node.js v6.5.0 (v8 VM, 5.1.281.81) |
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.
Ditto.
lib/repl.js
Outdated
this.run = function(data) { | ||
for (var n = 0; n < data.length; n++) | ||
this.emit('data', `${data[n]}\n`); | ||
this.run = (data, repl) => { |
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.
Can this function be put into the prototype object?
@@ -56,7 +52,7 @@ welcome('Node.js User'); | |||
|
|||
The following key combinations in the REPL have these special effects: | |||
|
|||
* `<ctrl>-C` - When pressed once, has the same effect as the `.break` command. | |||
* `<ctrl>-C` - When pressed once, it will break the current command. | |||
When pressed twice on a blank line, has the same effect as the `.exit` | |||
command. | |||
* `<ctrl>-D` - Has the same effect as the `.exit` command. |
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.
^M
and ^J
should be documented.
@@ -178,34 +174,6 @@ function myEval(cmd, context, filename, callback) { | |||
repl.start({prompt: '> ', eval: myEval}); | |||
``` | |||
|
|||
#### Recoverable Errors |
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 for one am not very happy this feature got removed. In recent versions of Chrome, a similar function just got added (instead of having to type Shift+Enter, the prompt automatically recognizes line continuation), and to have to type an awkward Ctrl+J for the same feature does not sound very appealing to me.
If this change is here to stay, may I suggest we at least add support to Shift+Enter also/instead? It is the syntax in most IM apps, and also in most developer consoles.
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.
@TimothyGu we discussed this option here. Shift+Enter is not possible
Ping @princejwesley this needs a rebase. Do you still want to follow up on this? |
@BridgeAR @TimothyGu point is valid, it will force user to use extra control key to execute or continue. |
@princejwesley @BridgeAR @TimothyGu This PR is comprised of a lot of incremental improvements. Some of these are still somewhat controversial. In order to move forward with some of the items that are universally agreed on (e.g. better stack traces and improved welcome message), would it perhaps be better and more fruitful in the short term to submit those as individual PRs? @princejwesley if you are not opposed, I could take a look at this. |
@lance Agreed. |
@lance sure |
Due to the various reasons noted above, I'm closing this PR. Feel free to reopen if you would like to continue work on it. |
When a user executes code in the REPLServer which generates an exception, there is no need to display the REPLServer internal stack frames. PR-URL: #15351 Reviewed-By: Prince John Wesley <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Refs: #9601
When a user executes code in the REPLServer which generates an exception, there is no need to display the REPLServer internal stack frames. PR-URL: nodejs/node#15351 Reviewed-By: Prince John Wesley <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Refs: nodejs/node#9601
When a user executes code in the REPLServer which generates an exception, there is no need to display the REPLServer internal stack frames. PR-URL: #15351 Backport-PR-URL: #16457 Reviewed-By: Prince John Wesley <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Refs: #9601
Checklist
make -j4 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
repl
Description of change
displayWelcomeMessage
flag is used toturn on/off
executeOnTimeout
value is used to determinethe end of expression when
terminal
is false.emitting to output stream.
.break
is removed - no more get stuckWelcome message template
Pretty stack trace
Refs: #8195
Original WIP PR: #8504